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

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

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)"



Motion Control


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.



Motion Control


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.



Motion Control


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.



Motion Control


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.



Motion Control


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.



Motion Control


2 Filling holes

In a binary image, some small black or white spots are filled to filter out noise.



Motion Control


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.



Motion Control


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.



Motion Control


Motion Control



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.



Motion Control

2


Design HMI interface.



Motion Control

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.



Motion Control

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


Motion Control


7

In the camera.bas file, add functions for collecting relevant button responses in the HMI interface and associate them with action functions.



Motion Control


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

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

Previous article:Reflection on domestic DC/torque motor speed controller
Next article:Why doesn’t the motor rotate faster after adjusting the speed regulator?

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号