A method for appearance quality inspection based on machine vision

By loading the template library and correcting the surface image of the packaging box, separating the character and pattern areas, calculating the area and center of mass distance, the problem of misdetection of traditional detection methods during rotation or scaling is solved, and automatic and accurate detection of surface defects of the packaging box is achieved. , reducing the cost of manual testing.

CN114549504BActive Publication Date: 2024-11-15ANHUI IND TECH INNOVATION RES INST LUAN INST +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210192665.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-01
Publication Date
2024-11-15
Estimated Expiration
2042-03-01

AI Technical Summary

Technical Problem

Traditional packaging box surface defect detection methods are prone to false detection when image rotation or scaling, and cannot accurately identify defects such as character bonding and pattern missing.

Method used

By loading the standard template images in the template library, collecting the surface image of the packaging box and performing correction processing, separating the character and pattern areas, calculating the area and centroid distance of each area, and determining whether it exceeds the set threshold to determine qualified or defective products.

Benefits of technology

Automatic and accurate detection of surface defects of packaging boxes is achieved, manual inspection costs are reduced, detection accuracy is improved, and it is not affected by the attitude of the packaging boxes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114549504B_ABST
    Figure CN114549504B_ABST
Patent Text Reader

Abstract

The present invention particularly relates to a method for detecting appearance quality based on machine vision, comprising the following steps: loading a template image of a current detection model packaging box in a template library; collecting a packaging box surface image after characters and patterns are printed; correcting the packaging box surface image to a system default detection position; performing adaptive threshold segmentation processing on the packaging box surface image corrected to a standard detection position, and separating the character area C1 and the pattern area P1 through a standard character area template image; and determining whether the separated character area C1 and pattern area P1 are qualified products by processing them. By separating characters from patterns, character defect detection mainly determines whether the product is qualified by finding character adhesion and missing, and pattern defect detection mainly determines whether the product is qualified by calculating whether the geometric moment meets the standard. This determination method is not affected by the posture of the packaging box, and the entire detection process is automatically completed by the machine, which reduces the cost of manual detection, and the detection accuracy is very high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine vision detection, and in particular to an appearance quality detection method based on machine vision. Background Art

[0002] Machine vision inspection technology has many advantages such as fast inspection speed, high inspection accuracy and strong inspection stability. In recent years, with the rapid development of my country's industrial automation field, machine vision inspection technology has been widely used in the field of printing defect detection on the surface of packaging boxes. This technology can accurately identify whether there are characters sticking, missing, misprinted, or missed on the surface of the packaging box. At present, the use of machine vision inspection technology for defect detection on the surface of packaging boxes has become an important research direction.

[0003] Most of the printing defects on the packaging box surface are manifested as excessive ink causing large differences in the adhesion of characters and the appearance of printed patterns, or insufficient ink causing unclear character imprints and blurred printed patterns. Therefore, the defects on the packaging box surface can be identified by collecting images of the packaging box surface. Traditional packaging box surface defect detection is mostly performed directly in the form of template matching. The similarity between the detection image and the standard template is determined based on the matching score between the two. The higher the similarity, the higher the matching score, indicating that the probability of defects on the packaging box surface is lower. However, when the collected image is rotated or scaled, it often fails to match and causes false detection. Summary of the invention

[0004] The object of the present invention is to provide a method for detecting appearance quality based on machine vision, which can automatically and accurately detect surface defects of packaging boxes.

[0005] To achieve the above purpose, the technical solution adopted by the present invention is: a method for detecting appearance quality based on machine vision, comprising the following steps: S100, loading the template image of the current detection model packaging box in the template library, each detection model including a standard template image, a standard detection area template image and a standard character area template image; S200, collecting the surface image of the packaging box after the characters and patterns are printed; S300, correcting the surface image of the packaging box to the system default detection position; S400, performing adaptive threshold segmentation processing on the surface image of the packaging box corrected to the system default detection position to obtain a binarized surface image of the packaging box, extracting the character area C1 and the pattern area P1 in the binarized surface image of the packaging box through the standard detection area template image, and separating the character area C1 and the pattern area P1 through the standard character area template image; S500, traversing the character area C1 , segment each character area into connected domains, calculate the areas of each connected domain after segmentation and find the character area C1-M with the largest area; S600, calculate the circumscribed rectangle C1-R of the character area C1-M with the largest area, use the circumscribed rectangle C1-R to deduct the corresponding character area in the standard template image, and calculate the character area C1-Y with the largest area, compare the result difference between the character area C1-M and the character area C1-Y, if the difference exceeds the set threshold, it is judged as a defective product, otherwise proceed to the next step; S700, traverse the pattern area P1, calculate the circumscribed rectangle P1-R of each pattern area P1-S, use the circumscribed rectangle P1-R to deduct the corresponding pattern area P1-Y in the standard template image, calculate the centroid distance between the pattern area P1-S and the pattern area P1-Y respectively, if the distance exceeds the set threshold, it is judged as a defective product, otherwise it is judged as a qualified product.

[0006] Compared with the prior art, the present invention has the following technical effects: by separating characters and patterns, character defect detection mainly determines whether it is a qualified product by finding character adhesion and missingness, and pattern defect detection mainly determines whether it is qualified or not by calculating whether the geometric moment meets the standard. This judgment method is not affected by the posture of the packaging box, and the entire detection process is automatically completed by the machine, which reduces the cost of manual detection and has a high detection accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0007] Figure 1 It is a schematic diagram of the process of the present invention;

[0008] Figure 2 It is the image preprocessing flow chart;

[0009] Figure 3 It is a character detection flow chart;

[0010] Figure 4 It is a pattern detection flow chart. DETAILED DESCRIPTION

[0011] Combine the following Figures 1 to 4 , the present invention is further described in detail.

[0012] See also Figure 1 , a method for detecting appearance quality based on machine vision, comprising the following steps: S100, loading a template image of a current detection model packaging box in a template library, wherein each detection model includes a standard template image, a standard detection area template image, and a standard character area template image; S200, collecting a packaging box surface image after characters and patterns are printed; S300, correcting the packaging box surface image to a system default detection position; S400, performing adaptive threshold segmentation processing on the packaging box surface image corrected to the system default detection position to obtain a binarized packaging box surface image, extracting a character area C1 and a pattern area P1 in the binarized packaging box surface image through the standard detection area template image, and separating the character area C1 and the pattern area P1 through the standard character area template image; S500, traversing the character area C1, and performing segmentation processing on each character area Connected domain segmentation, calculate the area of ​​each connected domain after segmentation and find the character area C1-M with the largest area; S600, calculate the circumscribed rectangle C1-R of the character area C1-M with the largest area, use the circumscribed rectangle C1-R to deduct the corresponding character area in the standard template image, and calculate the character area C1-Y with the largest area, compare the result difference between the character area C1-M and the character area C1-Y, if the difference exceeds the set threshold, it is judged as a defective product, otherwise proceed to the next step; S700, traverse the pattern area P1, calculate the circumscribed rectangle P1-R of each pattern area P1-S, use the circumscribed rectangle P1-R to deduct the corresponding pattern area P1-Y in the standard template image, calculate the center of mass distance between the pattern area P1-S and the pattern area P1-Y respectively, if the distance exceeds the set threshold, it is judged as a defective product, otherwise it is judged as a qualified product. By separating characters and patterns, character defect detection mainly determines whether it is a qualified product by finding character adhesion and missingness, and pattern defect detection mainly determines whether it is qualified by calculating whether the geometric moment meets the standard. This judgment method is not affected by the posture of the packaging box, and the entire detection process is completed automatically by the machine, which reduces the cost of manual inspection and has a high detection accuracy.

[0013] See also Figure 2There are many solutions to correct the surface image of the packaging box. In the present invention, the step S300 further includes the following steps: S310, calculating the average grayscale value of the surface image of the packaging box, performing adaptive threshold segmentation processing, calculating the rectangularity of each segmented area, and selecting the area with the best rectangularity as the image correction mark area R-MD; S320, extracting the center point coordinates and rotation angle of the image correction mark area R-MD, calling the center point coordinate position and rotation angle parameters of the system default rectangularity best area, and calculating the affine transformation matrix of the surface image of the packaging box; S330, correcting the surface image of the packaging box to the system default detection position through the calculated affine transformation matrix. By extracting the center point coordinates and rotation angle, then calculating the affine transformation matrix, and finally correcting according to the matrix, this solution has less calculation and very fast processing speed.

[0014] Furthermore, the step S310 includes the following steps: S311, calculating the average gray value G of the packaging box surface image by the following formula: A :

[0015]

[0016] S312, using the average gray value G of the packaging box surface image A The image is segmented by adaptive thresholding, by traversing each pixel gray value G P , judge G P and G A If G P <G A , then G P =255, otherwise G P =0; S313, obtain the binary image of the packaging box surface through the previous step, and calculate the rectangularity of each area in the binary image according to the following formula:

[0017]

[0018] If R M <R N , then let R0=R1, where R M Indicates the rectangularity value of the area with the best rectangularity at present, S0 represents the area of ​​the current area, S Minr represents the area of ​​the minimum circumscribed rectangle of the current region, R0 represents the region with the best rectangularity, and R1 represents the current detection region. The image correction mark region R-MD can be conveniently selected through the above steps.

[0019] Furthermore, in step S320, the affine transformation matrix includes a translation matrix and a rotation matrix, which are calculated by the following formulas respectively:

[0020] S321, calculate the translation matrix of the image correction mark area R-MD according to the following formula:

[0021]

[0022] In this formula, the 3×3 matrix is ​​the translation matrix, x and y represent the coordinates of the center point of the image correction mark area R-MD, and x′ and y′ represent the coordinates of the center point of the system default matrix optimal area;

[0023] S322, calculate the rotation matrix of the image correction mark area R-MD according to the following formula:

[0024]

[0025] In this formula, the 3×3 matrix is ​​the rotation matrix, θ represents the rotation angle of the image correction mark area R-MD, x′ and y′ here are consistent with those in step S321, and x″ and y″ represent the output coordinate calculation values;

[0026] S323, correcting each pixel of the packaging box surface image by using the translation matrix and the rotation matrix to obtain the system default detection position. By using the rotation matrix and the translation matrix, the packaging box surface image can be corrected very conveniently.

[0027] See also Figure 3 , further, in the step S600, the corresponding character area is deducted from the standard template image according to the following steps: S610, calculate the upper left corner coordinates tr and the lower right corner coordinates br of the circumscribed rectangle C1-R of the character area C1-M; S620, use the upper left corner coordinates tr and the lower right corner coordinates br to deduct the corresponding character area from the standard template image; in step S600, if (C1-M) ≤ 0.8 * (C1-Y) or (C1-M) ≥ 1.2 * (C1-Y), it is determined to be a defective product. The parameters 0.8 and 1.2 here are the preferred values ​​in this embodiment, and other values ​​can also be selected in actual setting.

[0028] See also Figure 4 Further, in the step S700, the centroid distance is calculated as follows: S710, by the geometric moment M of the pattern area ji Calculate the coordinates of its center of mass (C x , C y ):

[0029]

[0030] S720, calculate the centroid coordinates (C′) of the pattern area P1-S according to the above formula x , C′ y) and the centroid coordinates (C″) of the standard template image pattern area P1-Y x , C″ y ); S730, calculate the centroid coordinate distance by the following formula:

[0031]

[0032] Through the above formula, the center of mass coordinates can be easily calculated.

[0033] Furthermore, in the step S200, after the characters and patterns on the surface of the packaging box are printed, the packaging box is transported to the inspection station through a conveyor belt. A photoelectric sensor is installed at the bottom of the inspection station, and an industrial camera is installed above the inspection station. When the photoelectric sensor is triggered, the industrial camera collects the surface image of the packaging box. After this arrangement, the packaging box is continuously transported through the conveyor belt. Every time it arrives at the inspection station, the industrial camera will collect images and output the images to the industrial computer or computer for processing and judgment according to the above steps. When it is judged to be a defective product, the packaging box can be removed by a push rod or a blower, and the remaining qualified products continue to be output on the conveyor belt. The entire inspection process does not require human participation and is completed automatically, and the accuracy and speed of the inspection are very high.

[0034] Furthermore, the present invention also discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, a method for detecting appearance quality based on machine vision in any of the above embodiments is implemented. An electronic device is also disclosed, including a memory, a processor, and a computer program stored in the memory, and when the processor executes the computer program, a method for detecting appearance quality based on machine vision in any of the above embodiments is implemented.

Claims

1. A method for appearance quality inspection based on machine vision, Features: The steps include: S100, loading the template image of the current detection model packaging box in the template library, each detection model includes a standard template image, a standard detection area template image and a standard character area template image; S200, collecting the image of the packaging box surface after the characters and patterns are printed; S300, correcting the surface image of the packaging box to a system default detection position; S400, performing adaptive threshold segmentation processing on the packaging box surface image corrected to the system default detection position to obtain a binarized packaging box surface image, extracting the character area C1 and the pattern area P1 in the binarized packaging box surface image through a standard detection area template image, and separating the character area C1 and the pattern area P1 through a standard character area template image; S500, traverse the character region C1, segment each character region into connected domains, calculate the area of ​​each connected domain after segmentation, and find the character region C1-M with the largest area; S600, calculating the circumscribed rectangle C1-R of the character area C1-M with the largest area, using the circumscribed rectangle C1-R to deduct the corresponding character area in the standard template image, and calculating the character area C1-Y with the largest area, comparing the result difference between the character area C1-M and the character area C1-Y, if the difference exceeds the set threshold, it is determined to be a defective product, otherwise, proceed to the next step; S700, traverse the pattern area P1, calculate the circumscribed rectangle P1-R of each pattern area P1-S, use the circumscribed rectangle P1-R to deduct the corresponding pattern area P1-Y in the standard template image, and calculate the centroid distance between the pattern area P1-S and the pattern area P1-Y respectively. If the distance exceeds the set threshold, it is judged as a defective product, otherwise it is judged as a qualified product.

2. The appearance quality detection method based on machine vision as claimed in claim 1, Features: The step S300 includes the following steps: S310, calculating the average gray value of the packaging box surface image, performing adaptive threshold segmentation processing, calculating the rectangularity of each segmented area, and selecting the area with the best rectangularity as the image correction mark area R-MD; S320, extracting the center point coordinates and rotation angle of the image correction mark area R-MD, calling the center point coordinate position and rotation angle parameters of the system default rectangular optimal area, and calculating the affine transformation matrix of the packaging box surface image; S330, correcting the packaging box surface image to the system default detection position through the calculated affine transformation matrix.

3. The appearance quality detection method based on machine vision as claimed in claim 2, Features: The step S310 includes the following steps: S311, calculate the average gray value G of the packaging box surface image by the following formula A : S312, using the average gray value G of the packaging box surface image A The image is segmented by adaptive thresholding, by traversing each pixel gray value G P , judge G P and G A If G P <G A , then G P =255, otherwise G P =0; S313, a binary image of the packaging box surface is obtained through the previous step, and the rectangularity of each area in the binary image is calculated according to the following formula: If R M <R N , then let R 0 =R 1 , where R M Indicates the rectangularity value of the area with the best rectangularity at present, S 0 Indicates the area of ​​the current region, S MinR Represents the area of ​​the minimum enclosing rectangle of the current region, R 0 Indicates the area with the best rectangularity at present, R 1 Indicates the current detection area.

4. The appearance quality detection method based on machine vision as claimed in claim 3, Features: In step S320, the affine transformation matrix includes a translation matrix and a rotation matrix, which are calculated by the following formulas: S321, calculate the translation matrix of the image correction mark area R-MD according to the following formula: In this formula, the 3×3 matrix is ​​the translation matrix, x and y represent the center coordinates of the image correction mark area R-MD, and x' and y' represent the center coordinates of the system default matrix optimal area; S322, calculate the rotation matrix of the image correction mark area R-MD according to the following formula: In this formula, the 3×3 matrix is ​​the rotation matrix, θ represents the rotation angle of the image correction mark area R-MD, and x” and y” represent the output coordinate calculation values; S323. Correct each pixel of the packaging box surface image through the translation matrix and the rotation matrix to obtain the system default detection position.

5. The appearance quality detection method based on machine vision as claimed in claim 4, Features: In step S600, the corresponding character area is extracted from the standard template image according to the following steps: S610, calculating the coordinates tr of the upper left corner and the coordinates br of the lower right corner of the circumscribed rectangle C1-R of the character area C1-M; S620, using the upper left corner point coordinates tr and the lower right corner point coordinates br to deduct the corresponding character area from the standard template image; In step S600, if (C1-M)≤0.8*(C1-Y) or (C1-M)≥1.2*(C1-Y), it is determined to be a defective product.

6. The appearance quality detection method based on machine vision as claimed in claim 5, Features: In step S700, the centroid distance is calculated as follows: S710, through the geometric moment M of the pattern area ji Calculate the coordinates of its center of mass (C x ,C y ): S720, calculate the centroid coordinates (C') of the pattern area P1-S according to the above formula x ,C' y ) and the centroid coordinates (C″) of the standard template image pattern area P1-Y x ,C″ y ); S730. Calculate the centroid coordinate distance using the following formula:

7. The appearance quality inspection method based on machine vision as claimed in claim 1, Features: In the step S200, after the characters and patterns on the surface of the packaging box are printed, the packaging box is transported to the inspection station via a conveyor belt. A photoelectric sensor is installed at the bottom of the inspection station, and an industrial camera is installed above the inspection station. When the photoelectric sensor is triggered, the industrial camera collects the surface image of the packaging box.

8. A computer-readable storage medium, Features: A computer program is stored thereon, and when the computer program is executed by a processor, a method for detecting appearance quality based on machine vision as described in any one of claims 1 to 7 is implemented.

9. An electronic device, Features: The invention comprises a memory, a processor and a computer program stored in the memory. When the processor executes the computer program, a method for detecting appearance quality based on machine vision as described in any one of claims 1 to 7 is implemented.