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

Publisher:梦想启航Latest update time:2024-09-26 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Previously, we explained the introduction of software and hardware, counting examples, basic use of cameras, visual positioning based on shape matching, and BLOB detection.


Today, Positive Motion Technology will share with you the VPLC series machine vision motion control all-in-one quick start guide (Part 5), and share with you the commonly used detection function of machine vision - measuring dimensions.


Motion Control


Measuring dimensions: The principle of measuring dimensions commonly used in machine vision is to use two linear measuring devices to detect the points on the two edges of the product, fit them into straight lines, and then take the distance between the two straight lines.

The essence of size measurement is based on edge detection. It needs to first detect the edge points where the light-dark transition meets a certain threshold, and then extract the edge point data for processing and calculation to output the final result.


Measurement size characteristics


1. High accuracy

Choosing the right hardware selection scheme can achieve high detection accuracy. Telecentric lenses are often used to reduce distortion, increase depth of field, and reduce measurement errors.

2. Less image interference

Backlighting is often used in simple size measurement projects to highlight the edge size of the product and filter out surface interference factors.

3. Simple implementation

The algorithm for measuring size is based on edge detection and is easy to implement.

4. Need to follow the location

The measuring device for measuring dimensions does not have a positioning function. If the position of the product being tested is not fixed, the corresponding position of the measuring device cannot be determined. In this case, it is necessary to rely on positioning functions such as matching to track the position.

Calibration


Calibration refers to converting the pixel results (unit: pixel) processed by machine vision into the actual results (unit: millimeter) used in reality, or converting the image coordinates used in machine vision into world coordinates.

When we actually measure the size, the size units we use are generally international standard units such as meters, centimeters, millimeters, etc. Therefore, in the machine vision size measurement project, it is necessary to convert the obtained pixel size into the actual size (mm) and output it to the user end for direct use by the user.


Measurement dimension calibration method


1. Measurement calibration

Use a standard module of known size, such as a circle, a small square, or a ruler, to detect the pixel size in the image and divide the known actual size value by the pixel value to get the pixel ratio value (unit: mm/pixel). This is a common measurement calibration method used in measurement projects.



Motion Control

2. Coordinate calibration

Enter several sets of image coordinates (at least 9 sets), and then enter the world coordinates corresponding to the image coordinates. After calculating the matrix transformation coefficients through the formula, the image coordinates can be converted to the actual coordinates. In the measurement project with high measurement accuracy requirements, you can consider using coordinate calibration. We will explain the specific implementation content in detail in the next course.



Motion Control


1. Open ZDevelop software: Open the project "Visual Positioning Based on Shape Matching" → Define the global variables needed to measure the dimensions in the global_variable.bas file.


'----------------------------Dividing line-----------------------------------------

'Line 1 measurement parameter array, which is center cx, cy, w, h, angle, interp, sub_num, sub_width, filter_size, thresh, polor, select, all are image coordinates

GLOBAL DIM d_meas_param1(12) 'd at the beginning indicates data structure

'Line 2 measurement parameter array, which is center cx, cy, w, h, angle, interp, sub_num, sub_width, filter_size, thresh, polor, select, all are image coordinates

GLOBAL DIM d_meas_param2(12) 'd at the beginning indicates data structure

'Define common color variables for drawing graphics

GLOBAL C_RED, C_GREEN, C_BLUE, C_YELLOW

C_RED = RGB(255, 0, 0)

C_GREEN = RGB(0,255,0)

C_BLUE = RGB(0, 0,255)

C_YELLOW = RGB(255,255,0)

'Straight line 1 reference area position vector 1 saved when creating the template, x, y, angle

GLOBAL DIM d_meas_base_v1(3)

d_meas_base_v1(0) = 0

d_meas_base_v1(1) = 0

d_meas_base_v1(2) = 0

''Line 2 reference area position vector 2 saved when creating the template, x, y, angle

GLOBAL DIM d_meas_base_v2(3)

d_meas_base_v2(0) = 0

d_meas_base_v2(1) = 0

d_meas_base_v2(2) = 0

'Measurement results of line 1, which are the result points stx, sty, endx, endy in turn

GLOBAL DIM d_meas_rst1(4)

'Measurement results of line 2, which are the result points stx, sty, endx, endy in order

GLOBAL DIM d_meas_rst2(4)

'Define the length variable displayed on the interface

GLOBAL DIM d_show_rst

''Template reference point saved when creating the template, score, x, y, angle, scale

GLOBAL DIM d_match_base_rst(5)

global dim d_meas_param(12)

'Define the variables used in measurement calibration

GLOBAL PixLength,WorldLength,CalibParam

2. Supplement the design of the main interface.



Motion Control


3. Create a new main interface and press the [Measurement Settings] button to pop up the measurement parameter setting window "Set_Select", and design the interface layout.



Motion Control


4. Add a function in the main.bas file that responds when the [Measurement Settings] button is pressed on the main interface and associate the action function name.

'The function that responds when the measurement setting button is pressed on the main interface

GLOBAL SUB Goto_Meas()

HMI_SHOWWINDOW(13)

END SUB



Motion Control


5. Initialize the measurement parameters in the InitLocator.bas file.

'---------------------Dividing line------------------

'Initialize measurement parameters 1

d_meas_param1(0) = 320.0 'roi center x

d_meas_param1(1) = 240.0 'roi center y

d_meas_param1(2) = 160 'roi width

d_meas_param1(3) = 120.0 'roi height

d_meas_param1(4) = 0.0 'roi angle

d_meas_param1(5) = 1 'Interpolation method

d_meas_param1(6) = 20 'Number of sub-areas

d_meas_param1(7) = 5 'Size of sub-region

d_meas_param1(8) = 3 'Filter size

d_meas_param1(9) = 50 'Threshold

d_meas_param1(10) = 0 'Polarity

d_meas_param1(11) = 0 'Select edge position

'Initialize measurement parameters 2

d_meas_param2(0) = 320.0 'roi center x

d_meas_param2(1) = 240.0 'roi center y

d_meas_param2(2) = 160 'roi width

d_meas_param2(3) = 120.0 'roi height

d_meas_param2(4) = 0.0 'roi angle

d_meas_param2(5) = 1 'Interpolation method

d_meas_param2(6) = 20 'Number of sub-areas

d_meas_param2(7) = 5 'Size of sub-region

d_meas_param2(8) = 3 'Filter size

d_meas_param2(9) = 50 'Threshold

d_meas_param2(10) = 0 'Polarity

d_meas_param2(11) = 0 'Select edge position

'Initialize the result value displayed on the interface

d_meas_rst1(0) = 0

d_meas_rst1(1) = 0

d_meas_rst1(2) = 0

d_meas_rst1(3) = 0

d_meas_rst2(0) = 0

d_meas_rst2(1) = 0

d_meas_rst2(2) = 0

d_meas_rst2(3) = 0

d_show_rst = 0

'Initialize calibration parameters and pixel ratio

CalibParam = 0

WorldLength = 0

PixLength = 0

6. Create a new "Set_Roi1" window that pops up when you press the [Select Measuring Device Area 1] button in the "Set_Select" window interface. It is used to create a straight line measuring device for the first dimension edge and set the parameters for detecting the straight line.



Motion Control


7. In the draw.bas file, add a function that responds when the [Select Measuring Area 1] button is pressed in the "Set_Select" window interface and associate the action function name.

'-----------------Dividing line-------------------------

'Measurer drawing

DIM is_redraw

is_redraw = 0

DIM set_roi_open_init

set_roi_open_init = 0

DIM sr_mpos_x, sr_mpos_y, hit_pos

'''''''''''''''''''''''''''''''

'Function that responds when the button for selecting meter area 1 is pressed

GLOBAL SUB btn_sel_roi1()

ZV_LATCHCLEAR(1) 'Clear latch

ZV_LATCHSETSIZE(1, HMI_CONTROLSIZEX(14, 1), HMI_CONTROLSIZEY(14,1)) 'Set the latch size

ZV_LATCH(grabImg, 1) 'Display image on latch

SET_COLOR(RGB(0,255,0))

'Image roi to control roi

is_redraw = 0

TABLE(11, d_meas_param1(0), d_meas_param1(1))

ZV_POSFROMIMG(1, 1, 11, 11) 'Convert image coordinates to HMI control coordinates

TABLE(13) = ZV_LENFROMIMG(1, d_meas_param1(2))

TABLE(14) = ZV_LENFROMIMG(1, d_meas_param1(3))

TABLE(15) = d_meas_param1(4)

HMI_SHOWWINDOW(14)

END SUB



Motion Control


8. In the draw.bas file, add the function that updates the ROI position according to the mouse operation and the function that draws Roi1 in real time.

'Update the position of Roi1 according to mouse operation

GLOBAL SUB update_roi1()

if mouse_scan(21) = 1 then '

Scan Press Action

hit_pos = ZV_HMIADJRECT2(table(21), table(22), 11, -1) 'The hit position can only be changed when pressed

?TABLE(21),TABLE(22)

is_redraw = 1

endif

if mouse_scan(21) = -1 then '

Scan and release operation

if TABLE(21)<(table(11)-table(13) or="">(TABLE(11)+TABLE(13)/2) or TABLE(22)<(table(12)-table(14) or="">(TABLE(12)+TABLE(14)/2) then

hit_pos=-1

endif

ZV_HMIADJRECT2(table(21), table(22), 11, hit_pos)

?*TABLE(11,4)

is_redraw = 1

endif

if (MOUSE_state(21)) then

ZV_HMIADJRECT2(table(21), table(22), 11, hit_pos)

is_redraw = 1

endif

if (1 = is_redraw) then

is_redraw = 0

ZV_POSTOIMG(1, 1, 11, 31)

d_meas_param1(0) = TABLE(31)

d_meas_param1(1) = TABLE(32)

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

Previous article:Motion controller tracking application demo
Next article:What is the thyristor for speed regulating motor?

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号