Accurate classification and identification method and system for injection molding parts based on machine vision
By combining YOLOv8 object detection and template matching technology, the problems of low image resolution and high calculation cost in visual classification recognition of injection molded parts are solved, and the accurate classification and recognition of injection molded parts is achieved, which improves the accuracy and reliability of recognition.
Patent Information
- Application Number
- CN202510214674.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-26
- Publication Date
- 2025-06-27
AI Technical Summary
The prior art has problems in the visual classification recognition of injection molded parts with low image resolution, illumination change and noise sensitivity, and high computing and storage costs, and deep learning-based methods require a large amount of data annotation.
Combining YOLOv8 object detection and template matching, the YOLOv8 model is used to classify and identify the injection molded parts images, and through the step-by-step verification mechanism of confidence sorting and template matching, the precise visual classification and recognition of injection molded parts is achieved.
It improves the accuracy and reliability of classified recognition of injection molded parts, reduces dependence on image resolution and lighting changes, reduces calculation and storage costs, and does not rely on large amounts of data annotations.
Smart Images

Figure CN120219803A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of machine vision, and particularly relates to an accurate classification and recognition method and system for injection molded parts based on machine vision. Background Art
[0002] Machine vision can simulate the visual functions of humans. Through image acquisition, processing, and analysis, it can achieve automatic recognition, positioning, measurement, and detection of targets, and has become a key supporting technology for intelligent manufacturing and unmanned production. More and more injection molding factories are starting to use machine vision for visual classification and recognition, unmanned sorting, and packaging of injection molded parts products to improve production efficiency and product quality.
[0003] Patent CN202210105730.2 provides a classification method for injection molded parts based on image processing. However, the effectiveness of this method depends on high-resolution input images. Low-resolution images may lead to loss of details and affect classification accuracy. At the same time, the image quality is greatly affected by lighting conditions and background interference, which may lead to deviations in clustering analysis and similarity calculation. Patent CN202110746051.9 provides a classification method for engine rocker arm parts based on image feature extraction and template matching. However, this method is sensitive to factors such as the background, lighting changes, and noise of the image. Image transformation will significantly affect the algorithm performance, resulting in poor classification effects. Moreover, when dealing with the problem of large-scale image data, the calculation and storage costs are high, and the calculation speed is slow. Therefore, it is not suitable for injection molded part production lines with large production volumes and complex features. Patent CN202211491394.6 provides an image recognition method, and Patent CN202310329234.X provides a deep learning-based garbage image classification and recognition method. However, these deep learning-based machine vision image recognition methods usually require a large amount of data annotation and have high requirements for the quality and quantity of the dataset. Summary of the Invention
[0004] The main purpose of the present invention is to overcome the shortcomings and deficiencies of the prior art, and propose an accurate classification and recognition method and system for injection molded parts based on machine vision. By combining YOLOv8 object detection and template matching, template matching is used for verification and validation based on the recognition and detection results of the YOLOv8 model, and through confidence ranking and a hierarchical verification mechanism, accurate visual classification and recognition of injection molded parts are achieved.
[0005] To achieve the above purpose, the present invention adopts the following technical solutions:
[0006] An accurate classification and recognition method for injection molded parts based on machine vision, comprising the following steps:
[0007] S1. Build an image acquisition system, collect images of injection molded parts, and construct an image dataset;
[0008] S2. Train and use the YOLOv8 model to classify and recognize the injection molding part images, and sort the confidence levels according to the classification and recognition results;
[0009] S3. Use template matching to verify the detection results of the YOLOv8 model and output the final classification results.
[0010] Furthermore, in step S1, the image acquisition system includes an industrial camera and a uniform light source. The resolution of the industrial camera is specifically 640×480, and the uniform light source is specifically an LED light source.
[0011] Furthermore, in step S1, constructing the image dataset specifically includes:
[0012] Divide the collected injection molding part images into a training set and a test set, with a quantity ratio of 9 to 1. Among them, true bounding boxes and label information are marked on the training set images.
[0013] Furthermore, in step S2, the training process of the YOLOv8 model includes:
[0014] S21. Use the training set to train the YOLOv8 model to obtain a trained injection molding part classification and recognition model;
[0015] S22. Use the test set to test the trained injection molding part classification and recognition model to obtain test results. Adjust the parameters of the YOLOv8 model according to the test results, and jump to step S21 to continue model training until the test results meet the preset requirements to obtain the final injection molding part classification and recognition model;
[0016] During the training process of the YOLOv8 model, calculate the bounding box regression loss function. Measure the difference between the predicted position and the true position of the target bounding box through the bounding box regression loss. The calculation formula is:
[0017]
[0018] where x i represents the coordinates of the true bounding box, represents the coordinates of the predicted bounding box, and N represents the number of bounding boxes;
[0019] Take the bounding box regression loss function as the optimization objective to guide the YOLOv8 model to reduce the gap between the true bounding box and the predicted bounding box during the training process.
[0020] Furthermore, in step S2, sorting the confidence levels according to the classification and recognition results specifically includes:
[0021] Use the finally obtained injection molded part classification and recognition model to classify and recognize the injection molded part images, output the different injection molded part categories to which the detected object in the image may belong and their corresponding confidence levels, and sort them according to the confidence levels corresponding to different injection molded part categories.
[0022] Further, step S3 specifically includes:
[0023] S31. Template preparation: Take and extract images of multiple injection molded parts respectively to construct a template library. The images of various injection molded parts are required to have obvious features, clear images, no occlusion and no dirt. Match the detected image with the standard template image according to the outer contour and surface shape gray value of the images in the template library;
[0024] S32. Obtain the image after classification and recognition by the injection molded part classification and recognition model, preprocess the image, and extract the outer contour of the object in the detection frame and its surface shape gray value;
[0025] S33. According to the sorting result of the confidence level, match the detected injection molded part image with the template image of the corresponding injection molded part category, calculate the matching correlation coefficient, and obtain the final classification result.
[0026] Further, step S33 is specifically:
[0027] S331. According to the sorting result of the confidence level, determine the current matching category, and retrieve the template image of the current matching category in the template library; the current matching category is initially set as the injection molded part category corresponding to the highest confidence level;
[0028] S332. Perform template matching verification on the template image of the current matching category and the detected image, and calculate the matching correlation coefficient;
[0029] S333. When the matching correlation coefficient reaches the preset threshold, determine that the current matching category is the final classification result, and output the injection molded part category; otherwise, determine that the injection molded part category cannot be used as the final classification result, set the current matching category as the injection molded part category corresponding to the next confidence level, and jump to step S331.
[0030] Further, calculating the matching correlation coefficient is specifically:
[0031] Perform binarization processing on the detected image and the template image respectively to obtain the vector parameters t(r, c) and t(u, v) of the images. The vector parameters represent the gray value t at the coordinate (r, c) in the detected image and the coordinate (u, v) in the template image. Then overlap the outer contour regions of the two, and calculate the similarity of the matching condition between the template image and the covered area at this position;
[0032] Calculate the normalized cross - correlation coefficient between the detected regions of the image, and use it as the matching correlation coefficient for template matching. The calculation formula is as follows:
[0033]
[0034] Where, T is the region of interest of the detection box, n is the number of pixel points in the region of interest of the template, f(r + u, c + v) represents the gray value f in the region of interest at the current position, m t and are the average gray value and variance of the pixel points of the template image, and m f (r, c) and are the average gray value and variance of the pixel points translated to the current position of the image.
[0035] Furthermore, the YOLOv8 model can be replaced by any one of Faster R - CNN, Efficient Det or Retina Net;
[0036] The normalized cross - correlation coefficient can be replaced by any one of the mean square error MSE, structural similarity SSIM or Hamming distance.
[0037] The present invention also includes an injection - molded part precise classification and recognition system based on machine vision. The system adopts the injection - molded part precise classification and recognition method provided by the present invention. The system includes an image acquisition module, a YOLOv8 classification module, and a template matching verification module;
[0038] The image acquisition module is used to collect injection - molded part images and construct an image data set;
[0039] The YOLOv8 classification module is used to train and classify and recognize injection - molded part images using the YOLOv8 model, and sort the confidence levels according to the classification and recognition results;
[0040] The template matching verification module uses template matching to verify the detection results of the YOLOv8 model and output the final classification results.
[0041] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0042] 1. The present invention combines YOLOv8 object detection and template matching. Based on the recognition and detection results of the YOLOv8 model, template matching is used for verification. Through confidence level sorting and a step - by - step verification mechanism, precise visual classification and recognition of injection - molded parts are realized.
[0043] 2. Existing machine vision technology based on deep learning relies on a single deep learning model and lacks a verification mechanism for recognition results. The present invention uses the YOLOv8 model and verifies the recognition results step by step through correlation template matching according to the confidence ranking in its detection results, ensuring that the classification and recognition results of injection molded parts are correct, effectively improving the accuracy and reliability of injection molded parts classification and recognition detection.
[0044] 3. Existing traditional machine vision technology only relies on image pyramid and clustering, and the classification accuracy is limited by the singleness of feature extraction; the present invention fully utilizes the confidence ranking information generated by the deep learning vision model by integrating YOLOv8 target detection and template matching technology. Subsequent template matching is performed according to this order, which can greatly simplify the verification process and reduce unnecessary computational waste. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 is a flow chart of the method of the present invention;
[0046] Figure 2 It is a schematic diagram of classification and identification in the embodiment. DETAILED DESCRIPTION
[0047] The present invention is further described in detail below in conjunction with embodiments and drawings, but the embodiments of the present invention are not limited thereto.
[0048] Explanation of related terms:
[0049] NCC: Normalized Cross-Correlation, normalized cross-correlation, is used to calculate the similarity between the pixel values of the template and the target area.
[0050] Example
[0051] like Figure 1 As shown, the present invention provides a method for accurately classifying and identifying injection molded parts based on machine vision, comprising the following steps:
[0052] S1. Build an image acquisition system to collect images of injection molded parts and construct an image data set;
[0053] In this embodiment, the image acquisition system includes an industrial camera and a uniform light source. The resolution of the industrial camera is specifically 640×480, and the uniform light source is specifically an LED light source.
[0054] The specific steps of constructing the image dataset are:
[0055] The collected injection molded parts images are divided into a training set and a test set with a ratio of 9:1. The real bounding boxes and label information are annotated on the training set images, while the test set images do not contain any labels.
[0056] S2. Train and use the YOLOv8 model to classify and recognize injection molded part images, and sort them according to the classification and recognition results by confidence level;
[0057] In this embodiment, the training process of the YOLOv8 model includes:
[0058] S21. Use the divided training set to train the YOLOv8 model to obtain a trained injection molded part classification and recognition model;
[0059] S22. Use the test set to test the trained injection molded part classification and recognition model to obtain test results. Adjust the parameters of the YOLOv8 model according to the test results, and jump to step S21 to continue model training until the test results meet the preset requirements to obtain the final injection molded part classification and recognition model;
[0060] During the training process of the YOLOv8 model, it is necessary to calculate the bounding box regression loss function. The difference between the predicted position and the real position of the target bounding box is measured by the bounding box regression loss. The formula is:
[0061]
[0062] where x i represents the coordinates of the real bounding box, represents the coordinates of the predicted bounding box, and N represents the number of bounding boxes;
[0063] Take the bounding box regression loss function as the optimization objective to guide the YOLOv8 model to reduce the gap between the real bounding box and the predicted bounding box during training.
[0064] Sort according to the classification and recognition results by confidence level, specifically:
[0065] Use the finally obtained injection molded part classification and recognition model to classify and recognize injection molded part images, output the different injection molded part categories that the detected objects in the image may belong to and their corresponding confidence levels, and sort them according to the confidence levels corresponding to different injection molded part categories.
[0066] S3. Use template matching to verify the detection results of the YOLOv8 model and output the final classification results; specifically including:
[0067] S31. Template preparation. Take and extract images of various injection molded parts separately to build a template library. The images of various injection molded parts are required to have obvious features, clear images, no occlusion and no dirt. Match the detected image with the standard template image according to the outer contour and surface shape gray value of the images in the template library;
[0068] S32. Obtain the image after classification and recognition by the injection molded part classification and recognition model, preprocess the image, and extract the outer contour of the object in the detection frame and the gray value of its surface shape;
[0069] S33. According to the confidence ranking result, match the detected injection molded part image with the template image of the corresponding injection molded part category, calculate the matching correlation coefficient, and obtain the final classification result. In this embodiment, it specifically includes:
[0070] S331. According to the confidence ranking result, determine the current matching category, and retrieve the template image of the current matching category in the template library; the current matching category is initially set as the injection molded part category corresponding to the highest confidence;
[0071] S332. Perform template matching verification on the template image of the current matching category and the detected image, and calculate the matching correlation coefficient; specifically calculating the matching correlation coefficient is as follows:
[0072] Perform binarization processing on the detected image and the template image to obtain the vector parameters t(r, c) and t(u, v) of the images respectively. The vector parameter represents the gray value t at the coordinate (r, c) in the detected image and the coordinate (u, v) in the template image. Then, overlap the outer contour regions of the two, and calculate the similarity of the matching condition between the template image and the covered area at this position;
[0073] Calculate the normalized cross-correlation coefficient (NCC) between the image detection regions and use it as the matching correlation coefficient for template matching. The calculation formula is:
[0074]
[0075] where T is the region of interest of the detection frame, n is the number of pixel points in the region of interest of the template, f(r + u, c + v) represents the gray value f at the current position in the region of interest, m t and are the average gray value and variance of the pixel points of the template image, m f (r, c) and are the average gray value and variance of the pixel points translated to the current position of the image; the normalized correlation coefficient reflects the similarity matching degree of the overlapping region between the template image and the detected image. The larger the normalized correlation coefficient, the stronger the similarity correlation of the overlapping region. When the absolute value of the normalized correlation coefficient is 1, it indicates a perfect match.
[0076] S333. When the matching correlation coefficient reaches the preset threshold, determine that the current matching category is the final classification result and output the injection molded part category; otherwise, determine that the injection molded part category cannot be used as the final classification result, set the current matching category as the injection molded part category corresponding to the next confidence, and jump to step S331.
[0077] For this embodiment, in actual implementation, the YOLOv8 model can be replaced by any one of Faster R-CNN, EfficientDet, or RetinaNet; the normalized cross-correlation coefficient can be replaced by any one of the mean squared error MSE, structural similarity SSIM, or Hamming distance.
[0078] As Figure 2 shown, it is an example of classification and recognition using the method described in this embodiment. Two pictures are given in the figure, as well as the confidence results of classification and recognition by the YOLOv8 model and template matching verification respectively; the results of YOLOv8 classification and recognition in the first row show that the category with the highest confidence ranking is YuanG (round cover). After matching with the corresponding YuanG (round cover) template picture, if the matching correlation coefficient reaches the given threshold, the final classification result output is YuanG (round cover); the results of YOLOv8 classification and recognition in the second row show that the category with the highest confidence ranking is YuanG (round cover). After matching with the corresponding YuanG (round cover) template picture, if the matching correlation coefficient is lower than the given threshold, it is necessary to perform template matching on the category template library in descending order of the confidence ranking. The label with the second highest confidence ranking is DiZ (base). After matching with the corresponding DiZ (base) template picture, its matching correlation coefficient is 0.77, which is higher than the given threshold, so the final classification result output is DiZ (base).
[0079] In another embodiment, an injection molded part precise classification and recognition system based on machine vision is provided. The system adopts the injection molded part precise classification and recognition method described in the above embodiment. The system includes an image acquisition module, a YOLOv8 classification module, and a template matching verification module;
[0080] The image acquisition module is used to acquire injection molded part images and construct an image dataset;
[0081] The YOLOv8 classification module is used to train and classify and recognize injection molded part images using the YOLOv8 model, and perform confidence ranking according to the classification and recognition results;
[0082] The template matching verification module uses template matching to verify the detection results of the YOLOv8 model and output the final classification result.
[0083] It should also be noted that in this specification, terms such as "including", "comprising" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising said element.
[0084] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for accurate classification and identification of injection molded parts based on machine vision, characterized in that: The following steps are involved: S1. Build an image acquisition system to collect images of injection molded parts and construct an image data set; S2. Train and use the YOLOv8 model to classify and identify images of injection molded parts, and rank the confidence levels according to the classification and recognition results; S3. Use template matching to verify the YOLOv8 model detection results and output the final classification results.
2. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 1, characterized in that: In step S1, the image acquisition system includes an industrial camera and a uniform light source. The resolution of the industrial camera is specifically 640×480, and the uniform light source is specifically an LED light source.
3. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 1, characterized in that: In step S1, constructing the image dataset is specifically as follows: The collected injection molded parts images are divided into a training set and a test set with a ratio of 9 to 1, wherein the real bounding boxes and label information are annotated on the training set images.
4. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 3 is characterized in that: In step S2, the training process of the YOLOv8 model includes: S21. Train the YOLOv8 model using the training set to obtain a trained injection molded parts classification and recognition model; S22, using the test set to test the trained injection molded parts classification and recognition model to obtain test results, adjusting the parameters of the YOLOv8 model according to the test results, and jumping to step S21 to continue model training until the test results meet the preset requirements to obtain the final injection molded parts classification and recognition model; During the YOLOv8 model training process, the bounding box regression loss function is calculated. The bounding box regression loss is used to measure the difference between the predicted position and the actual position of the target bounding box. The calculation formula is: Among them, x i represents the coordinates of the true bounding box, Represents the coordinates of the predicted bounding box, and N represents the number of bounding boxes; The bounding box regression loss function is used as the optimization objective to guide the YOLOv8 model to reduce the gap between the true bounding box and the predicted bounding box during training.
5. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 4, characterized in that: In step S2, confidence ranking is performed according to the classification and recognition results, specifically: The final obtained injection molded part classification and recognition model is used to classify and recognize the injection molded part images, and the different injection molded part categories and their corresponding confidence levels that the detected objects in the image may belong to are output, and the injection molded part categories are sorted according to the confidence levels corresponding to different injection molded part categories.
6. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 5, characterized in that: Step S3 specifically includes: S31, template preparation, respectively capturing and extracting a variety of injection molded parts images to construct a template library, wherein the various injection molded parts images are required to have obvious features, clear images, no obstructions and no dirt, and the image to be inspected is matched with the standard template image according to the outline contour and surface shape grayscale value of the image in the template library; S32, obtaining an image after classification and recognition by the injection molded part classification and recognition model, preprocessing the image, and extracting the outline of the object in the detection frame and its surface shape grayscale value; S33, sorting the results by confidence, matching the image of the injection molded part to be inspected with the template image of the corresponding injection molded part category, calculating the matching correlation coefficient, and obtaining the final classification result.
7. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 6, characterized in that: Step S33 is specifically as follows: S331, determining the current matching category according to the confidence ranking result, and retrieving the template image of the current matching category in the template library; the current matching category is initially set to the injection molded part category corresponding to the highest confidence; S332, performing template matching verification between the template image of the current matching category and the detected image, and calculating the matching correlation coefficient; S333. When the matching correlation coefficient reaches a preset threshold, the current matching category is determined to be the final classification result, and the injection molded part category is output; otherwise, the injection molded part category is determined not to be the final classification result, the current matching category is set as the injection molded part category corresponding to the next confidence level, and the process jumps to step S331.
8. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 7, characterized in that: The calculation of matching correlation coefficient is as follows: The detected image and the template image are binarized to obtain the vector parameters t(r,c) and t(u,v) of the images respectively. The vector parameter indicates that the gray value at the coordinates (r,c) in the detected image and (u,v) in the template image is t. Then the contour areas of the two are overlapped, and the similarity of the matching conditions between the template image and the coverage area is calculated at this position. Calculate the normalized mutual correlation coefficient between the image detection areas and use it as the matching correlation coefficient for template matching. The calculation formula is: Where T is the detection box region of interest, n is the number of pixels in the template region of interest, f(r+u,c+v) indicates the gray value in the region of interest at the current position is f, m t and is the average gray value and variance of the template image pixels, m f (r,c) and It is the average gray value and variance of the pixel translated to the current position of the image.
9. The method for accurate classification and identification of injection molded parts based on machine vision according to claim 8, characterized in that: The YOLOv8 model can be replaced by any of Faster R-CNN, Efficient Det or Retina Net; The normalized cross-correlation coefficient can be replaced by any of the mean square error MSE, structural similarity SSIM or Hamming distance.
10. A precise classification and identification system for injection molded parts based on machine vision, characterized in that: The system adopts the method for accurate classification and identification of injection molded parts according to any one of claims 1 to 9, and the system includes an image acquisition module, a YOLOv8 classification module, and a template matching verification module; An image acquisition module, used to acquire images of injection molded parts and construct an image data set; YOLOv8 classification module, used to train and use the YOLOv8 model to classify and identify injection molded parts images, and to sort the confidence levels based on the classification and identification results; The template matching verification module uses template matching to verify the detection results of the YOLOv8 model and output the final classification results.
Citation Information
Patent Citations
Engine rocker part classification method based on image feature extraction and template matching
CN113591923A
Injection molding part classification method and system based on image processing
CN114445379A
Image recognition method, AGV material sorting method and system
CN115937765A
Deep learning-based junk image classification and identification method
CN116434061A
Cited By
Intelligent injection molding part defect detection method and system based on machine vision
CN121147627A