Printing pattern defect detection method, system and readable storage medium
By performing image registration, size adjustment, brightness and darkness threshold segmentation, and stroke template correction in printed pattern defect detection, the detection problems caused by stroke thickness and positional deviations are solved, achieving high-precision defect detection.
Patent Information
- Application Number
- CN202410804170.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2044-06-21
AI Technical Summary
Existing technologies cannot adapt to changes in stroke thickness and positional deviations in printed pattern defect detection, leading to problems of over-detection and under-detection.
By reading the image to be detected, the target detection area is obtained, registration is performed to obtain the actual center position and angle of the local pattern, the image size is adjusted using a preset average template, and defect segmentation and correction are performed using brightness thresholds and thick/thin stroke templates, combined with preset defect conditions for detection.
It effectively detects defects in printed patterns, adapts to changes in stroke thickness and positional deviations, improves detection accuracy, and avoids over-detection and under-detection.
Smart Images

Figure CN118379279B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and more specifically, to a printing pattern defect detection method, system and readable storage medium. Background Art
[0002] During the production process of printed products, they are often affected by mechanical precision, printing technology, etc., making it difficult to ensure the quality of printing. Usually, it is necessary to perform defect detection on the printed pattern to determine whether it is a qualified product, and reprint the defective products.
[0003] At present, the industry usually uses machine vision-based methods to detect printed pattern defects. The conventional method is to collect multiple good printed images as templates, register the multiple templates one by one, calculate the average template of the registered images and save them. During the printing process, the saved average template is called to register the detection target, and the template and registered images are differentiated. The area with the difference is the defect.
[0004] However, conventional methods have many problems and shortcomings. For example, printed patterns usually have some differences in stroke thickness, which is a normal phenomenon and usually not considered a defect. Conventional methods cannot adapt to changes in stroke thickness, and are very likely to cause over-inspections when doing differentials. For example, the positional relationship between printed patterns is not completely fixed in practice. Limited by the precision of the printing machinery, there may be positional deviations and angle deviations in their positional relationship. Directly using the overall template for comparison cannot adapt, resulting in more over-inspections and missed inspections. Summary of the invention
[0005] The object of the present invention is to provide a printing pattern defect detection method, system and readable storage medium, which can effectively detect printing pattern defects and adapt to changes in the thickness of printed pattern strokes and positional relationship deviations.
[0006] A first aspect of the present invention provides a method for detecting printed pattern defects, comprising the following steps:
[0007] Read the image to be detected and obtain the target detection area;
[0008] Registering the image to be detected to obtain target data in the image to be detected, wherein the target data includes an actual center position and angle of a local pattern in a target detection area;
[0009] Extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size using a preset average template;
[0010] Defect segmentation is performed on the resized local pattern using a preset brightness and darkness threshold;
[0011] Using a preset thick / thin stroke template, the defect-corrected image is corrected to obtain a corrected image;
[0012] Defect information of the corrected image is calculated based on a preset defect condition to complete defect detection.
[0013] In this solution, the method further includes registering template data, wherein the template data includes a position of a pattern template, a pattern, a binary mask, an average template, and a thick / thin stroke template.
[0014] In this solution, registering the template data specifically includes:
[0015] Acquire an original image and a user-set benchmark, wherein the user-set benchmark includes a benchmark template image and a center coordinate of a benchmark template image frame;
[0016] Performing image processing on the original image to obtain a minimum bounding box of each pattern template, wherein the processing process includes binarization processing, average gray value calculation, denoising processing, closing operation processing and connected domain retrieval;
[0017] The template data is calculated based on the minimum bounding box, wherein:
[0018] The position of the pattern template is obtained by converting the minimum bounding box in combination with the center coordinates of the reference template image frame;
[0019] Based on the minimum bounding box, a pattern of the pattern template is obtained by intercepting it from the original image;
[0020] Obtaining a binary mask of a pattern template from the image in the closing operation process based on the minimum bounding box;
[0021] Obtaining the average template based on the pattern of the pattern template;
[0022] A thick / thin stroke template of the pattern template is obtained by cutting out the binary image after denoising based on the minimum bounding box.
[0023] In this solution, registering the image to be detected to obtain target data in the image to be detected specifically includes:
[0024] Registering the image to be detected based on the user-set reference to obtain a reference center position in the image to be detected and an angle relative to a reference template image;
[0025] Based on the reference center position and the angle relative to the reference template image combined with the pattern template, the area where each image to be detected is located is converted to obtain a local area;
[0026] The target data is obtained by performing pattern registration in a local area using an average template, wherein the actual center position and angle of the local pattern are specifically obtained.
[0027] In this solution, the local pattern is cut out from the image to be detected based on the actual center position and angle, and the image size is adjusted using a preset average template, specifically including:
[0028] Extracting the local pattern from the image to be detected based on a preset extraction range;
[0029] The average template is rotated to the local pattern position with the center position of the image as the rotation center, and the image of the average template is adjusted to the size of the local pattern, wherein the pixel value of the background area is filled with the calculated average gray value.
[0030] In this solution, the defect segmentation of the resized local pattern using the preset brightness threshold specifically includes:
[0031] Obtain the light and dark thresholds preset by the user to obtain the light threshold and the dark threshold;
[0032] Performing full black mapping on the resized local pattern to obtain a bright defect map and a dark defect map;
[0033] Extracting a pixel value of the image of the average template as a first pixel value, and extracting a pixel value of the local pattern as a second pixel value;
[0034] The relationship between the difference between the first pixel value and the second pixel value and the bright threshold and the dark threshold is compared, so as to adjust the pixels of the bright defect map and the dark defect map.
[0035] In this solution, the defect correction of the image after defect segmentation using the preset thick / thin stroke template to obtain the corrected image specifically includes:
[0036] The pixel value of the region where the pixel value of the thick stroke image is zero in the defect segmented image is set to zero to shield the thick stroke defect;
[0037] The pixel values of the areas with full pixel values in the fine stroke image in the defect segmented image are reset to zero to mask the fine stroke defects.
[0038] In this solution, the preset defect conditions specifically include: the area of the connected domain is larger than the preset minimum defect area, and the shortest side of the connected domain is larger than the preset minimum defect width.
[0039] The second aspect of the present invention further provides a printed pattern defect detection system, comprising a memory and a processor, wherein the memory comprises a printed pattern defect detection method program, and when the printed pattern defect detection method program is executed by the processor, the following steps are implemented:
[0040] Read the image to be detected and obtain the target detection area;
[0041] Registering the image to be detected to obtain target data in the image to be detected, wherein the target data includes an actual center position and angle of a local pattern in a target detection area;
[0042] Extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size using a preset average template;
[0043] Defect segmentation is performed on the resized local pattern using a preset brightness and darkness threshold;
[0044] Using a preset thick / thin stroke template, the defect-corrected image is corrected to obtain a corrected image;
[0045] Defect information of the corrected image is calculated based on a preset defect condition to complete defect detection.
[0046] In this solution, the method further includes registering template data, wherein the template data includes a position of a pattern template, a pattern, a binary mask, an average template, and a thick / thin stroke template.
[0047] In this solution, registering the template data specifically includes:
[0048] Acquire an original image and a user-set benchmark, wherein the user-set benchmark includes a benchmark template image and a center coordinate of a benchmark template image frame;
[0049] Performing image processing on the original image to obtain a minimum bounding box of each pattern template, wherein the processing process includes binarization processing, average gray value calculation, denoising processing, closing operation processing and connected domain retrieval;
[0050] The template data is calculated based on the minimum bounding box, wherein:
[0051] The position of the pattern template is obtained by converting the minimum bounding box in combination with the center coordinates of the reference template image frame;
[0052] Based on the minimum bounding box, a pattern of the pattern template is obtained by intercepting it from the original image;
[0053] Obtaining a binary mask of a pattern template from the image in the closing operation process based on the minimum bounding box;
[0054] Obtaining the average template based on the pattern of the pattern template;
[0055] A thick / thin stroke template of the pattern template is obtained by cutting out the binary image after denoising based on the minimum bounding box.
[0056] In this solution, registering the image to be detected to obtain target data in the image to be detected specifically includes:
[0057] Registering the image to be detected based on the user-set reference to obtain a reference center position in the image to be detected and an angle relative to a reference template image;
[0058] Based on the reference center position and the angle relative to the reference template image combined with the pattern template, the area where each image to be detected is located is converted to obtain a local area;
[0059] The target data is obtained by performing pattern registration in a local area using an average template, wherein the actual center position and angle of the local pattern are specifically obtained.
[0060] In this solution, the local pattern is cut out from the image to be detected based on the actual center position and angle, and the image size is adjusted using a preset average template, specifically including:
[0061] Extracting the local pattern from the image to be detected based on a preset extraction range;
[0062] The average template is rotated to the local pattern position with the center position of the image as the rotation center, and the image of the average template is adjusted to the size of the local pattern, wherein the pixel value of the background area is filled with the calculated average gray value.
[0063] In this solution, the defect segmentation of the resized local pattern using the preset brightness threshold specifically includes:
[0064] Obtain the light and dark thresholds preset by the user to obtain the light threshold and the dark threshold;
[0065] Performing full black mapping on the resized local pattern to obtain a bright defect map and a dark defect map;
[0066] Extracting a pixel value of the image of the average template as a first pixel value, and extracting a pixel value of the local pattern as a second pixel value;
[0067] The relationship between the difference between the first pixel value and the second pixel value and the bright threshold and the dark threshold is compared, so as to adjust the pixels of the bright defect map and the dark defect map.
[0068] In this solution, the defect correction of the image after defect segmentation using the preset thick / thin stroke template to obtain the corrected image specifically includes:
[0069] The pixel value of the region where the pixel value of the thick stroke image is zero in the defect segmented image is set to zero to shield the thick stroke defect;
[0070] The pixel values of the areas with full pixel values in the fine stroke image in the defect segmented image are reset to zero to mask the fine stroke defects.
[0071] In this solution, the preset defect conditions specifically include: the area of the connected domain is larger than the preset minimum defect area, and the shortest side of the connected domain is larger than the preset minimum defect width.
[0072] The third aspect of the present invention provides a computer-readable storage medium, which includes a printing pattern defect detection method program for a machine. When the printing pattern defect detection method program is executed by a processor, the steps of a printing pattern defect detection method as described in any one of the above items are implemented.
[0073] The present invention discloses a printing pattern defect detection method, system and readable storage medium, which can effectively detect printing pattern defects and adapt to changes in the thickness of printed pattern strokes and position relationship deviations, wherein:
[0074] In response to positional relationship deviations, the overall template is broken up and only local useful templates are retained for flexible combination, which improves the algorithm's adaptability to positional deviations and detection accuracy.
[0075] In response to changes in the thickness of pattern strokes, by learning the thickness characteristics of the strokes, defects can be corrected using the thickness characteristics during defect detection, which can effectively avoid over-inspection caused by the thickness of the strokes.
[0076] For non-defect interference items, a pattern mask is obtained, and a light and dark defect shielding mask is created in the defect detection link. Shielding the detection interference caused by non-defects can effectively avoid over-inspection caused by non-defective parts. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] Figure 1 A flow chart of a printing pattern defect detection method of the present invention is shown;
[0078] Figure 2 A schematic diagram showing an image to be detected in an embodiment of a printing pattern defect detection method of the present invention;
[0079] Figure 3 A schematic diagram of an original image in an embodiment of a printing pattern defect detection method of the present invention is shown;
[0080] Figure 4 A schematic diagram of a reference template image in an embodiment of a printed pattern defect detection method of the present invention is shown;
[0081] Figure 5 A binary image of a detection area after denoising in a printing pattern defect detection method in one embodiment of the present invention is shown;
[0082] Figure 6 A binary image of a detection area after a closing operation in an embodiment of a printing pattern defect detection method of the present invention is shown;
[0083] Figure 7 A schematic diagram showing a minimum bounding box in an embodiment of a printed pattern defect detection method of the present invention;
[0084] Fig. 8A A schematic diagram showing a pattern template in an embodiment of a printed pattern defect detection method of the present invention;
[0085] Figure 8B A mask schematic diagram of a pattern template in an embodiment of a printed pattern defect detection method of the present invention is shown;
[0086] Figure 8C A schematic diagram showing an average template in an embodiment of a printing pattern defect detection method of the present invention;
[0087] Fig.8D A schematic diagram showing a fine stroke template in an embodiment of a printing pattern defect detection method of the present invention;
[0088] Fig. 8E A schematic diagram showing a thick stroke template in an embodiment of a printing pattern defect detection method of the present invention;
[0089] Fig. 9 A schematic diagram showing four corner points of a printing pattern defect detection method in one embodiment of the present invention;
[0090] Fig.10 A schematic diagram of a local search area in an embodiment of a printing pattern defect detection method of the present invention is shown;
[0091] Fig.11A A schematic diagram showing image correction in an embodiment of a printing pattern defect detection method of the present invention is shown;
[0092] Fig. 11B A schematic diagram showing another image correction in an embodiment of a printing pattern defect detection method of the present invention;
[0093] Fig. 11CA schematic diagram showing another image correction in an embodiment of a printing pattern defect detection method of the present invention;
[0094] Fig.11D A schematic diagram showing another image correction in an embodiment of a printing pattern defect detection method of the present invention;
[0095] Fig.12 A block diagram of a printing pattern defect detection system of the present invention is shown. DETAILED DESCRIPTION
[0096] In order to more clearly understand the above-mentioned purpose, features and advantages of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0097] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the protection scope of the present invention is not limited to the specific embodiments disclosed below.
[0098] Figure 1 A flow chart of a printing pattern defect detection method of the present application is shown.
[0099] like Figure 1 As shown, the present application discloses a printing pattern defect detection method, comprising the following steps:
[0100] S102, reading the image to be detected and obtaining the target detection area;
[0101] S104, registering the image to be detected to obtain target data in the image to be detected;
[0102] S106, extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size using a preset average template;
[0103] S108, performing defect segmentation on the resized local pattern using a preset brightness threshold;
[0104] S110, using a preset thick / thin stroke template to perform defect correction on the defect segmented image to obtain a corrected image;
[0105] S112, calculating defect information of the corrected image based on a preset defect condition to complete defect detection.
[0106] It should be noted that, in this embodiment, Figure 2As shown, it is a schematic diagram of the image to be detected, wherein the saved reference template is aligned in the image to be detected to obtain the center position of the reference in the detection image and its angle relative to the reference template, wherein the alignment method can be selected based on contour alignment, cross-correlation-based alignment, etc., which is equivalent to calculating the translation position and rotation angle through alignment, and through translation and rotation calculation, the pattern in the template and the corresponding pattern in the alignment image can be overlapped.
[0107] Furthermore, the approximate area where each pattern to be detected is located is converted according to the reference center position, angle and the set of saved image template relative reference positions, and is used as the local area. The local pattern is aligned in the local area by using the corresponding saved pattern average template to obtain the actual center position and angle of the local pattern in the detection image, and according to the obtained actual center position and angle of the local pattern, the local pattern in the detection image is cut out (when cutting out, the cut-out range is appropriately enlarged, because the defect may be connected to the character outside the character), the average template is rotated to the local pattern orientation with the image center position as the rotation center, and the average template image is adjusted to the local pattern size (the average pixel value of the background area obtained in S5 is filled in all directions outward).
[0108] Furthermore, the defect segmentation of the resized local pattern is performed using preset light and dark thresholds, corresponding to a bright defect map and a dark defect map, as described in detail in the subsequent description, and the defect correction of the image after defect segmentation is performed using a preset thick / thin stroke template to obtain a corrected image, wherein the correction method is: shielding defects outside the thick strokes (setting the pixel value to zero in the area where the defect image corresponds to the pixel value of "0" in the thick stroke image), shielding defects within the thin strokes (setting the pixel value to zero in the area where the defect image corresponds to the pixel value of "255" in the thin stroke image); and calculating the defect information of the corrected image based on preset defect conditions to complete defect detection, wherein the preset defect conditions specifically include: the area of the connected domain is greater than the preset minimum defect area, and the shortest side of the connected domain is greater than the preset minimum defect width.
[0109] According to an embodiment of the present invention, the method further comprises registering template data, wherein the template data comprises a position, a pattern, a mask, an average template and a thick / thin stroke template of a pattern template.
[0110] It should be noted that in this embodiment, when performing detection, it is necessary to obtain a reference template in advance, and accordingly, it is necessary to register the template data first, wherein the template data includes the position, pattern, mask, average template and thick / thin stroke template of the pattern template. The specific registration steps are described in the subsequent description, wherein mask is an image binarization mask.
[0111] According to an embodiment of the present invention, registering the template data specifically includes:
[0112] Acquire an original image and a user-set benchmark, wherein the user-set benchmark includes a benchmark template image and a center coordinate of a benchmark template image frame;
[0113] Performing image processing on the original image to obtain a minimum bounding box of each pattern template, wherein the processing process includes binarization processing, average gray value calculation, denoising processing, closing operation processing and connected domain retrieval;
[0114] The template data is calculated based on the minimum bounding box, wherein:
[0115] The position of the pattern template is obtained by converting the minimum bounding box in combination with the center coordinates of the reference template image frame;
[0116] Based on the minimum bounding box, a pattern of the pattern template is obtained by intercepting it from the original image;
[0117] Obtaining a binary mask of a pattern template from the image in the closing operation process based on the minimum bounding box;
[0118] Obtaining the average template based on the pattern of the pattern template;
[0119] A thick / thin stroke template of the pattern template is obtained by cutting out the binary image after denoising based on the minimum bounding box.
[0120] It should be noted that, in this embodiment, Figure 3 As shown, the original image is displayed, wherein the framed area is the detection area, and the user frames the reference template image in the detection area image, and sets the reference template image and the reference template image frame center coordinates (X base ,Y base ) for record keeping, where X base is the horizontal coordinate of the center coordinate of the reference template image frame, Y base The vertical coordinate is the center coordinate of the reference template image frame. The reference template is used to determine the relative position of the printed pattern. The position of each printed pattern will be converted according to the position of the reference template. Therefore, the reference template generally selects a pattern with unique and obvious features. For example, as shown in Figure 4, the frame selection is displayed as a reference template image.
[0121] Further, the original image is processed to obtain the minimum bounding box of each pattern, wherein the entire detection area is binarized, the pixel value of the white area of the image is "255", and the pixel value of the black area is "0", and the optional binarization methods include local adaptive segmentation, global adaptive segmentation, fixed threshold segmentation, etc., and the average gray value of the background of the detection area is calculated. The calculation method is to map the area (background area) where the pixel of the binary image of the detection area is "0" to the detection area image, and calculate the pixel average value of the background area as the background average gray value, and the average gray value is used to fill the background when the template or detection image is resized; and the binary image of the detection area is denoised to eliminate interference whose connected domain area is smaller than the set minimum pattern area, wherein, if Figure 5 As shown, it is a binary image of the detection area after denoising.
[0122] Furthermore, the denoised detection area binary image is closed. The main purpose is to detect some patterns as a whole (such as the character "i"), improve the conspicuity of pattern features, and improve detection stability. The closing operation can also eliminate some internal holes. Figure 6 As shown, it is a binary image of the detection area after the closing operation.
[0123] Furthermore, the connected domain in the binary image of the detection area after the closing operation is retrieved to obtain the minimum bounding box of each pattern connected domain {(X1, Y1, W1, H1), (X2, Y2, W2, H2), (X3, Y3, W3, H3), ..., (X n ,Y n ,W n ,H n )}, where X and Y represent the upper left corner abscissa and upper left corner ordinate of the minimum bounding box, respectively, W and H represent the width and height of the minimum bounding box, respectively, and n is the number of minimum bounding boxes. Figure 7 As shown, it is shown as a schematic diagram of the minimum bounding box.
[0124] Furthermore, the template information is calculated, and the template information includes the position set, template set, mask set, average template set, thin stroke template set, and thick stroke template set of each pattern template. base ,Y base ) is used for conversion, and the relative position of each pattern is recorded as {(X1-X base ,Y1-Y base ,W1,H1),(X2-X base ,Y2-Y base ,W2,H2),(X3-X base ,Y3-Y base ,W3,H3),...,(Xn -X base ,Y n -Y base ,W n ,H n )}; The set is obtained by intercepting the minimum bounding box set from the detection area image, where, Fig. 8A As shown, it is a schematic diagram of a pattern template; based on the minimum bounding box, a mask of the pattern template is obtained from the image in the closing operation process, wherein, Figure 8B As shown, it is a mask schematic diagram of a pattern template; the average template is obtained based on the pattern of the pattern template, such as Figure 8C As shown, it is a schematic diagram of an average template; based on the minimum bounding box, a thick / thin stroke template of the pattern template is obtained from the binary image after denoising, wherein, Fig.8D 8A and 8B are schematic diagrams of thin stroke templates, and 8C are schematic diagrams of thick stroke templates.
[0125] When applying, it is necessary to collect multiple images with good patterns for learning, traverse the collected images, select the area where the pattern is located, and learn the pattern features in the image.
[0126] According to an embodiment of the present invention, registering the image to be detected to obtain target data in the image to be detected specifically includes:
[0127] Registering the image to be detected based on the user-set reference to obtain a reference center position in the image to be detected and an angle relative to a reference template image;
[0128] Based on the reference center position and the angle relative to the reference template image combined with the pattern template, the area where each image to be detected is located is converted to obtain the local area;
[0129] The target data is obtained by performing pattern registration in a local area using an average template, wherein the actual center position and angle of the local pattern are specifically obtained.
[0130] It should be noted that, in this embodiment, the center position (X base ’ ,Y base ’ ) and its angle theta relative to the reference template, where X base is the horizontal coordinate of the center coordinate of the reference template image frame, Y baseIt is the ordinate of the center coordinate of the reference template image frame. The registration method can be selected from contour-based registration, cross-correlation-based registration, etc., which is equivalent to calculating the translation position and rotation angle through registration. Through translation and rotation calculation, the pattern in the template and the corresponding pattern in the registered image can be overlapped, and the approximate area where each pattern to be learned is located is converted according to the reference center position, angle and the saved image template relative to the reference position set as the local retrieval area.
[0131] Specifically, first, according to the reference center of the registration (X base ’ ,Y base ’ ) and the saved image template relative reference position set, calculate the corresponding corner point coordinates of the four corner points of the minimum bounding box of each pattern before rotation in the learning image area.
[0132] For example, the coordinates of the upper left corner of the pattern corresponding to the bounding box (X1, Y1, W1, H1) in the learning image are (X1-X base +X base ’ ,Y1-Y base +Y base ’ ), the coordinates of the upper right corner are (X1-X base +W1+X base ’ ,Y1-Y base +Y base ’ ), the coordinates of the lower right corner are (X1-X base +W1+X base ’ ,Y1-Y base +H1+Y base ’ ), the coordinates of the lower left corner are (X1-X base +X base ’ ,Y1-Y base +H1+Y base ’ ). The image coordinates of the four corner points of each box are expressed as (X base ’ ,Y base ’ ) is the center of rotation theta, and the image coordinates of the corner points after rotation are calculated. The coordinates of one of the corner points obtained are recorded as (X corner ,Y corner ), the coordinates after rotation are (X r_corner ,Y r_corner ), the calculation formula of the rotated image coordinates is: ,
[0133] ,
[0134] Convert all corner point coordinates according to the formula to obtain the corner point coordinates of each pattern bounding box corner point after rotation relative to the reference center. Fig. 9 For example, the diagram shows four corner points. The coordinates of the four corner points after the rotation of one of the bounding boxes are P1 (X r_corner1 , Y r_corner1 )、P2(X r_corner2 , Y r_corner2 )、P3(X r_corner3 , Y r_corner3 )、P4(X r_corner4 , Y r_corner4 ). Find X r_corner1 , X r_corner2 , X r_corner3 , X r_corner4 The minimum and maximum values in min , X max , find Y r_corner1 , Y r_corner2 , Y r_corner3 , Y r_corner4 The minimum and maximum values in min , Y max , calculate the local search area (X part ,Y part ,W part ,H part ).
[0135] ,
[0136] ,
[0137] Where X part is the horizontal coordinate of the upper left corner of the local search area, Y part is the upper left corner ordinate of the local search area, W part is the width of the local search area, H part is the height of the local search area. Fig.10 As shown, it is a schematic diagram of the local search area, where T w is the width tolerance value (set by the user, used to expand the search range, T w The larger the width direction, the greater the tolerable pattern deviation), T h is the height tolerance value (set by the user, used to expand the search range, T h The larger the height direction, the greater the tolerable pattern deviation). w , T hExpanding the local search area and floatingly registering the local pattern within the local search area can effectively overcome the influence of pattern position offset and pattern rotation.
[0138] According to an embodiment of the present invention, extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size using a preset average template, specifically includes:
[0139] Extracting the local pattern from the image to be detected based on a preset extraction range;
[0140] The average template is rotated to the local pattern position with the center position of the image as the rotation center, and the image of the average template is adjusted to the size of the local pattern, wherein the pixel value of the background area is filled with the calculated average gray value.
[0141] It should be noted that, in this embodiment, the actual center position and angle of the local pattern are obtained, and the local pattern in the detection image is cut out (when cutting out, the cut-out range is appropriately enlarged because the defect may be connected to the character outside the character), the average template is rotated to the local pattern orientation with the image center position as the rotation center, and the average template image is adjusted to the local image size (the average pixel value of the background area is filled in all directions outward).
[0142] According to an embodiment of the present invention, the defect segmentation of the resized local pattern using a preset brightness threshold specifically includes:
[0143] Obtain the light and dark thresholds preset by the user to obtain the light threshold and the dark threshold;
[0144] Performing full black mapping on the resized local pattern to obtain a bright defect map and a dark defect map;
[0145] Extracting a pixel value of the image of the average template as a first pixel value, and extracting a pixel value of the local pattern as a second pixel value;
[0146] The relationship between the difference between the first pixel value and the second pixel value and the bright threshold and the dark threshold is compared, so as to adjust the pixels of the bright defect map and the dark defect map.
[0147] It should be noted that in this embodiment, the defect bright threshold T1 and dark threshold T2 are manually set, and the positions that may be defects are segmented by comparing the adjusted average template image with the local pattern in the detection image. The segmentation method is: create two completely black images, which are recorded as bright defect images and dark defect images respectively.
[0148] Compare the pixel values at each pixel position of the adjusted average template image and the local pattern. Assume that the first pixel value at a certain position on the average template is V1, and the second pixel value at the corresponding position on the local pattern is V2. If V2 - V1 > T1, set the pixel value at the corresponding position in the bright defect map to "255" (white pixel); if V2 - V1 < T2, set the pixel value at the corresponding position in the dark defect map to "255" (white pixel), where T1 is the bright defect threshold and T2 is the bright defect threshold.
[0149] According to an embodiment of the present invention, the method for defect correction of the image obtained by defect segmentation using a preset thick / thin stroke template specifically includes:
[0150] Perform a pixel value setting operation to zero the pixel values in the area where the pixel values of the thick stroke image in the defect-segmented image are zero to mask the thick stroke defects;
[0151] Perform a pixel value setting operation to zero the pixel values in the area where the pixel values of the thin stroke image in the defect-segmented image are full value to mask the thin stroke defects.
[0152] It should be noted that in this embodiment, defects other than thick strokes are masked (the area corresponding to the thick stroke image in the defect image with a pixel value of "0" is set to a "0" pixel value), and defects within thin strokes are masked (the area corresponding to the thin stroke image in the defect image with a pixel value of "255" is set to a "0" pixel value). Fig.11A Shows a schematic diagram of image correction in an embodiment of a method for detecting printing pattern defects according to the present invention; Fig. 11B Shows another schematic diagram of image correction in an embodiment of a method for detecting printing pattern defects according to the present invention; Fig. 11C Shows another schematic diagram of image correction in an embodiment of a method for detecting printing pattern defects according to the present invention; Fig.11D Shows another schematic diagram of image correction in an embodiment of a method for detecting printing pattern defects according to the present invention. As Fig.11A shown, taking the bright defect image as an example, where Fig. 11B is shown as a schematic diagram of the thin stroke template, Fig. 11C is shown as a schematic diagram of the thick stroke template, Fig.11D is shown as the bright defect image after defect correction.
[0153] According to an embodiment of the present invention, the based-on preset defect conditions specifically include: the area of the connected domain is greater than the preset minimum defect area, and the shortest side of the connected domain is greater than the preset minimum defect width.
[0154] It should be noted that in this embodiment, the connected domain search and discrimination is performed on the bright defect image and the dark defect image after noise shielding, and the defects must meet the following requirements: the area of the connected domain must be greater than the set minimum defect area; the shortest side of the connected domain must be greater than the set minimum defect width. When comparing the average template image and the local pattern, noise interference will be introduced, such as background defects or other regional patterns. Therefore, pattern defect detection only needs to detect defects on the current pattern or connected to the current pattern, and use the pattern mask set to perform non-defect shielding on the defect image. The dark defect shielding mask is obtained by adding the pattern mask image to the dark threshold segmentation map to obtain the largest connected domain. The bright defect shielding mask is obtained as follows: the pattern mask image is added to the bright threshold segmentation map to obtain the maximum connected domain, where the defect will be connected to the mask to form a new positioning area after addition, while the non-defect will not be connected to the mask because it is far away from the character; and the pattern mask size and the bright and dark segmentation map have the same size, and the new image formed after addition also has the same size. The addition rule is to add the pixel values of the corresponding pixel positions. If the addition is "0", the pixel value of the new image at this position is "0". If the addition is not "0", the pixel value of the new image at this position is "255".
[0155] Fig.12 A block diagram of a printing pattern defect detection system of the present invention is shown.
[0156] like Fig.12 As shown, the present invention discloses a printing pattern defect detection system, including a memory and a processor, wherein the memory includes a printing pattern defect detection method program, and when the printing pattern defect detection method program is executed by the processor, the following steps are implemented:
[0157] Read the image to be detected and obtain the target detection area;
[0158] Registering the image to be detected to obtain target data in the image to be detected, wherein the target data includes an actual center position and angle of a local pattern in a target detection area;
[0159] Extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size using a preset average template;
[0160] Defect segmentation is performed on the resized local pattern using a preset brightness and darkness threshold;
[0161] Using a preset thick / thin stroke template, the defect-corrected image is corrected to obtain a corrected image;
[0162] Defect information of the corrected image is calculated based on a preset defect condition to complete defect detection.
[0163] It should be noted that since the specific implementation method of this embodiment corresponds to the aforementioned method embodiment, the same details will not be repeated here. Those skilled in the art should also understand that when the printed pattern defect detection method program is executed by the processor, the steps consistent with the aforementioned method embodiment are implemented.
[0164] A third aspect of the present invention provides a computer-readable storage medium, which includes a printed pattern defect detection method program. When the printed pattern defect detection method program is executed by a processor, the steps of a printed pattern defect detection method as described in any one of the above items are implemented.
[0165] The present invention discloses a printing pattern defect detection method, system and readable storage medium, which can effectively detect printing pattern defects and adapt to changes in the thickness of printed pattern strokes and positional relationship deviations. Specifically, for positional relationship deviations, the overall template is broken up and only local useful templates are retained for flexible combination, thereby improving the algorithm's adaptability to positional deviations and detection accuracy; for changes in the thickness of pattern strokes, the thickness characteristics of the strokes are learned and defects are corrected through the thickness characteristics in the defect detection link, which can effectively avoid over-inspection caused by the thickness of the strokes; for non-defect interference items, a pattern mask is obtained, and a light and dark defect shielding mask is created in the defect detection link to shield detection interference caused by non-defects, thereby effectively avoiding over-inspection caused by non-defective parts.
[0166] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0167] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0168] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0169] A person of ordinary skill in the art can understand that: all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: a mobile storage device, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0170] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
Claims
1. A method for detecting defects in printed patterns, characterized in that: The following steps are involved: Read the image to be detected and obtain the target detection area; Registering the image to be detected to obtain target data in the image to be detected, wherein the target data includes the actual center position and angle of the local pattern in the target detection area; specifically including: Registering the image to be detected based on a user-set reference to obtain a reference center position in the image to be detected and an angle relative to a reference template image; Based on the reference center position and the angle relative to the reference template image combined with the pattern template, the area where each image to be detected is located is converted to obtain a local area; Performing pattern registration using an average template in a local area to obtain the target data, wherein specifically obtaining the actual center position and angle of the local pattern; Extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size of the local pattern using a preset average template; Defect segmentation is performed on the resized local pattern using the preset brightness and darkness threshold; specifically including: Obtain the light and dark thresholds preset by the user to obtain the light threshold and the dark threshold; Performing full black mapping on the resized local pattern to obtain a bright defect map and a dark defect map; Extracting a pixel value of the image of the average template as a first pixel value, and extracting a pixel value of the local pattern as a second pixel value; Comparing the relationship between the difference between the first pixel value and the second pixel value and the bright threshold and the dark threshold, thereby adjusting the pixels of the bright defect image and the dark defect image; Using the preset thick / thin stroke template, the defect-segmented image is corrected to obtain a corrected image; specifically, the process includes: The pixel value of the region where the pixel value of the thick stroke image is zero in the defect segmented image is set to zero to shield the thick stroke defect; The pixel value of the area with full pixel value in the fine stroke image in the defect segmented image is set to zero to mask the fine stroke defect; Using a pattern mask set to perform non-defect masking on the defect image, and calculating defect information of the corrected image based on a preset defect condition to complete defect detection; The method further comprises registering template data, wherein the template data comprises a position of a pattern template, a pattern, a binary mask, an average template, and a thick / thin stroke template; The registering of the template data specifically includes: Acquire an original image and a user-set benchmark, wherein the user-set benchmark includes a benchmark template image and a center coordinate of a benchmark template image frame; Performing image processing on the original image to obtain a minimum bounding box of each pattern template, wherein the processing process includes binarization processing, average gray value calculation, denoising processing, closing operation processing and connected domain retrieval; The template data is calculated based on the minimum bounding box, wherein: The position of the pattern template is obtained by converting the minimum bounding box in combination with the center coordinates of the reference template image frame; Based on the minimum bounding box, a pattern of the pattern template is obtained by intercepting it from the original image; Obtaining a binary mask of a pattern template from the image in the closing operation process based on the minimum bounding box; Obtaining the average template based on the pattern of the pattern template; A thick / thin stroke template of the pattern template is obtained by cutting out the binary image after denoising based on the minimum bounding box.
2. A printing pattern defect detection method according to claim 1, characterized in that: The extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size using a preset average template, specifically includes: Extracting the local pattern from the image to be detected based on a preset extraction range; The average template is rotated to the local pattern position with the center position of the image as the rotation center, and the image of the average template is adjusted to the size of the local pattern, wherein the pixel value of the background area is filled with the calculated average gray value.
3. A printing pattern defect detection method according to claim 1, characterized in that: The preset defect conditions specifically include: the area of the connected domain is larger than the preset minimum defect area, and the shortest side of the connected domain is larger than the preset minimum defect width.
4. A printing pattern defect detection system, characterized in that: The method comprises a memory and a processor, wherein the memory comprises a printing pattern defect detection method program, and when the printing pattern defect detection method program is executed by the processor, the following steps are implemented: Read the image to be detected and obtain the target detection area; Registering the image to be detected to obtain target data in the image to be detected, wherein the target data includes the actual center position and angle of the local pattern in the target detection area; specifically including: Registering the image to be detected based on a user-set reference to obtain a reference center position in the image to be detected and an angle relative to a reference template image; Based on the reference center position and the angle relative to the reference template image combined with the pattern template, the area where each image to be detected is located is converted to obtain a local area; Performing pattern registration using an average template in a local area to obtain the target data, wherein specifically obtaining the actual center position and angle of the local pattern; Extracting the local pattern from the image to be detected based on the actual center position and angle, and adjusting the image size of the local pattern using a preset average template; Defect segmentation is performed on the resized local pattern using the preset brightness and darkness threshold; specifically including: Obtain the light and dark thresholds preset by the user to obtain the light threshold and the dark threshold; Performing full black mapping on the resized local pattern to obtain a bright defect map and a dark defect map; Extracting a pixel value of the image of the average template as a first pixel value, and extracting a pixel value of the local pattern as a second pixel value; Comparing the relationship between the difference between the first pixel value and the second pixel value and the bright threshold and the dark threshold, thereby adjusting the pixels of the bright defect image and the dark defect image; Using the preset thick / thin stroke template, the defect-segmented image is corrected to obtain a corrected image; specifically, the process includes: The pixel value of the region where the pixel value of the thick stroke image is zero in the defect segmented image is set to zero to shield the thick stroke defect; The pixel value of the area with full pixel value in the fine stroke image in the defect segmented image is set to zero to mask the fine stroke defect; Using a pattern mask set to perform non-defect masking on the defect image, and calculating defect information of the corrected image based on a preset defect condition to complete defect detection; the method also includes registering template data, wherein the template data includes a position of a pattern template, a pattern, a binary mask, an average template, and a thick / thin stroke template; The registering of the template data specifically includes: Acquire an original image and a user-set benchmark, wherein the user-set benchmark includes a benchmark template image and a center coordinate of a benchmark template image frame; Performing image processing on the original image to obtain a minimum bounding box of each pattern template, wherein the processing process includes binarization processing, average gray value calculation, denoising processing, closing operation processing and connected domain retrieval; The template data is calculated based on the minimum bounding box, wherein: The position of the pattern template is obtained by converting the minimum bounding box in combination with the center coordinates of the reference template image frame; Based on the minimum bounding box, a pattern of the pattern template is obtained by intercepting it from the original image; Obtaining a binary mask of a pattern template from the image in the closing operation process based on the minimum bounding box; Obtaining the average template based on the pattern of the pattern template; A thick / thin stroke template of the pattern template is obtained by cutting out the binary image after denoising based on the minimum bounding box.
5. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a printing pattern defect detection method program, and when the printing pattern defect detection method program is executed by a processor, the steps of a printing pattern defect detection method as described in any one of claims 1 to 3 are implemented.
