Application Background
With the further development of automation technology, production lines in manufacturing enterprises are increasingly moving towards automation and intelligence. As a result, a large number of automated equipment are gradually being installed on production lines.
In material color recognition and sorting, visual imaging is required for image acquisition and data analysis to effectively identify and locate the sample's color. Zhengdong Technology provides an effective visual color recognition and sorting solution to improve enterprise production capacity.
The vision-based detection method using positive motion technology has the advantages of fast detection speed, high reliability, and high efficiency. It can achieve non-contact and non-destructive detection and has good applicability in machine vision color recognition, positioning and sorting in various industries. It also has a wide range of market application scenarios.
In the last lesson, we discussed application cases of online contour extraction and contour trajectory processing in machine vision solutions. In this lesson, we will share with you how to implement the function of coffee cap color recognition, positioning, and sorting.
Instructional Videos
01 Detection Principle
(I) Testing Requirements
The system intelligently matches and locates the four coffee cap colors currently in place, and then sorts the coffee caps accordingly.
(II) Software Algorithm
First, take pictures with a color camera. After converting the captured RGB images to grayscale images, use matching modeling to learn the shape template of the coffee lid. Then, use the shape template position result as the reference position and the position correction source of the color recognition rectangle ROI.
Then, by repeatedly reading RGB images of coffee lids of different colors, color sample learning is performed on each coffee lid, and the color sample results are stored in a list. Finally, the identified coffee lid color results and location information are displayed.
02 Software Implementation
1. Open ZDevelop software: Create a new project named "Color Recognition and Sorting.zpj" → Create a new "HMI" file → Create a new "main.bas" file (for writing the interface response function) → Create a new "global_variable.bas" file (for storing global variables and enabling HMI to run tasks automatically) → Create a new "InitLocator.bas" file (for initializing measurement parameters) → Create a new "draw.bas" file (for updating and drawing ROI data) → Create a new "camera.bas" file (for implementing camera acquisition function) → Add the files to the project.
2. Design the HM main interface.
3. Associate HMI main interface control variables.
4. Associate the color template interface control variables with learning.
5. The main commands used in the code implementation of this course are commands for generating color models, inserting color models into lists, and color recognition.
ZV_CLRGENMODELRE (Parameter 1: Input RGB image, Parameter 2: Specify the detection region in the image used to generate the color model, Parameter 3: The generated color model, Parameter 4: Model name, string, cannot be empty ("" or "?", Parameter 5: Color system, 0-RGB color space, 1-HSV color space)
ZV_LISTINSERT(parameter 1: element to be inserted, parameter 2: list, parameter 3: position of the element to be inserted in the list, default value is -1, indicating that the element is inserted at the end of the list) ZV_CLRMODELCLASSIFY(parameter 1: list of color models to be inserted, parameter 2: input RGB image, parameter 3: detection area of the generated color model, parameter 4: maximum length of the tab_name TABLE, parameter 5: color name, output parameter, TABLE index, parameter 6: output parameter, TABLE index, parameter index for storing color ID, parameter 7: set recognition score)
Full code and sample image download address
▼
03 Operation Demonstration
(I) Operating Procedures
To check the running effect: Download the project to the controller → Use local image → Single acquisition → Click Matching Modeling (to learn shape templates) → Click Color Sample (to learn multiple color templates respectively) → Click Single Execution (to view the current sample detection results) → Click Continuous Run (to view the continuous run effect) → End.
(II) Effect Demonstration
That concludes our presentation on the Zhengdong Technology Machine Vision Motion Control All-in-One Machine Application Example: Color Recognition Positioning and Sorting System.
For more exciting content, please follow the "Zheng Motion Assistant" WeChat official account. For related development environment and example code, please contact Zheng Motion's technical sales engineer: 400-089-8936.
This article is original content from Zheng Motion Technology. We welcome everyone to reprint it for mutual learning and to jointly improve China's intelligent manufacturing level. Copyright belongs to Zheng Motion Technology. Please indicate the source if you reprint this article.