Barcode defect detection method, device, equipment, storage medium and program product
Through denoising and outer contour extraction, combined with morphological operations and affine transformation, the barcode defect detection process is simplified, the problem of difficult positioning of barcode areas is solved, and the detection efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202411035499.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2044-07-31
AI Technical Summary
In the prior art, the barcode area positioning is difficult, resulting in low barcode defect detection efficiency and requires a large amount of data to train deep learning models.
By acquiring images, the barcode area is initially determined, denoising and outer contour extraction are performed, and morphological operations and affine transformation correction are used to simplify the barcode defect detection process and reduce dependence on data training.
It realizes simpler and more accurate barcode area positioning, improves the efficiency and accuracy of barcode defect detection, and reduces the need for data training.
Smart Images

Figure CN118570196B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a barcode defect detection method, device, equipment, storage medium and program product. Background Art
[0002] Industrial products usually use barcodes to record product-related information, which is convenient for tracing back to product production-related information. During the transportation process, industrial products may be damaged by bumps, scratches, etc., which may affect the normal recognition of the barcode. Therefore, the integrity of the barcode is often tested before the product is shipped out.
[0003] Currently, deep learning models are usually used to locate the barcode area for subsequent defect detection. However, using deep learning models to locate the barcode area often requires collecting a large amount of data for model training in the early stage, which is time-consuming and labor-intensive, making it difficult to locate the barcode area. Summary of the invention
[0004] The embodiments of the present application provide a barcode defect detection method, apparatus, device, storage medium and program product to solve the technical problem of difficulty in locating the barcode area during the barcode defect detection process.
[0005] In a first aspect, an embodiment of the present application provides a barcode defect detection method, comprising:
[0006] When the first image is acquired, determining a first barcode region in the first image;
[0007] Performing denoising on the first barcode region to obtain a denoised first barcode region;
[0008] Extracting the outer contour of the barcode in the first image according to the first barcode region after denoising to obtain a second barcode region;
[0009] Correcting the second barcode region by using a preset width and a preset height to obtain a second image corresponding to the barcode in the first image;
[0010] Barcode defect detection is performed based on the second image.
[0011] In this embodiment, the first barcode area in the first image can be preliminarily determined, and then denoising can be performed. Based on the first barcode area after denoising, the outer contour of the barcode in the first image can be extracted to obtain a more accurate second barcode area, so that barcode defect detection can be performed after correction based on the second barcode area with higher accuracy. There is no need to collect a large amount of data to train the model to locate the barcode area, and the barcode area can be located more easily and accurately.
[0012] In some embodiments, performing denoising on the first barcode region to obtain the denoised first barcode region includes:
[0013] The first barcode region is subjected to denoising by a target operation to obtain the denoised first barcode region, wherein the target operation includes at least one of a morphological closing operation and a morphological opening operation.
[0014] In this embodiment, the first barcode region may be denoised by using a morphological closing operation and / or a morphological opening operation, so that an outer contour may be extracted based on the clearer first barcode region to obtain a more accurate second barcode region.
[0015] In some embodiments, when the target operation includes a morphological closing operation and a morphological opening operation, performing denoising on the first barcode region through the target operation to obtain the denoised first barcode region includes:
[0016] Performing binarization processing on the first barcode region to obtain an initial binarization image corresponding to the first barcode region;
[0017] The initial binary image is subjected to denoising by a morphological closing operation to obtain a first binary image;
[0018] The first binarized image is denoised by a morphological opening operation to obtain a second binarized image. The first barcode region after the denoising operation is the second binarized image.
[0019] In this way, the first barcode region after binarization can be denoised through morphological closing and opening operations to obtain a clearer second binarization image, which lays the foundation for the subsequent extraction of an accurate second barcode region.
[0020] In some embodiments, extracting the outer contour of the barcode in the first image according to the first barcode region after denoising to obtain the second barcode region includes:
[0021] Performing a debinarization process on the second binarized image to obtain a debinarized image;
[0022] Extract four corner points of the white edge in the debinarized image to obtain the outer contour of the barcode in the first image;
[0023] The area corresponding to the outer contour is determined as the second barcode area.
[0024] In this way, the outer contour of the barcode can be extracted based on the debinarization process, so that a more accurate second barcode area can be located, laying a foundation for subsequently improving the accuracy of barcode defect detection.
[0025] In some embodiments, the barcode includes a plurality of bars, and performing barcode defect detection based on the second image includes:
[0026] extracting a sub-contour of each bar in the second image;
[0027] Determine whether a first sub-contour exists according to each bar-shaped sub-contour and a preset height threshold, wherein the height of the first sub-contour is less than the height threshold;
[0028] In the presence of the first sub-profile, it is determined that the barcode is defective.
[0029] In this way, the sub-contour of each bar of the barcode can be extracted, and the barcode can be detected whether there are defects by comparing the height of the sub-contour with a preset height threshold. This detection method is simpler and more convenient, and improves the efficiency of barcode defect detection.
[0030] In some embodiments, extracting a sub-contour of each bar in the second image includes:
[0031] Binarizing the second image to obtain a third image;
[0032] Debinarize the third image to obtain a fourth image;
[0033] Extracting the boundary of each white strip area in the fourth image;
[0034] The boundary of each white bar area is drawn into the preset canvas to obtain the sub-contour of each bar in the second image.
[0035] In this way, the second image is binarized and debinarized to assist in extracting the sub-contour of each bar of the barcode, thereby more accurately extracting the sub-contour of each bar in the second image, laying the foundation for subsequently improving the accuracy of barcode defect detection.
[0036] In some embodiments, when the first sub-contour exists, after determining whether the first sub-contour exists according to each bar-shaped sub-contour and a preset height threshold, the method further includes:
[0037] Performing clustering processing on the first sub-contour according to the coordinate value of the first direction to obtain at least one contour cluster, wherein the first direction is a direction perpendicular to the strip;
[0038] Through morphological black hat operation, the defect area of each contour cluster is extracted;
[0039] According to the defect area, the defects of the barcode are analyzed and located.
[0040] In this way, when there are defects in the barcode, the first sub-contour with defects can be clustered first, and then the defect area can be extracted according to the contour clustering, and then the defect can be located and analyzed, thereby improving the efficiency and accuracy of barcode defect detection.
[0041] In some embodiments, the second barcode region is corrected by a preset width and a preset height to obtain a second image corresponding to the barcode in the first image, including:
[0042] Determine a transformation matrix according to the preset width and the preset height, and the coordinates of at least three corner points of the second barcode area;
[0043] Performing an affine transformation on the second barcode region according to the transformation matrix to obtain a corrected second barcode region;
[0044] The corrected image of the second barcode region is determined as the second image.
[0045] In this way, the second barcode area can be corrected according to the width and height of the defect-free barcode and the coordinates of at least three corner points of the second barcode area to obtain a more accurate second image including the barcode content, so that when barcode defect detection is subsequently performed based on the second image, the accuracy of the detection result can be improved.
[0046] In some embodiments, when a first image is acquired, determining a first barcode region in the first image includes:
[0047] When the first image is acquired, the first image is matched with the template to determine a first barcode region in the first image, wherein the template is used to represent image content corresponding to the barcode.
[0048] In this way, the first barcode area can be preliminarily matched from the first image according to the template of the image content corresponding to the barcode, laying the foundation for the subsequent accurate positioning of the second barcode area.
[0049] In some embodiments, when a first image is acquired, matching the first image with a template to determine a first barcode region in the first image includes:
[0050] When the first image is acquired, denoising is performed on the first image to obtain a third image;
[0051] The third image is matched with the template to determine the first barcode area in the third image.
[0052] In this way, before the first barcode region is preliminarily matched through the template, the acquired first image may be subjected to denoising processing, so as to improve the accuracy of positioning the barcode region, and further improve the accuracy of barcode defect detection.
[0053] In a second aspect, an embodiment of the present application further provides a barcode defect detection device, comprising:
[0054] A first determination module is used to match the first image with a template to determine a first barcode region in the first image when the first image is acquired, wherein the template is used to characterize image content corresponding to a defect-free barcode;
[0055] A processing module, used for performing denoising processing on the first barcode region to obtain the first barcode region after denoising processing;
[0056] An extraction module, used to extract the outer contour of the barcode in the first image according to the first barcode area after denoising to obtain a second barcode area;
[0057] A correction module, used to perform correction processing on the second barcode area by using a preset width and a preset height to obtain a second image corresponding to the barcode in the first image;
[0058] The detection module is used to perform barcode defect detection based on the second image.
[0059] In this embodiment, the first barcode area in the first image can be preliminarily determined, and then denoising can be performed. Based on the first barcode area after denoising, the outer contour of the barcode in the first image can be extracted to obtain a more accurate second barcode area, so that barcode defect detection can be performed after correction based on the second barcode area with higher accuracy. There is no need to collect a large amount of data to train the model to locate the barcode area, and the barcode area can be located more easily and accurately.
[0060] In some embodiments, the processing module may also be used to:
[0061] The first barcode region is subjected to denoising by a target operation to obtain the denoised first barcode region, wherein the target operation includes at least one of a morphological closing operation and a morphological opening operation.
[0062] In this embodiment, the first barcode region may be denoised by using a morphological closing operation and / or a morphological opening operation, so that an outer contour may be extracted based on the clearer first barcode region to obtain a more accurate second barcode region.
[0063] In some embodiments, when the target operation includes a morphological closing operation and a morphological opening operation, the processing module may further be configured to:
[0064] Performing binarization processing on the first barcode region to obtain an initial binarization image corresponding to the first barcode region;
[0065] The initial binary image is subjected to denoising by a morphological closing operation to obtain a first binary image;
[0066] The first binarized image is denoised by a morphological opening operation to obtain a second binarized image. The first barcode region after the denoising operation is the second binarized image.
[0067] In this way, the first barcode region after binarization can be denoised through morphological closing and opening operations to obtain a clearer second binarization image, which lays the foundation for the subsequent extraction of an accurate second barcode region.
[0068] In some embodiments, the extraction module may also be used to:
[0069] Performing a debinarization process on the second binarized image to obtain a debinarized image;
[0070] Extract four corner points of the white edge in the debinarized image to obtain the outer contour of the barcode in the first image;
[0071] The area corresponding to the outer contour is determined as the second barcode area.
[0072] In this way, the first barcode area can be denoised through morphological closing and opening operations, and then the outer contour of the barcode can be extracted based on the debinarization process, so that the second barcode area can be located more accurately, laying the foundation for subsequently improving the accuracy of barcode defect detection.
[0073] In some embodiments, the barcode includes a plurality of bars, and the detection module further includes:
[0074] An extraction unit, used for extracting a sub-contour of each bar in the second image by using a contour discovery algorithm;
[0075] A first determining unit, configured to determine whether a first sub-contour exists according to each bar-shaped sub-contour and a preset height threshold, wherein a height of the first sub-contour is less than the height threshold;
[0076] The second determining unit is used to determine whether the barcode has defects when the first sub-profile exists.
[0077] In this way, the sub-contour of each bar of the barcode can be extracted, and the barcode can be detected whether there are defects by comparing the height of the sub-contour with a preset height threshold. This detection method is simpler and more convenient, and improves the efficiency of barcode defect detection.
[0078] In some embodiments, the extraction unit is further configured to:
[0079] Binarizing the second image to obtain a third image;
[0080] Debinarize the third image to obtain a fourth image;
[0081] Extracting the boundary of each white strip area in the fourth image;
[0082] The boundary of each white bar area is drawn into the preset canvas to obtain the sub-contour of each bar in the second image.
[0083] In this way, the second image is binarized and debinarized to assist in extracting the sub-contour of each bar of the barcode, thereby more accurately extracting the sub-contour of each bar in the second image, laying the foundation for subsequently improving the accuracy of barcode defect detection.
[0084] In some embodiments, when the first sub-contour exists, the detection module is further configured to:
[0085] Performing clustering processing on the first sub-contour according to the coordinate value of the first direction to obtain at least one contour cluster, wherein the first direction is a direction perpendicular to the strip;
[0086] Through morphological black hat operation, the defect area of each contour cluster is extracted;
[0087] According to the defect area, the defects of the barcode are analyzed and located.
[0088] In this way, when there are defects in the barcode, the first sub-contour with defects can be clustered first, and then the defect area can be extracted according to the contour clustering, and then the defect can be located and analyzed, thereby improving the efficiency and accuracy of barcode defect detection.
[0089] In some embodiments, the correction module is further configured to:
[0090] Determine a transformation matrix according to the preset width and the preset height, and the coordinates of at least three corner points of the second barcode area;
[0091] Performing an affine transformation on the second barcode region according to the transformation matrix to obtain a corrected second barcode region;
[0092] The corrected image of the second barcode region is determined as the second image.
[0093] In this way, the second barcode area can be corrected according to the width and height of the defect-free barcode and the coordinates of at least three corner points of the second barcode area to obtain a more accurate second image including the barcode content, so that when barcode defect detection is subsequently performed based on the second image, the accuracy of the detection result can be improved.
[0094] In some embodiments, the first determining module is further configured to:
[0095] When the first image is acquired, the first image is matched with the template to determine a first barcode region in the first image, wherein the template is used to represent image content corresponding to the barcode.
[0096] In this way, the first barcode area can be preliminarily matched from the first image according to the template of the image content corresponding to the barcode, laying the foundation for the subsequent accurate positioning of the second barcode area.
[0097] In some embodiments, the first determining module is further configured to:
[0098] When the first image is acquired, denoising is performed on the first image to obtain a third image;
[0099] The third image is matched with the template to determine the first barcode area in the third image.
[0100] In this way, before the first barcode region is preliminarily matched through the template, the acquired first image may be subjected to denoising processing, so as to improve the accuracy of positioning the barcode region, and further improve the accuracy of barcode defect detection.
[0101] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory storing program instructions; when the processor executes the program instructions, the method of the first aspect is implemented.
[0102] In a fourth aspect, an embodiment of the present application provides a machine-readable storage medium having program instructions stored thereon, and the method of the first aspect is implemented when the program instructions are executed by a processor.
[0103] In a fifth aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the method of the first aspect.
[0104] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0105] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the drawings without paying creative work.
[0106] Figure 1 A schematic diagram of a process for detecting barcode defects according to an embodiment of the present application;
[0107] Figure 2 A schematic diagram of a first image in a barcode defect detection method provided in an embodiment of the present application;
[0108] Figure 3 A schematic diagram of a first barcode region in a barcode defect detection method provided in an embodiment of the present application;
[0109] Figure 4 A schematic diagram of a binary image after denoising in the barcode defect detection method provided in an embodiment of the present application;
[0110] Figure 5 A schematic diagram of a debinarization image in a barcode defect detection method provided in an embodiment of the present application;
[0111] Figure 6 A schematic diagram of a second barcode region in a barcode defect detection method provided in an embodiment of the present application;
[0112] Figure 7 A schematic diagram of a second image in a barcode defect detection method provided in an embodiment of the present application;
[0113] Figure 8 A schematic diagram of a sub-contour of each bar in the barcode defect detection method provided in an embodiment of the present application;
[0114] Fig. 9 for Figure 8 A schematic diagram of the N first sub-contours in ;
[0115] Fig.10a for Fig. 9 One of the schematic diagrams of the middle contour clustering;
[0116] Fig.10b for Fig. 9 Schematic diagram of middle contour clustering (part 2);
[0117] Fig.10c for Fig. 9 Schematic diagram of middle contour clustering (part 3);
[0118] Fig.11a for Fig.10a Schematic diagram of the defect area in the middle;
[0119] Fig.11b for Fig.10b Schematic diagram of the defect area in the middle;
[0120] Fig.11c for Fig.10c Schematic diagram of the defect area in the middle;
[0121] Fig.12 A schematic diagram of the structure of a barcode defect detection device provided in an embodiment of the present application;
[0122] Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0123] In the drawings, the drawings are not drawn to scale. DETAILED DESCRIPTION
[0124] The following detailed description and drawings of the embodiments of the present application are used to illustrate the principles of the present application, but cannot be used to limit the scope of the present application, that is, the present application is not limited to the described embodiments.
[0125] In the description of the present application, it should be noted that, unless otherwise specified, "multiple" means more than two; the terms "upper", "lower", "left", "right", "inside", "outside", etc., indicating the orientation or positional relationship, are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application. In addition, the terms "first", "second", "third", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. "Vertical" is not strictly vertical, but is within the allowable error range. "Parallel" is not strictly parallel, but is within the allowable error range.
[0126] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0127] The embodiments of the present application provide a barcode defect detection method, device, equipment, storage medium and program product to solve the above technical problems. The barcode defect detection method provided by the embodiments of the present application is first introduced below.
[0128] Please refer to Figure 1 , Figure 1 A barcode defect detection method provided in an embodiment of the present application may include:
[0129] Step 101: when a first image is acquired, determine a first barcode area in the first image.
[0130] In step 101, a first image of a surface of an industrial product including a barcode may be acquired. Figure 2 As shown, the first image may include a barcode.
[0131] The first barcode region in the first image can be determined from the first image. For example, the first barcode region can be determined from the first image by a pre-trained target detection model, or the similarity between the image content of the first image and the image content of the pre-stored barcode can be directly calculated to obtain the region in the first image with the highest similarity to the image content of the barcode, and the region is determined as the first barcode region. The specific method is not specifically limited here.
[0132] Step 102: denoising the first barcode region to obtain a denoised first barcode region.
[0133] In step 102, the first barcode region may be subjected to denoising processing, thereby eliminating fine burrs at the barcode boundary in the first barcode region, or some non-defects such as cracks generated by the barcode image during image processing, thereby obtaining a clearer and more accurate denoised first barcode region.
[0134] Step 103: extract the outer contour of the barcode in the first image according to the first barcode region after the denoising process to obtain the second barcode region.
[0135] In step 103, the outer contour of the barcode in the first image can be extracted from the first barcode region after the denoising process, so that the region corresponding to the outer contour can be determined as a more accurate second barcode region.
[0136] Step 104: Correct the second barcode region by using a preset width and a preset height to obtain a second image corresponding to the barcode in the first image.
[0137] In step 104, when the first image of the barcode is acquired, the barcode region in the first image may be deformed due to problems such as the shooting angle, so that the second barcode region may not be a regular rectangular region.
[0138] Based on this, the theoretical coordinate values of the four corners of the rectangular area corresponding to the barcode without deformation can be determined by the preset width and the preset height. The actual coordinate values of the four corners of the second barcode area can be obtained, and the affine transformation can be performed according to the actual coordinate values and the theoretical coordinate values to correct the second barcode area to obtain a rectangular barcode area. The image of the rectangular barcode area can be determined as the second image corresponding to the barcode in the first image.
[0139] Step 105: Perform barcode defect detection based on the second image.
[0140] In step 105, the barcode defect detection can be performed according to the image content of the second image. For example, the barcode defect in the second image can be detected by horizontally projecting and calculating the grayscale mean. It is also possible to extract the sub-contour of each bar in the barcode, and detect the barcode defect in the second image by determining whether there is a missing part in each column of sub-contours. It is also possible to extract the sub-contour of each bar in the barcode, and detect the barcode defect in the second image according to the height of each sub-contour.
[0141] In this embodiment, the first barcode area in the first image can be preliminarily determined, and then denoising can be performed. Based on the first barcode area after denoising, the outer contour of the barcode in the first image can be extracted to obtain a more accurate second barcode area, so that barcode defect detection can be performed after correction based on the second barcode area with higher accuracy. There is no need to collect a large amount of data to train the model to locate the barcode area, and the barcode area can be located more easily and accurately.
[0142] In some embodiments, performing denoising on the first barcode region to obtain the denoised first barcode region includes:
[0143] The first barcode region is subjected to denoising by a target operation to obtain the denoised first barcode region, wherein the target operation includes at least one of a morphological closing operation and a morphological opening operation.
[0144] In this embodiment, the first barcode region can be de-noised by at least one of a morphological closing operation and a morphological opening operation. The morphological closing operation is to first dilate the first barcode region and then erode it. The morphological closing operation can fill the small holes in the first barcode region and eliminate the small burrs on the barcode boundary. The morphological opening operation is to first erode the first barcode region and then dilate it. The morphological opening operation can remove isolated small dots in the first barcode region to eliminate the noise generated during the image processing process.
[0145] In this embodiment, the first barcode region may be denoised by using a morphological closing operation and / or a morphological opening operation, so that an outer contour may be extracted based on the clearer first barcode region to obtain a more accurate second barcode region.
[0146] In some embodiments, when the target operation includes a morphological closing operation and a morphological opening operation, performing denoising on the first barcode region through the target operation to obtain the denoised first barcode region may include:
[0147] Performing binarization processing on the first barcode region to obtain an initial binarization image corresponding to the first barcode region;
[0148] The initial binary image is subjected to denoising by a morphological closing operation to obtain a first binary image;
[0149] The first binarized image is denoised by a morphological opening operation to obtain a second binarized image. The first barcode region after the denoising operation is the second binarized image.
[0150] In this embodiment, the first barcode region may be binarized to obtain an initial binarized image corresponding to the first barcode region. The binarization expression is shown in formula (1):
[0151] .
[0152] Where P(x,y) is the pixel value and T is the pixel threshold. If the pixel value is greater than the pixel threshold, the pixel value is changed to 255; if the pixel value is less than or equal to the pixel threshold, the pixel value is changed to 0.
[0153] like Figure 4 As shown, the initial binarized image can be subjected to a morphological closing operation to obtain a first binarized image, and the first binarized image can be subjected to a morphological opening operation to perform denoising processing to obtain a second binarized image (i.e., the first barcode region after denoising processing).
[0154] As mentioned above, the morphological closing operation is to first perform an expansion operation and then an erosion operation, while the morphological opening operation is to first perform an erosion operation and then a expansion operation.
[0155] The dilation operation is to slide a small template of the structure element on the binary image, and compare the structure element with the pixels at the corresponding position in the binary image at each position. If all pixels under the structure element match the pixels in the binary image, the pixel value at that position remains unchanged. If any pixel under the structure element does not match the pixel in the binary image, the corresponding position in the binary image is set to 1.
[0156] The erosion operation is to slide a small template of the structural element on the binary image, compare the structural element with the pixels at the corresponding position in the binary image at each position, and keep the pixel value unchanged if all the pixels of the structural element match the pixels at the corresponding position in the binary image. If any pixel of the structural element does not match the pixel in the binary image, the pixel value at that position is set to 0. It can be understood that the target element value is 1 and the non-target element value is 0.
[0157] The morphological opening operation can connect the small broken parts of the black stripes and eliminate the noise in the binarization process. The morphological closing operation can eliminate the small burrs on the boundaries of the black stripes and make the stripe boundaries smoother.
[0158] In this way, the first barcode region after binarization can be denoised through morphological closing and opening operations to obtain a clearer second binarization image, which lays the foundation for the subsequent extraction of an accurate second barcode region.
[0159] In some embodiments, extracting the outer contour of the barcode in the first image according to the first barcode region after denoising to obtain the second barcode region may include:
[0160] Performing a debinarization process on the second binarized image to obtain a debinarized image;
[0161] Extract four corner points of the white edge in the debinarized image to obtain the outer contour of the barcode in the first image;
[0162] The area corresponding to the outer contour is determined as the second barcode area.
[0163] In this embodiment, if Figure 5 As shown, the second binarized image may be subjected to a debinarization process to flip the black and white areas in the denoised binarized image to obtain a debinarized image.
[0164] The expression of debinarization is shown in formula (2):
[0165] .
[0166] Where P(x,y) is the pixel value and T is the pixel threshold. If the pixel value is greater than the pixel threshold, the pixel value is changed to 0; if the pixel value is less than or equal to the pixel threshold, the pixel value is changed to 255.
[0167] It is understandable that when extracting contours, extracting white edges is clearer and more convenient than extracting black edges, which can improve the accuracy of contour extraction to a certain extent. Figure 6As shown, the four corner points of the white edge in the debinarized image can be extracted, and the outer contour of the barcode can be obtained by connecting the four corner points. The area corresponding to the outer contour can be determined as the second barcode area.
[0168] In this way, the first barcode area can be denoised through morphological closing and opening operations, and then the outer contour of the barcode can be extracted based on the debinarization process, so that the second barcode area can be located more accurately, laying the foundation for subsequently improving the accuracy of barcode defect detection.
[0169] In some embodiments, performing correction processing on the second barcode region by using a preset width and a preset height to obtain a second image corresponding to the barcode in the first image may include:
[0170] Determine a transformation matrix according to the preset width and the preset height, and the coordinates of at least three corner points of the second barcode area;
[0171] Performing an affine transformation on the second barcode region according to the transformation matrix to obtain a corrected second barcode region;
[0172] The corrected image of the second barcode region is determined as the second image.
[0173] In this embodiment, the coordinates of at least three corner points of the second barcode area can be obtained. For example, the coordinates of the upper left point of the second barcode area are (x1, y1), the coordinates of the upper right point are (x2, y2), and the coordinates of the lower right point are (x3, y3).
[0174] Assume that the width of the defect-free barcode is w and the height is h. The coordinates of the upper left point of the corrected second image are (0,0), the coordinates of the upper right point are (w,0), and the coordinates of the lower right point are (w,h).
[0175] The transformation matrix M can be calculated based on the coordinates of the upper left point of the second barcode area being (x1, y1), the coordinates of the upper right point being (x2, y2), and the coordinates of the lower right point being (x3, y3), and the coordinates of the upper left point of the second image being (0, 0), the coordinates of the upper right point being (w, 0), and the coordinates of the lower right point being (w, h). For example, the transformation matrix M can be directly calculated using the getAffineTransform function of opencv.
[0176] like Figure 7As shown, the second barcode region can be affine transformed according to the transformation matrix to obtain the corrected second barcode region, and the image of the corrected second barcode region is determined as the second image. For example, the warpAffine function of opencv can be used to perform affine transformation to obtain the corrected second barcode region. In the warpAffine function, the expression of affine transformation can be shown as formula (3):
[0177] .
[0178] Among them, M is the transformation matrix, (x, y) is the coordinate of the point before transformation, (x ’ ,y ’ ) are the coordinates of the transformed point.
[0179] In this way, the second barcode area can be corrected according to the width and height of the defect-free barcode and the coordinates of at least three corner points of the second barcode area to obtain a more accurate second image including the barcode content, so that when barcode defect detection is subsequently performed based on the second image, the accuracy of the detection result can be improved.
[0180] In some embodiments, the barcode includes a plurality of bars, and performing barcode defect detection based on the second image may include:
[0181] Extracting the sub-contour of each bar in the second image by a contour finding algorithm;
[0182] Determine whether a first sub-contour exists according to each bar-shaped sub-contour and a preset height threshold, wherein the height of the first sub-contour is less than the height threshold;
[0183] In the presence of the first sub-profile, it is determined that the barcode is defective.
[0184] In this embodiment, the barcode includes a plurality of bars. Figure 8 As shown, the sub-contour of each bar in the second image can be extracted.
[0185] The sub-contours may be filtered according to their minimum circumscribed rectangle heights to select the first sub-contours whose heights are less than a preset height threshold. The preset height threshold may be a height value of a defect-free barcode, or a height value that is smaller than the height value of a defect-free barcode and the difference satisfies an error range.
[0186] It is understandable that if the barcode has no defects, the height of each bar sub-contour in the barcode is not less than the preset height threshold. Based on this, if the number of the first sub-contour is 0, it can be considered that the barcode has no defects.
[0187] like Fig. 9As shown, if there is a first sub-contour whose height is less than a preset height threshold, it can be considered that the barcode has a defect.
[0188] In this way, the sub-contour of each bar of the barcode can be extracted, and the barcode can be detected whether there are defects by comparing the height of the sub-contour with a preset height threshold. This detection method is simpler and more convenient, and improves the efficiency of barcode defect detection.
[0189] In some embodiments, extracting the sub-contour of each bar in the second image may include:
[0190] Binarizing the second image to obtain a third image;
[0191] Debinarize the third image to obtain a fourth image;
[0192] Extracting the boundary of each white strip area in the fourth image;
[0193] The boundary of each white bar area is drawn into the preset canvas to obtain the sub-contour of each bar in the second image.
[0194] In this embodiment, the second image may be binarized to obtain a third image, and the third image may be debinarized to obtain a fourth image. The binarization and debinarization are as described above and will not be described in detail here.
[0195] When extracting the boundary, it is clearer and more convenient to extract the white boundary than to extract the black boundary, and the accuracy of boundary extraction can be improved to a certain extent. Based on this, the boundary of each white strip area in the debinarized fourth image can be extracted, and then the boundary of each white strip area can be drawn to the preset canvas, and the following is obtained: Figure 8 The sub-profiles of each bar in the second image are shown.
[0196] In this way, the second image is binarized and debinarized to assist in extracting the sub-contour of each bar of the barcode, thereby more accurately extracting the sub-contour of each bar in the second image, laying the foundation for subsequently improving the accuracy of barcode defect detection.
[0197] In some embodiments, when the first sub-contour exists, after determining whether the first sub-contour exists according to the sub-contour of each bar and a preset height threshold, the barcode defect detection method may further include:
[0198] Performing clustering processing on the first sub-contour according to the coordinate value of the first direction to obtain at least one contour cluster, wherein the first direction is a direction perpendicular to the strip;
[0199] Through morphological black hat operation, the defect area of each contour cluster is extracted;
[0200] According to the defect area, the defects of the barcode are analyzed and located.
[0201] In this embodiment, taking the extension direction of the bar as the y-axis and the first direction perpendicular to the bar as the x-axis as an example, when there is a first sub-contour, the first sub-contour can be clustered according to the coordinate value of the x-axis to obtain at least one contour cluster. That is, the first sub-contours originally belonging to the same bar can be paired. In other words, the first sub-contours included in each contour cluster belong to the same bar. For example, Figures 10a to 10c A partial outline clustering is shown.
[0202] The defect areas of M contour clusters can be extracted by morphological black hat operation. For example, the image processed by morphological closing operation can be subtracted from the original image to obtain the small hole area inside the image, that is, the defect area of each contour cluster. For example, Figures 11a to 11c They are shown respectively Figures 10a to 10c Contour clustering of defect areas.
[0203] The defects of the barcode can be analyzed and located according to the defect area corresponding to each contour cluster. For example, the findContours function of opencv can be used to find the defect contour corresponding to the defect area, which is convenient for analyzing the location of the defect, the cause of the defect, and the subsequent remediation of the defect.
[0204] In this way, when there are defects in the barcode, the first sub-contour with defects can be clustered first, and then the defect area can be extracted according to the contour clustering, and then the defect can be located and analyzed, thereby improving the efficiency and accuracy of barcode defect detection.
[0205] In some embodiments, the above step 101 may include:
[0206] When the first image is acquired, the first image is matched with the template to determine a first barcode region in the first image, wherein the template is used to represent image content corresponding to the barcode.
[0207] In this embodiment, a template may be generated based on the barcode, and the template may represent the image content corresponding to the barcode.
[0208] The first image may be matched with the template. For example, the similarity between the image content of the first image and the image content of the template may be calculated to obtain the region in the first image that has the highest similarity with the template, such as Figure 3 As shown, the area can be considered as the first barcode area corresponding to the barcode in the first image.
[0209] In this way, the first barcode area can be preliminarily matched from the first image according to the template of the image content corresponding to the barcode, laying the foundation for the subsequent accurate positioning of the second barcode area.
[0210] In some embodiments, when a first image is acquired, matching the first image with a template to determine a first barcode region in the first image includes:
[0211] When the first image is acquired, denoising is performed on the first image to obtain a third image;
[0212] The third image is matched with the template to determine the first barcode area in the third image.
[0213] In this embodiment, after obtaining the first image of the surface of the industrial product including the barcode, the first image may be subjected to denoising. For example, the noise of the first image may be removed by Gaussian blurring. The expression of Gaussian blurring is shown in formula (4):
[0214] .
[0215] Among them, u and v are the distance from the center pixel. The larger the value, the farther away from the center pixel, the smaller the Gaussian weight, and the lower the blur. In other words, Gaussian blur is actually a low-pass filter to remove high-frequency noise.
[0216] Each pixel in the first image is multiplied by its corresponding Gaussian weight to obtain a third image after Gaussian blurring. The third image can be matched with the template to determine the first barcode area from the third image.
[0217] In this way, before the first barcode region is preliminarily matched through the template, the acquired first image may be subjected to denoising processing, so as to improve the accuracy of positioning the barcode region, and further improve the accuracy of barcode defect detection.
[0218] Based on the barcode defect detection method provided in the above embodiment, the present application also provides an embodiment of a barcode defect detection device.
[0219] Fig.12 A schematic structural diagram of a barcode defect detection device provided in another embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.
[0220] Reference Fig.12 , the barcode defect detection device 1200 may include:
[0221] A first determination module 1201 is used to match the first image with a template to determine a first barcode region in the first image when the first image is acquired, wherein the template is used to represent image content corresponding to a defect-free barcode;
[0222] The processing module 1202 is used to perform denoising on the first barcode region to obtain the denoised first barcode region;
[0223] The extraction module 1203 is used to extract the outer contour of the barcode in the first image according to the first barcode area after the denoising process to obtain the second barcode area;
[0224] The correction module 1204 is used to perform correction processing on the second barcode area by using a preset width and a preset height to obtain a second image corresponding to the barcode in the first image;
[0225] The detection module 1205 is used to perform barcode defect detection based on the second image.
[0226] In this embodiment, the first barcode area in the first image can be preliminarily determined, and then denoising can be performed. Based on the first barcode area after denoising, the outer contour of the barcode in the first image can be extracted to obtain a more accurate second barcode area, so that barcode defect detection can be performed after correction based on the second barcode area with higher accuracy. There is no need to collect a large amount of data to train the model to locate the barcode area, and the barcode area can be located more easily and accurately.
[0227] In some embodiments, the processing module 1202 may also be used to:
[0228] The first barcode region is subjected to denoising by a target operation to obtain the denoised first barcode region, wherein the target operation includes at least one of a morphological closing operation and a morphological opening operation.
[0229] In this embodiment, the first barcode region may be denoised by using a morphological closing operation and / or a morphological opening operation, so that an outer contour may be extracted based on the clearer first barcode region to obtain a more accurate second barcode region.
[0230] In some embodiments, when the target operation includes a morphological closing operation and a morphological opening operation, the processing module 1202 may also be used to:
[0231] Performing binarization processing on the first barcode region to obtain an initial binarization image corresponding to the first barcode region;
[0232] The initial binary image is subjected to denoising by a morphological closing operation to obtain a first binary image;
[0233] The first binarized image is denoised by a morphological opening operation to obtain a second binarized image. The first barcode region after the denoising operation is the second binarized image.
[0234] In this way, the first barcode region after binarization can be denoised through morphological closing and opening operations to obtain a clearer second binarization image, which lays the foundation for the subsequent extraction of an accurate second barcode region.
[0235] In some embodiments, the extraction module 1203 may also be used to:
[0236] Performing a debinarization process on the second binarized image to obtain a debinarized image;
[0237] Extract four corner points of the white edge in the debinarized image to obtain the outer contour of the barcode in the first image;
[0238] The area corresponding to the outer contour is determined as the second barcode area.
[0239] In this way, the first barcode area can be denoised through morphological closing and opening operations, and then the outer contour of the barcode can be extracted based on the debinarization process, so that the second barcode area can be located more accurately, laying the foundation for subsequently improving the accuracy of barcode defect detection.
[0240] In some embodiments, the barcode includes a plurality of bars, and the detection module 1205 further includes:
[0241] An extraction unit, used for extracting a sub-contour of each bar in the second image by using a contour discovery algorithm;
[0242] A first determining unit, configured to determine whether a first sub-contour exists according to each bar-shaped sub-contour and a preset height threshold, wherein a height of the first sub-contour is less than the height threshold;
[0243] The second determining unit is used to determine whether the barcode has defects when the first sub-profile exists.
[0244] In this way, the sub-contour of each bar of the barcode can be extracted, and the barcode can be detected whether there are defects by comparing the height of the sub-contour with a preset height threshold. This detection method is simpler and more convenient, and improves the efficiency of barcode defect detection.
[0245] In some embodiments, the extraction unit is further configured to:
[0246] Binarize the second image to obtain a third image;
[0247] Debinarize the third image to obtain a fourth image;
[0248] Extracting the boundary of each white strip area in the fourth image;
[0249] The boundary of each white bar area is drawn into the preset canvas to obtain the sub-contour of each bar in the second image.
[0250] In this way, the second image is binarized and debinarized to assist in extracting the sub-contour of each bar of the barcode, thereby more accurately extracting the sub-contour of each bar in the second image, laying the foundation for subsequently improving the accuracy of barcode defect detection.
[0251] In some embodiments, when the first sub-contour exists, the detection module 1205 is further configured to:
[0252] Performing clustering processing on the first sub-contour according to the coordinate value of the first direction to obtain at least one contour cluster, wherein the first direction is a direction perpendicular to the strip;
[0253] Through morphological black hat operation, the defect area of each contour cluster is extracted;
[0254] According to the defect area, the defects of the barcode are analyzed and located.
[0255] In this way, when there are defects in the barcode, the first sub-contour with defects can be clustered first, and then the defect area can be extracted according to the contour clustering, and then the defect can be located and analyzed, thereby improving the efficiency and accuracy of barcode defect detection.
[0256] In some embodiments, the correction module 1204 is further configured to:
[0257] Determine a transformation matrix according to the preset width and the preset height, and the coordinates of at least three corner points of the second barcode area;
[0258] Performing an affine transformation on the second barcode region according to the transformation matrix to obtain a corrected second barcode region;
[0259] The corrected image of the second barcode region is determined as the second image.
[0260] In this way, the second barcode area can be corrected according to the width and height of the defect-free barcode and the coordinates of at least three corner points of the second barcode area to obtain a more accurate second image including the barcode content, so that when barcode defect detection is subsequently performed based on the second image, the accuracy of the detection result can be improved.
[0261] In some embodiments, the first determining module 1201 is further configured to:
[0262] When the first image is acquired, the first image is matched with the template to determine a first barcode region in the first image, wherein the template is used to represent image content corresponding to the barcode.
[0263] In this way, the first barcode area can be preliminarily matched from the first image according to the template of the image content corresponding to the barcode, laying the foundation for the subsequent accurate positioning of the second barcode area. In some embodiments, the first determination module 1201 is also used to:
[0264] When the first image is acquired, denoising is performed on the first image to obtain a third image;
[0265] The third image is matched with the template to determine the first barcode area in the third image.
[0266] In this way, before the first barcode region is preliminarily matched through the template, the acquired first image may be subjected to denoising processing, so as to improve the accuracy of positioning the barcode region, and further improve the accuracy of barcode defect detection.
[0267] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application, and are devices corresponding to the above-mentioned barcode defect detection method. All implementation methods in the above-mentioned method embodiment are applicable to the embodiments of the device. Its specific functions and the technical effects brought about can be found in the method embodiment part, which will not be repeated here.
[0268] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0269] Fig.13 A schematic diagram of the hardware structure of an electronic device provided in yet another embodiment of the present application is shown.
[0270] The electronic device 1300 may include a processor 1301 and a memory 1302 storing programs or instructions. When the processor 1301 executes the program, the steps in any of the above method embodiments are implemented.
[0271] Exemplarily, the program may be divided into one or more modules / units, one or more modules / units are stored in the memory 1302, and executed by the processor 1301 to complete the present application. One or more modules / units may be a series of program instruction segments capable of completing a specific function, and the instruction segments are used to describe the execution process of the program in the device.
[0272] Specifically, the processor 1301 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0273] The memory 1302 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 1302 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. Where appropriate, the memory 1302 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 1302 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 1302 is a non-volatile solid-state memory.
[0274] The memory may include read-only memory (ROM), random access memory (RAM), magnetic disk storage media devices, optical storage media devices, flash memory devices, electrical, optical or other physical / tangible memory storage devices. Thus, typically, the memory includes one or more tangible (non-transitory) readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present disclosure.
[0275] The processor 1301 implements any one of the methods in the above embodiments by reading and executing the program or instruction stored in the memory 1302 .
[0276] In one example, the electronic device may further include a communication interface 1303 and a bus 1304. The processor 1301, the memory 1302, and the communication interface 1303 are connected via the bus 1304 and communicate with each other.
[0277] The communication interface 1303 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0278] Bus 1304 includes hardware, software or both, and couples the components of online data traffic billing equipment to each other. For example, but not limitation, the bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front-side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnect (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. Where appropriate, bus 1304 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.
[0279] In addition, in combination with the method in the above embodiment, the embodiment of the present application may provide a machine-readable storage medium for implementation. The machine-readable storage medium stores a program or instruction; when the program or instruction is executed by a processor, any one of the methods in the above embodiment is implemented. The machine-readable storage medium can be read by a machine such as a computer.
[0280] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0281] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0282] An embodiment of the present application provides a computer program product, which is stored in a machine-readable storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0283] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0284] The functional modules shown in the structural block diagram described above can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application-specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier. "Machine-readable medium" may include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROMs, flash memories, erasable ROMs (EROMs), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer grid such as the Internet, an intranet, etc.
[0285] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0286] Aspects of the present disclosure are described above with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by a computer program or instruction. These programs or instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the functions / actions specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0287] Although the present application has been described with reference to preferred embodiments, various modifications may be made thereto and parts thereof may be replaced with equivalents without departing from the scope of the present application. In particular, the various technical features mentioned in the various embodiments may be combined in any manner as long as there is no structural conflict. The present application is not limited to the specific embodiments disclosed herein, but includes all technical solutions falling within the scope of the claims.
Claims
1. A barcode defect detection method, characterized in that: include: When a first image is acquired, determining a first barcode region in the first image; Performing denoising processing on the first barcode region to obtain a denoised first barcode region; Extracting the outer contour of the barcode in the first image according to the first barcode region after the denoising process to obtain a second barcode region; Correcting the second barcode region by using a preset width and a preset height to obtain a second image corresponding to the barcode; performing barcode defect detection based on the second image; The performing denoising on the first barcode region to obtain the denoised first barcode region includes: Performing denoising on the first barcode region by a target operation to obtain a denoised first barcode region, wherein the target operation includes at least one of a morphological closing operation and a morphological opening operation; The barcode includes a plurality of bars, and the barcode defect detection based on the second image includes: Extracting a sub-contour of each bar in the second image; Determining whether a first sub-contour exists according to each bar-shaped sub-contour and a preset height threshold, wherein the height of the first sub-contour is less than the height threshold; In the case where the first sub-profile exists, determining that the barcode has a defect; In the case where the first barcode region after the denoising process is a second binarized image after the binarization process, the outer contour of the barcode in the first image is extracted according to the first barcode region after the denoising process to obtain the second barcode region, including: Performing a debinarization process on the second binarized image to obtain a debinarized image; Extracting four corner points of the white edge in the debinarized image to obtain the outer contour of the barcode in the first image; The area corresponding to the outer contour is determined as the second barcode area.
2. The method according to claim 1, characterized in that In the case where the target operation includes a morphological closing operation and a morphological opening operation, the denoising process is performed on the first barcode region through the target operation to obtain the denoised first barcode region, including: Performing binarization processing on the first barcode region to obtain an initial binarization image corresponding to the first barcode region; Performing denoising on the initial binary image through a morphological closing operation to obtain a first binary image; The first binarized image is subjected to denoising processing by a morphological opening operation to obtain a second binarized image, and the first barcode region after the denoising processing is the second binarized image.
3. The method according to claim 1, characterized in that The step of extracting a sub-contour of each strip in the second image comprises: Binarizing the second image to obtain a third image; Performing a debinarization process on the third image to obtain a fourth image; Extracting the boundary of each white strip area in the fourth image; The boundary of each white strip area is drawn into a preset canvas to obtain a sub-contour of each strip in the second image.
4. The method according to claim 1, characterized in that: In the case where the first sub-contour exists, after determining whether the first sub-contour exists according to the sub-contour of each bar and a preset height threshold, the method further includes: Performing clustering processing on the first sub-contours according to coordinate values in a first direction to obtain at least one contour cluster, wherein the first direction is a direction perpendicular to the strip; Extracting the defect area of each of the contour clusters through morphological black hat operations; The defects of the barcode are analyzed and located according to the defect area.
5. The method according to claim 1, characterized in that The correction process is performed on the second barcode region by using a preset width and a preset height to obtain a second image corresponding to the barcode, including: Determine a transformation matrix according to a preset width and a preset height, and coordinates of at least three corner points of the second barcode area; According to the transformation matrix, performing an affine transformation on the second barcode region to obtain a corrected second barcode region; The corrected image of the second barcode region is determined as the second image.
6. The method according to claim 1, characterized in that The step of determining a first barcode region in the first image when the first image is acquired includes: When a first image is acquired, the first image is matched with a template to determine a first barcode region in the first image, wherein the template is used to represent image content corresponding to the barcode.
7. The method according to claim 6, characterized in that When the first image is acquired, matching the first image with a template to determine a first barcode area in the first image includes: When the first image is acquired, denoising is performed on the first image to obtain a third image; The third image is matched with the template to determine the first barcode area in the third image.
8. A barcode defect detection device, characterized in that: include: A first determination module, configured to determine a first barcode region in a first image when a first image is acquired; A processing module, configured to perform denoising on the first barcode region to obtain a denoised first barcode region; An extraction module, configured to extract the outer contour of the barcode in the first image according to the first barcode area after the denoising process, so as to obtain a second barcode area; A correction module, used to perform correction processing on the second barcode area by using a preset width and a preset height to obtain a second image corresponding to the barcode in the first image; A detection module, configured to perform barcode defect detection based on the second image; The processing module is further used for: Performing denoising on the first barcode region by a target operation to obtain a denoised first barcode region, wherein the target operation includes at least one of a morphological closing operation and a morphological opening operation; The detection module is further used for: Extracting a sub-contour of each bar in the second image; Determining whether a first sub-contour exists according to each bar-shaped sub-contour and a preset height threshold, wherein the height of the first sub-contour is less than the height threshold; In the case where the first sub-profile exists, determining that the barcode has a defect; In the case where the first barcode region after the denoising process is a second binarized image after the binarization process, the extraction module is further used to: Performing a debinarization process on the second binarized image to obtain a debinarized image; Extracting four corner points of the white edge in the debinarized image to obtain the outer contour of the barcode in the first image; The area corresponding to the outer contour is determined as the second barcode area.
9. An electronic device, characterized in that: The device comprises: a processor and a memory storing programs or instructions; When the processor executes the program or instruction, the method according to any one of claims 1 to 7 is implemented.
10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Defect detection method and apparatus, electronic device, and readable storage medium
WO2023179122A1