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.
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.
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.
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.
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.
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
↓
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.
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
↓
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)
Previous article:Motion controller tracking application demo
Next article:What is the thyristor for speed regulating motor?
- 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
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- 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
- 37 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (VSCode Debugging ROS)
- How to pack .mpy files into esp8266 micro python firmware package?
- Beidou short message development board based on STM32F103RET6
- Want to know more about UWB? Just read this article.
- When downloading a program to a PCB board in SWD mode, what will happen if the PCB board's own power is not disconnected?
- I would like to ask you guys, what is the value of the bypass capacitor for the LT1763 chip?
- Many people ask whether the soft board can run at high speed...
- stm32 camera experiment
- Control high power electromagnetic valve 24V. Is there anything wrong with the use of thyristor?
- [SAMR21 New Gameplay] 16. Switching between Graphical Programming and Code Programming