VPLC Series Machine Vision Motion Control All-in-One Quick Start (Part 3)

Publisher:DazzlingSpiritLatest update time:2024-09-29 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Motion Control

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.



Motion Control


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.



Motion Control


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.



Motion Control

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.



Motion Control


As shown in the figure, lightning is the only feature of target 1, which can distinguish target 1 from target 2.



Motion Control


1 Target positioning



Motion Control


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



Motion Control


Count the products with the same shape characteristics.

3 Position following



Motion Control


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.



Motion Control


Motion Control

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.



Motion Control


2

Design the main interface.



Motion Control


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.

[1] [2] [3]
Reference address:VPLC Series Machine Vision Motion Control All-in-One Quick Start (Part 3)

Previous article:What is the output voltage of the torque motor controller?
Next article:ZMC Motion Controller SCARA Robot Application Quick Start

Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号