Today, Positive Motion Technology will share with you a quick introduction to the VPLC series machine vision motion control all-in-one machine (Part 3) - visual positioning based on shape matching.
In the last course, we talked about the basis for implementing machine vision solutions, that is, the basic use of cameras. Through the last course, we have been able to use ZDevelop software to acquire images for processing.
In this course, we will share with you the shape matching-based visual positioning function commonly used in machine vision solutions.
Visual localization refers to the process of learning specific templates or certain fixed features in visual detection , searching for features that meet the conditions in the detection area, and returning the location information of the features in the image coordinates , such as coordinate position X, coordinate position Y, and angle.
Shape matching is based on edge direction gradient matching. It extracts edge features in ROI and combines them with grayscale information to create a template. Then it searches for features that meet a certain degree of similarity with the contour features of the template within the detection area ROI and returns the corresponding position information.
Shape matching features
1. Strong adaptability: can adapt to changes in lighting and image grayscale.
2. Strong compatibility: It can support searching for targets with missing local edges, noise interference, slight deformation and out-of-focus.
3. Multi-target search: supports simultaneous search for multiple matching targets under the same template.
4. Support rotation and scaling: The target can still be matched when the target image is rotated or scaled, but it needs to be within the set rotation and scaling ratio range.
Template Selection
The premise of using the shape matching function is that the detection target must have unique and fixed features.
1. When selecting a template, you need to ensure that the feature is the only feature of the detection target, otherwise it cannot be distinguished from other detection targets.
2. Try to choose standard products with clear images and complete shapes as templates to avoid interference factors such as noise.
3. Try to avoid choosing symmetrical features as templates.
As shown in the figure, lightning is the only feature of target 1, which can distinguish target 1 from target 2.
1 Target positioning
When the target contour features are clear and the positioning accuracy requirement is not high, the position results output by shape matching can be directly used for positioning projects.
2 Product Count
Count the products with the same shape characteristics.
3 Position following
When the position of the target to be detected is not fixed, the ROI position of some detection functions cannot be determined, such as detecting a straight line or a circle. We can use features with a fixed distance around the detection target to track the position.
Shape matching flow chart
Example Demonstration
1
Create a new project → Create a new HMI file → Create a new main.bas file to write the interface response function → Create a new global_variable.bas file to store global variables and start the HMI automatic run task → Create a new InitLocator.bas file to initialize the measurement parameters → Create a new camera.bas file to implement the camera acquisition function → Create a new draw.bas file to update the drawing graphics refresh interface → Add the file to the project.
2
Design the main interface.
3
Define global variables in the global_variable.bas file.
'''''Most global variables use array structures'''''
''Note: In basic programming, many functions take TABLE (system data structure) as a parameter.
''Here table is used as an intermediate variable
''table 0-20 is used as an intermediate variable for matching
''table 50-70 is used as an intermediate variable when drawing roi
''table 21-22, represents the coordinate system of the mouse button control
''table 31-35, represents the image coordinates corresponding to the control coordinate conversion
''table 111-114, represents the locator area roi parameters, belongs to the control coordinate system
''table 121-124, represents the eraser area roi parameters, belonging to the control coordinate system
'***********Define program task related variables**************************
'Main task status
'0 - Uninitialized
'1 - Stop
'2 - Running
'3 - Stopping
GLOBAL DIM main_task_state
main_task_state = 1
'Run task switch
GLOBAL DIM run_switch
run_switch = 0
'Collection task switch
'0 - Stop collecting
'1 - Request collection
GLOBAL DIM grab_switch
grab_switch = 0
'Location detection main task id - 10
GLOBAL DIM main_task_id
main_task_id = 10
'Camera continuous acquisition thread id - 7
GLOBAL DIM grab_task_id
grab_task_id = 7
'***********End definition of program task related variables******************
'***********Define camera acquisition related variables**************************
'Camera type,""Here we use Hikvision camera - "mvision"
GLOBAL DIM CAMERA_TYPE(100)
'CAMERA_TYPE = "min dvi sion;basler;mvision;huaray;basler;zmo ti on"
CAMERA_TYPE = "mvision"
'Number of cameras
GLOBAL cam_num
cam_num = 0
'Camera mode, -1 for continuous acquisition, 0 for triggered acquisition
GLOBAL cam_mode
cam_mode = 0
'***********End definition of camera acquisition related variables******************
'Define the flag to return to the main interface, 1-returned, 0-not returned
GLOBAL DIM d_is_rtn_loc
d_is_rtn_loc = 1
'***********Define template related variables****************************
'Define the template creation flag, 1-template has been created, 0-template has not been created
GLOBAL DIM d_is_creModel
d_is_creModel = 0
'Learn template parameters, starAngle, endAngle, minScale, maxScale, thresh, numlevel, reduce, angleStep, scaleStep
GLOBAL DIM
d_mod_param
(9)
'***********End definition of template related variables***********************
'***********Define editing template related variables*************************
'Define the template editing flag, 0-indicates not editing the template, 1-indicates editing the template
GLOBAL DIM d_edit_m
d_edit_m = 0
'Define the eraser function flag, 0-indicates restoring the erased area, 1-indicates erasing the area
GLOBAL DIM d_isMask_m
d_isMask_m = 1
'Define the roi parameters of the eraser, which are the image coordinates x, y, x, y of the upper left and lower right corners of the rectangle
GLOBAL DIM d_locator_roi(4),d_eraser_roi(4)
'Define the width of the square eraser
GLOBAL DIM d_eraser_size
d_eraser_size = 5
'Define the rectangular area of the eraser on the interface control
GLOBAL DIM c_rect(4)
'Define the mouse status flag, 0-indicates that the mouse is released, 1-indicates that the mouse is pressed
GLOBAL DIM d_mouse_s
d_mouse_s = 0
'***********End definition of editing template related variables******************
'***********Define matching detection related variables************************
'Match detection parameters, minScore, matchNum, minDist, thresh, ac curacy, speed, polor
GLOBAL DIM d_match_param(7)
'Define the roi parameters of the learning template and the eraser, which are the image coordinates x, y, x, y of the upper left corner and lower right corner of the rectangle respectively
GLOBAL DIM d_locator_roi(4),d_eraser_roi(4)
'Matching results, score, x, y, angle, scale, currently only the first target is stored for multi-target matching
GLOBAL DIM
d_match_rst
(5)
GLOBAL DIM d_match_time 'Define the time variable consumed by matching positioning
d_match_time = 0
'***********End definition of matching detection related variables******************
'Define variables for caching intermediate images and result images during program execution
GLOBAL ZVOBJECT grabImg
GLOBAL ZVOBJECT subImg ,copy_subImg,colorSubImg, s_mod
GLOBAL ZVOBJECT modRe
RUN "Hmi1.hmi",1
4
Initialize the measurement parameters in the InitLocator.bas file.
end
GLOBAL SUB init_meas_param() 'Initialize measurement parameters
'Initialize locator roi parameters
d_locator_roi(0) = 240 'upper left corner x
d_locator_roi(1) = 180 'Upper left corner y
d_locator_roi(2) = 400 'lower right corner x
d_locator_roi(3) = 300 'lower right corner y
'Initialize template parameters
d_mod_param(0) = -180 'Starting angle
d_mod_param(1) = 180 'End angle
d_mod_param(2) = 1 'Minimum zoom
d_mod_param(3) = 1 'Maximum zoom
d_mod_param(4) = 80 'Threshold
d_mod_param(5) = 0 'Default number of pyramid levels
d_mod_param(6) = 0 'Default feature point reduction
d_mod_param(7) = 0 'Default angle step
d_mod_param(8) = 0 'Default scaling step size
'Initialize matching measurement parameters
d_match_param(0) = 50 'Minimum score
d_match_param(1) = 1 'Number of matches
d_match_param(2) = 0 'Default minimum spacing
d_match_param(3) = 40 'Minimum threshold
d_match_param(4) = 0 'Precision
d_match_param(5) = 9 'Speed
d_match_param(6) = 0 'Polarity
'Initialize matching positioning results
d_match_rst(0) = 0 'score
d_match_rst(1) = 0 'Position X
d_match_rst(2) = 0 'Position Y
d_match_rst(3) = 0 'angle
d_match_rst(4) = 0 'Ratio
'Initialize matching and positioning time
d_match_time = 0
END SUB
5
Associate the main interface value display control variable.
Previous article:What is the output voltage of the torque motor controller?
Next article:ZMC Motion Controller SCARA Robot Application Quick Start
- Popular Resources
- Popular amplifiers
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- [New version of Zhongke Bluexun AB32VG1 RISC-V development board] - 7: Using RT-Thread in VS Code on Ubuntu
- Analysis of Factors Affecting WiFi RF EVM
- Transistor replacement
- [Voice and vision module based on ESP32S3] Hardware design, debugging and progress - after 4 versions of iterative hardware design completed
- It’s like face to face with real people. What do you think of this black technology?
- MATLAB/Simulink Video Tutorials
- The novel coronavirus epidemic is affecting people's hearts. Please share some interesting things to relax yourself!
- Complain about this development environment. It does not support the previous ARM simulation tools and you have to buy more tools.
- The power of technology to change life~~
- C Basic skills training