Today, Positive Motion Technology will share with you the VPLC series machine vision motion control all-in-one quick start (Part 4) - BLOB presence detection.
Video tutorial: "VPLC Series Machine Vision Motion Control All-in-One Quick Start (Part 4)"
In the last course, we talked about the visual positioning function based on shape matching which is commonly used in machine vision solutions. Through the last course, we mastered the method of using ZDevelop software to realize the shape matching function.
In this course, we will share with you another detection function of machine vision - using BLOB to detect the presence of products.
BLOB, also known as spot, refers to a connected bright area on a dark background or a connected dark area on a bright background in a binary image.
BLOB detection uses morphological methods (such as binarization, dilation, erosion, etc.) to convert grayscale images into binary images. At the same time, the detection features are processed into BLOB spots and the interference factors are processed into image background, so that the detection features can be processed accurately.
1. Rely on morphological processing
The detection image needs to be converted into a binary image and the image needs to be processed using morphology to highlight the detection features.
2. Don’t care about shape features
As long as the area is connected, it can be detected, regardless of the shape of the product.
3. Suitable for high contrast products
BLOB detection requires good contrast between the detection features and the background, otherwise the features and the background cannot be distinguished.
4. Fast execution speed
After converting into a binary image, searching for BLOB spots does not take too much time.
Morphological processing refers to processing local pixels of an image to extract local feature details of interest in the detection process. Commonly used morphological processing methods include binarization, dilation, erosion, and hole filling.
1 Binarization
Convert an 8-bit grayscale image (grayscale value 0~255) into a binary image (an image composed of pure black and pure white) that is either 0 or 1.
2 Filling holes
In a binary image, some small black or white spots are filled to filter out noise.
3. Expansion
The white area in the binary image is enlarged, the black area is reduced, and the interference of small black spots is removed.
4 Corrosion
By enlarging the black area and reducing the white area in the binary image, the interference of small white spots can be removed.
BLOB detection flow chart
// Example demonstration //
1
Open ZDevelop software: 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 enable HMI automatic running tasks → Create a new detectParam.bas file to initialize 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 HMI interface.
3
Define global variables in the global_variable.bas file, and run the Hmi.hmi file after the definition is completed.
'''''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 21-22, mouse buttons, control coordinate system
''table 31-35, rotation moment ROI parameters, cx, cy, width, height, angle, control coordinate system
''table 41-45, the image coordinates corresponding to the coordinate conversion of the rotated rectangle control, image coordinate system
''table 51-56, annular ROI parameters, cx, cy, annular centerline radius r, annular half width ann_R, starting angle stAngle, angle range entAngle, control coordinate system
''table 61-66, the image coordinates corresponding to the circle control coordinate conversion, image coordinate system
'Main task status
'0 - Uninitialized
'1 - Stop
'2 - Running
'3 - Stopping
GLOBAL DIM main_task_state
main_task_state = 1
'Collection switch
'0 - Stop collecting
'1 - Request collection
GLOBAL DIM grab_switch
grab_switch = 0
'Number of cameras
GLOBAL cam_num
cam_num = 0
'Camera type, "zmotion; mvision; basler; mindvision; huaray"
GLOBAL DIM CAMERA_TYPE(16)
CAMERA_TYPE = "zmotion"
'Define the main task id - 10
GLOBAL DIM main_task_id
main_task_id = 10
'Define continuous collection task id - 9
GLOBAL DIM grab_task_id
grab_task_id = 9
'Define global image variables
GLOBAL ZVOBJECT grabImg 'Capture image
GLOBAL ZVOBJECT binImg 'binarized image
GLOBAL ZVOBJECT disImg 'Display image
'Error message
GLOBAL DIM error_msg(256)
'Define common color variables
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)
GLOBAL DIM d_roi_arc_flag 'Define ROI type flag: 0-rectangle, 1-circle
GLOBAL DIM d_rlt_area 'Define BLOB area result
GLOBAL DIM d_rlt_state 'Define status result
'Rotate rectangular ROI parameters: cx, cy, width, height, angle
GLOBAL DIM d_roi_rect2(5) 'd at the beginning indicates data structure
'Arc ROI parameters: cx, cy, annular centerline radius r, annular half width ann_R, starting angle stAngle, angle range entAngle
GLOBAL DIM d_roi_arc(6) 'd at the beginning indicates data structure
'Detection parameters: Threshold mode (automatic threshold or manual threshold), low threshold, high threshold, polarity (black or white), minimum area, maximum area, reverse (i.e. the result is reversed, success becomes failure, failure becomes success)
GLOBAL DIM d_detect_param(7) 'd at the beginning indicates data structure
'Open/Close operation parameters
GLOBal DIM d_deal_value(2)
'The results of the detection are status results, pixel area
GLOBAL DIM d_detect_rst(2)
'Show the printed characters
GLOBAL ShowString(64)
'Run HMI file
RUN "Hmi.hmi",1
4
Initialize the measurement parameters in the detectParam.bas file.
end
GLOBAL SUB init_detect_param() 'Initialize measurement parameters
d_roi_arc_flag = 0 'Default is rectangular
d_rlt_area = 0
d_rlt_state = 0
d_deal_value(0)=1
d_deal_value(1)=1
'Initialize roi parameters
d_roi_rect2(0) = 320.0 'roi center x
d_roi_rect2(1) = 240.0 'roi center y
d_roi_rect2(2) = 160.0 'roi width
d_roi_rect2(3) = 120.0 'roi height
d_roi_rect2(4) = 0.0 'roi angle
TABLE(31) = d_roi_rect2(0)
TABLE(32) = d_roi_rect2(1)
TABLE(33) = d_roi_rect2(2)
TABLE(34) = d_roi_rect2(3)
TABLE(35) = d_roi_rect2(4)
d_roi_arc(0) = 320.0 'roi center x
d_roi_arc(1) = 240.0 'roi center y
d_roi_arc(2) = 60.0 'Circle centerline radius
d_roi_arc(3) = 20.0 'circle half width
d_roi_arc(4) = 0.0 'Starting angle
d_roi_arc(5) = 360.0 'End angle
TABLE(51) = d_roi_arc(0)
TABLE(52) = d_roi_arc(1)
TABLE(53) = d_roi_arc(2)
TABLE(54) = d_roi_arc(3)
TABLE(55) = d_roi_arc(4)
TABLE(56) = d_roi_arc(5)
'Initialize detection parameters: threshold mode (automatic threshold = 1 or manual threshold = 0), low threshold, high threshold, polarity (black or white), maximum, minimum, reverse (that is, the result is reversed, success becomes failure, failure becomes success)
d_detect_param(0) = 0 'Manual threshold
d_detect_param(1) = 128 'low threshold
d_detect_param(2) = 255 'High threshold
d_detect_param(3) = 1 'Polar white, that is, detect white pixel area
d_detect_param(4) = 60000 'Minimum area, number of pixels
d_detect_param(5) = 90000 'Maximum area
d_detect_param(6) = 0 'The result is not reversed
END SUB
5
Associate the HMI interface value display control variable.
6
Add the HMI interface initialization function in the main.bas file and associate the initialization function in the Hmi system settings.
'HMI interface initialization function
GLOBAL SUB hmi_init()
grab_switch = 0
main_task_state = 1
ZV_RESETCLIPSIZE(1280, 1024) 'When initializing, set the clipping size of the area according to the image resolution. Here the image resolution is 1280x1024
ZV_LATCHSETSIZE(0, HMI_CONTROLSIZEX(10, 7), HMI_CONTROLSIZEY(10, 7)) 'Set the latch size
init_detect_param() 'Initialize measurement parameters
ZV_SETSYSDBL("CamGetTimeout", 1000) 'Set the acquisition timeout
ZV_LATCHCLEAR(0)
ZV_LATCH(grabImg, 0)
END SUB
↓
7
In the camera.bas file, add functions for collecting relevant button responses in the HMI interface and associate them with action functions.
Camera operation related buttons
Specific implementation function early course:
VPLC Series Machine Vision Motion Control All-in-One Quick Start (Part 3) Visual Positioning Based on Shape Matching
VPLC Series Machine Vision Motion Control All-in-One Quick Start (Part 2) Basic Use of Cameras
VPLC Series Machine Vision Motion Control All-in-One Quick Start (I) Software and Hardware Introduction and Counting Examples
There is already an operation demonstration, so I won’t go into details here.
8
Add the detection ROI update drawing function in the draw.bas file, and associate the refresh function and the drawing function in the custom component property window.
end
'The refresh drawing function of the interface related to drawing (i.e. selecting ROI) is placed in this bas file
DIM is_redraw
is_redraw = 0
Previous article:Reflection on domestic DC/torque motor speed controller
Next article:Why doesn’t the motor rotate faster after adjusting the speed regulator?
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- What is the effect of connecting the SW pin of the switching power supply to the capacitor and resistor in series to GND?
- EEWORLD University ----TI LED Driver
- NRF24LE1 2.4g wireless RF chip introduction
- Doorbell program + circuit made by AVR microcontroller timer
- [N32L43X Review] 2.IO Operation and Delay
- AR1021X series WiFi module selection reference and driver discussion in the field of wireless image transmission
- Allegro software placement problem
- 2812 TxPR register write failure caused by TxCON highest bit
- Fabrication process of fiber-embedded microfluidic chip
- 3D Printer Project—STM32F750 Main Program Framework and Interface (Part 3)