Defect detection method and device and electronic equipment

By performing multi-directional filtering and difference analysis on barcode images, combined with binarization segmentation and shape feature screening, the defects of black and white lines in the inkjet printing process can be identified, solving the problem of insufficient detection in existing technologies and improving detection accuracy and packaging quality.

CN121962005APending Publication Date: 2026-05-01苏州凌云光工业智能技术有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
苏州凌云光工业智能技术有限公司
Filing Date
2025-12-15
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

The lack of effective detection methods in the current technology to identify the appearance defects of black and white lines generated during the inkjet printing process leads to barcode appearance problems that affect packaging quality and product appearance.

Method used

By performing multi-directional filtering on the barcode image, feature images are obtained, and candidate defect images are generated based on the difference information between the feature images. By combining binarization segmentation and shape feature information, the target defect region is determined from the candidate defect images.

Benefits of technology

It improves the sensitivity and accuracy of barcode appearance defect detection, enhances packaging quality and product appearance, and effectively monitors barcode appearance problems generated during the coding process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121962005A_ABST
    Figure CN121962005A_ABST
Patent Text Reader

Abstract

The invention discloses a defect detection method and device and electronic equipment, and belongs to the technical field of defect detection. The defect detection method comprises the following steps: performing at least two times of filtering processing on an initial image corresponding to a bar code to be detected to obtain at least two target feature images; wherein the filtering directions of the at least two times of filtering processing are different; obtaining candidate defect images based on difference information between the at least two target feature images; and processing the candidate defect image, and determining a target defect area from the candidate defect image. According to the defect detection method, the bar code appearance problem generated in the code spraying process can be effectively supervised, the packaging quality and the product impression are improved, and the detection sensitivity and accuracy of the appearance defect in the bar code are high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of defect detection technology, and in particular relates to a defect detection method, apparatus and electronic equipment. Background Technology

[0002] In logistics, industrial manufacturing, and product traceability, one-dimensional barcodes serve as crucial information carriers, and their inkjet printing quality directly impacts brand image and product quality. However, there is a lack of specialized and effective detection methods for appearance defects in the black and white lines generated during the inkjet printing process, such as rough edges, ink diffusion, or white line clogging. This results in barcodes with appearance defects entering subsequent stages, affecting packaging quality and product appearance. Summary of the Invention

[0003] This invention aims to address at least one of the technical problems existing in the prior art. To this end, this invention proposes a defect detection method, apparatus, and electronic device that can effectively monitor barcode appearance problems generated during the inkjet printing process, improving packaging quality and product appearance, and exhibiting high sensitivity and accuracy in detecting appearance defects in barcodes.

[0004] Firstly, this application provides a defect detection method, including: The initial image corresponding to the barcode to be tested is subjected to at least two filtering processes to obtain at least two target feature images; wherein the filtering directions of the at least two filtering processes are different. Based on the difference information between the at least two target feature images, candidate defect images are obtained; The candidate defect image is processed to determine the target defect region from the candidate defect image.

[0005] According to the defect detection method provided in the embodiments of this application, feature images are obtained by multi-directional filtering of barcode images, and candidate defect images are obtained based on the difference information between the feature images. Then, the candidate defect images are processed to determine the target defect area from the candidate defect images. This can effectively supervise the barcode appearance problems generated during the inkjet printing process, improve packaging quality and product appearance, and has high sensitivity and accuracy in detecting appearance defects in barcodes.

[0006] A defect detection method according to an embodiment of this application, wherein processing the candidate defect image to determine the target defect region from the candidate defect image includes: The candidate defect image is subjected to binarization segmentation to obtain a binary image; Based on the shape feature information of the connected regions in the binary image, the target defect region is obtained from the connected regions.

[0007] One embodiment of the defect detection method of this application includes performing binarization segmentation processing on the candidate defect image to obtain a binary image, comprising: The candidate defect image is segmented using at least two different segmentation thresholds to obtain at least two binary images.

[0008] One embodiment of the defect detection method of this application, wherein, when the at least two different segmentation thresholds include a first threshold and a second threshold, the step of segmenting the candidate defect image using at least two different segmentation thresholds to obtain at least two binary images includes: The candidate defect image is segmented using a first threshold to obtain a first binary image; The candidate defect image is segmented using a second threshold to obtain a second binary image; wherein the absolute value of the first threshold is greater than the absolute value of the second threshold.

[0009] One embodiment of the defect detection method of this application, wherein obtaining the target defect region from the connected regions based on the shape feature information of the connected regions in the binary image, includes: The connected regions in the first binary image are filtered to obtain a first type of defect region; the shape feature information of the first type of defect region satisfies the target filtering condition. The connected regions in the second binary image are filtered to obtain the second type of defect region; the corresponding position of the second type of defect region in the first binary image is not determined to be the first type of defect region, and the shape feature information of the second type of defect region satisfies the target filtering condition. The first type of defect region and the second type of defect region are determined as the target defect region.

[0010] One embodiment of the defect detection method of this application includes target screening conditions including: the ratio of the width to the height of the minimum bounding rectangle of the connected region is less than a target ratio threshold, and / or the area of ​​the connected region is greater than a target area threshold.

[0011] One embodiment of the defect detection method of this application, wherein obtaining a candidate defect image based on the difference information between the at least two target feature images, includes: The candidate defect image is obtained by performing a difference operation on the at least two target feature images; wherein, the region in the candidate defect image whose gray value is outside the preset gray value range is used to characterize the candidate defect region.

[0012] One embodiment of the defect detection method of this application includes performing at least two filtering processes on the initial image corresponding to the barcode to be tested to obtain at least two target feature images, including: The initial image is filtered along a first direction to obtain a first target feature image; The first target feature image is filtered along the second direction to obtain the second target feature image; the second direction is parallel to the bar extension direction of the barcode to be tested; the first direction is perpendicular to the second direction.

[0013] Secondly, this application provides a defect detection device, comprising: The first processing module is used to perform at least two filtering processes on the initial image corresponding to the barcode to be tested to obtain at least two target feature images; wherein the filtering directions of the at least two filtering processes are different; The second processing module is used to obtain candidate defect images based on the difference information between the at least two target feature images; The third processing module is used to process the candidate defect image and determine the target defect region from the candidate defect image.

[0014] According to the defect detection device provided in the embodiments of this application, feature images are obtained by multi-directional filtering of barcode images, and candidate defect images are obtained based on the difference information between the feature images. Then, the candidate defect images are processed to determine the target defect area from the candidate defect images. This can effectively supervise the barcode appearance problems generated during the inkjet printing process, improve packaging quality and product appearance, and has high sensitivity and accuracy in detecting appearance defects in barcodes.

[0015] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the defect detection method as described in the first aspect above.

[0016] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the defect detection method as described in the first aspect above.

[0017] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the defect detection method as described in the first aspect.

[0018] In a sixth aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the defect detection method as described in the first aspect above.

[0019] The above-described one or more technical solutions in the embodiments of this application have at least one of the following technical effects: By performing multi-directional filtering on the barcode image to obtain a feature image, and then obtaining a candidate defect image based on the difference information between the feature images, the candidate defect image is processed to determine the target defect area. This can effectively supervise the barcode appearance problems generated during the inkjet printing process, improve packaging quality and product appearance, and has high sensitivity and accuracy in detecting appearance defects in barcodes.

[0020] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0021] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating the defect detection method provided in the embodiments of this application; Figure 2 This is a schematic diagram of a defect in the defect detection method provided in the embodiments of this application; Figure 3 This is a schematic diagram of the defect detection device provided in the embodiments of this application; Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0022] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0023] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0024] The defect detection method, defect detection device, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.

[0025] Among them, the defect detection method can be applied to the terminal, and can be executed by the hardware or software in the terminal.

[0026] The defect detection method provided in this application embodiment can be executed by an electronic device or a functional module or entity in an electronic device that can implement the defect detection method. The electronic devices mentioned in this application embodiment include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices. The defect detection method provided in this application embodiment is described below using an electronic device as the execution subject.

[0027] like Figure 1 As shown, the defect detection method includes steps 110, 120 and 130.

[0028] Step 110: Perform at least two filtering processes on the initial image corresponding to the barcode to be tested to obtain at least two target feature images; In this step, the barcode to be tested is a one-dimensional barcode that needs to be inspected for appearance defects. For example, it can be a one-dimensional barcode used in logistics, industrial manufacturing and product traceability.

[0029] One-dimensional barcodes are identification symbols composed of regularly arranged bars, spaces, and corresponding characters, widely used for product identification and information storage. One-dimensional barcodes can represent information through horizontally arranged bars and blank areas.

[0030] The initial image is an image containing the barcode to be tested, which can be acquired by image acquisition devices such as industrial cameras and scanners. The initial image can be a grayscale image or an image after grayscale processing, and includes the original grayscale information of the barcode area.

[0031] The initial image can be filtered two or more times, and the filtering directions (i.e., the main extension direction of the filtering kernel or operation) of at least two filtering operations are different. For example, one filtering may mainly smooth pixels or extract features along the horizontal direction (X-axis), while another filtering may mainly be performed along the vertical direction (Y-axis) or other directions.

[0032] By setting different filtering directions, images containing different directional features can be extracted from the same initial image.

[0033] The target feature image is the output image obtained after directional filtering. Each filtering direction is different, and the resulting at least two target feature images enhance or retain the feature information in different directions of the initial image. For example, one filtering may result in an image that enhances the vertical continuity, while another filtering may result in an image that weakens the vertical continuity.

[0034] Step 120: Based on the difference information between at least two target feature images, obtain candidate defect images; In this step, the difference information can be the difference in gray values ​​calculated at corresponding pixel positions or regions by comparing at least two target feature images.

[0035] The feature images of each target may appear similar in normal barcode areas, but may show significant differences in areas with specific directional defects.

[0036] In candidate feature images, the magnitude (or absolute value) of grayscale values ​​characterizes the degree of directional difference at the corresponding location. For example, in normal areas, the difference information is close to zero, and the image grayscale value is low (e.g., close to black); in areas where there may be vertical continuity defects, the difference information is significant, and the image grayscale value is high (e.g., displayed as a bright area); candidate feature images can be used to characterize all possible defect locations.

[0037] Step 130: Process the candidate defect images to determine the target defect region from the candidate defect images.

[0038] In this step, when analyzing candidate defect images, screening and judgment can be performed based on the elongated shape of the barcode bars to identify abnormal areas in the candidate defect images that conform to or closely resemble the elongated shape of the bars. A one-dimensional barcode consists of a series of parallel, alternating black and white "bars" and "spaces" (collectively referred to as barcodes). The barcodes have a basic elongated shape, meaning they extend along the barcode's encoding direction (usually vertical), and are narrower in the direction perpendicular to it.

[0039] The target defect area is the region in the barcode to be tested where a real defect exists.

[0040] Target defects can include linear defects and stripe defects, such as black line defects (e.g., abnormally dark black vertical lines thicker than the design width) and white line defects (e.g., abnormally bright white vertical lines narrower than the design width or completely missing). Figure 2 Examples of black line defects and white line defects are provided.

[0041] In the application, by using a combination of directional filters, image features are extracted from different dimensions, and by comparing their differences, candidate defect images that can characterize gray-level continuity anomalies along a specific direction are obtained. This can effectively amplify and highlight continuous defect features (such as slight brightening of white lines and thickening of black lines) that are originally mixed in with complex barcode textures and background noise, thereby improving the accuracy of detecting such defects.

[0042] Processing candidate defect images based on the inherent shape features of barcodes can effectively eliminate false defects with mismatched shapes, such as circular ink spots, irregular stains, and random image noise, thereby improving the accuracy of detection results and reducing the false alarm rate.

[0043] According to the defect detection method provided in the embodiments of this application, feature images are obtained by multi-directional filtering of barcode images, and candidate defect images are obtained based on the difference information between the feature images. Then, the candidate defect images are processed to determine the target defect area from the candidate defect images. This can effectively supervise the barcode appearance problems generated during the inkjet printing process, improve packaging quality and product appearance, and has high sensitivity and accuracy in detecting appearance defects in barcodes.

[0044] In some embodiments, step 130 may include: The candidate defect image is binarized and segmented to obtain a binary image; Based on the shape feature information of connected regions in a binary image, the target defect region is obtained from the connected regions.

[0045] In this embodiment, binarization segmentation processing is performed on the candidate defect image, which can convert the candidate defect image into a binary image containing only two pixel values ​​(e.g., 0 and 255, or "black" and "white").

[0046] In some embodiments, binarization segmentation can be performed by setting one or more segmentation thresholds. For example, pixels in the candidate defect image whose grayscale values ​​meet specific conditions (e.g., greater than or equal to a certain threshold) can be classified into the first category (e.g., represented as white), and pixels that do not meet the conditions can be classified into the second category (e.g., represented as black).

[0047] After performing binarization segmentation on the candidate defect image, a binary image can be obtained. In the binary image, the region formed by white pixels represents the connected region that may belong to the defect and is initially segmented from the candidate defect image. Here, a connected region refers to the set of pixels that are adjacent in position and have the same pixel value in the image.

[0048] The shape characteristics of a connected region can include its area, perimeter, dimensions (width and height) of the smallest bounding rectangle and its aspect ratio, circularity, and extensibility.

[0049] The shape feature information calculated for each connected region is compared and filtered with pre-set judgment conditions that reflect the shape feature information of the barcode to be tested. For example, since the bars of a one-dimensional barcode are long and thin, the connected region corresponding to the target defect region in the binary image should also be long and thin. That is, the width of the minimum bounding rectangle of the target defect region should be significantly smaller than its height, and its area should be greater than a set threshold. Only connected regions whose shape feature information meets these preset conditions will be identified as target defect regions, and connected regions that do not meet the conditions will be excluded.

[0050] In some embodiments, performing binarization segmentation on the candidate defect image to obtain a binary image may include: The candidate defect image is segmented using at least two different segmentation thresholds to obtain at least two binary images.

[0051] In this embodiment, at least two different segmentation thresholds may include two or more thresholds with different values. The segmentation thresholds represent different segmentation strictnesses based on the magnitude of their absolute values. For example, they may be a set of thresholds {T1,T2,…,Tn}, where |T1|>|T2|>…>|Tn| (n≥2). The specific values ​​and number of thresholds can be user-defined and are not limited in this application.

[0052] For each segmentation threshold, an image binarization operation can be performed independently. That is, the gray value of each pixel in the candidate defect image is compared with the segmentation threshold, and a binary image is generated based on the comparison result.

[0053] In some embodiments, when at least two different segmentation thresholds include a first threshold and a second threshold, segmenting the candidate defect image using at least two different segmentation thresholds to obtain at least two binary images may include: The candidate defect image is segmented using a first threshold to obtain a first binary image; The candidate defect image is segmented using a second threshold to obtain a second binary image.

[0054] In this embodiment, the first threshold is a pre-set grayscale threshold with a large absolute value (representing a high degree of strictness). The specific value can be determined based on image quality, defect contrast expectation, or experience, and is not limited in this application.

[0055] The candidate defect image is segmented using a first threshold. The gray value of each pixel in the candidate defect image is compared with the first threshold. For example, pixels with gray values ​​greater than or equal to the first threshold are set as the first value (such as white), and pixels with gray values ​​less than the first threshold are set as the second value (such as black).

[0056] In the first binary image, white connected regions represent candidate defect regions that are significantly different from the background and have a high degree of confidence. The first binary image usually contains less noise, but may miss some real defects with relatively weak contrast.

[0057] The second threshold is a pre-set grayscale threshold, and the absolute value of the first threshold is greater than the absolute value of the second threshold. The second threshold is a relatively lenient threshold standard.

[0058] The second binary image will contain more white connected regions. These regions not only cover the high-confidence regions that already exist in the first binary image, but may also contain some candidate defect regions that were missed by the first threshold due to their weak contrast.

[0059] In this application, two binary images with different absolute values ​​are obtained by segmenting the same candidate defect image using two thresholds with different absolute values. Even in cases where the image quality is poor or the gray-scale contrast of the defect is weak, the defect region can be obtained more accurately.

[0060] In some embodiments, obtaining the target defect region from the connected regions based on the shape feature information of the connected regions in the binary image may include: The connected regions in the first binary image are filtered to obtain the first type of defect region; the shape feature information of the first type of defect region satisfies the target filtering condition. The connected regions in the second binary image are filtered to obtain the second type of defect region; the corresponding position of the second type of defect region in the first binary image is not identified as the first type of defect region, and the shape feature information of the second type of defect region meets the target filtering conditions. The first type of defect area and the second type of defect area are identified as the target defect areas.

[0061] In this embodiment, for each connected region in the first binary image, its related shape feature information (such as area and minimum bounding rectangle aspect ratio) can be calculated and compared with the target screening conditions. Connected regions that meet the conditions are identified as real defects and classified as first-class defect regions, representing defects with strong contrast and typical shape, with a high degree of certainty.

[0062] The corresponding position of the second type of defect region in the first binary image is the range of pixel coordinates covered by the currently detected connected region in the second binary image. It can be determined whether there is already a connected region in the first binary image that has been identified as a first type of defect region within the same pixel coordinate range (corresponding position). If the corresponding position has been covered by a first type of defect region, it means that the defect at this position has been confirmed by a standard with higher confidence (first threshold), and this connected region in the current second binary image does not need to be analyzed and judged again. If the corresponding position is not covered by any first type of defect region, it indicates that the defect here may have weak contrast and failed to be captured by the first threshold, and the next step of judgment can be carried out.

[0063] For connected regions identified in the second binary image whose corresponding positions are not covered by the first type of defect region, their shape feature information can be further calculated. If their shape feature information meets the target screening conditions, the region can be identified as a real defect.

[0064] The second type of defect area consists of defects with relatively weak contrast, but whose morphological characteristics still meet the requirements.

[0065] The first type of defect region and the second type of defect region can be identified as the target defect region. For example, all connected regions that are identified as the first type of defect region and the second type of defect region can be merged and identified as the target defect region.

[0066] In this application, obvious defect areas are first quickly detected using high threshold results (first binary image), and then supplementary monitoring is performed on the high threshold missed areas based on low threshold results (second binary image). This improves the ability to capture weak defects without increasing the risk of misjudging high-confidence defects, enabling the detection system to improve the defect detection rate while ensuring high reliability.

[0067] In some embodiments, multiple preset segmentation thresholds can be used for more precise intensity control; or adaptive segmentation thresholds can be dynamically generated based on image content; the method for obtaining the target defect region from the connected region is similar to the dual threshold segmentation screening method, and will not be described in detail here.

[0068] In some embodiments, target filtering criteria may include: the ratio of the width to the height of the smallest bounding rectangle of the connected region is less than a target ratio threshold, and / or the area of ​​the connected region is greater than a target area threshold.

[0069] In this embodiment, the minimum bounding rectangle of the connected region is the rectangle with the smallest area among those rectangles that can completely enclose all pixels of the connected region and whose edges are parallel (horizontal / vertical) to the image coordinate axes.

[0070] For a one-dimensional barcode, the bars extend vertically, so the connected regions corresponding to the linear defects associated with the bars in the image should also exhibit vertical extension, and their minimum bounding rectangle usually has a large height and a small width.

[0071] The target ratio threshold is a preset value, such as 0.5, 0.3 or 0.1, etc. It can be based on user-defined values, such as the theoretical width of the barcode, the imaging resolution and the specific requirements for the slenderness, etc. This application does not limit it.

[0072] By setting the minimum bounding rectangle of the connected region to have a width-to-height ratio less than the target ratio threshold, the filtered connected regions are elongated in shape, which can exclude near-circular (width-to-height ratio close to 1) or horizontal strip-shaped regions, ensuring that the filtered regions are related to the bar defect in shape.

[0073] Setting a filtering condition that the area of ​​the connected region is greater than the target area threshold can be used to distinguish real defect areas from small image noise, isolated pixels, or shot noise caused by the sensor.

[0074] The target area threshold is a pre-set number of pixels, which can be determined based on the point spread function of the imaging system, the minimum identifiable size of the barcode module, and the minimum allowable defect size. This ensures that only areas reaching a certain size will be identified as defect areas, improving the robustness of the detection results and avoiding false detections caused by random noise.

[0075] In some embodiments, the target filtering criteria may further include: the absolute value of the difference between the average gray level of the connected region and the average gray level of its immediate surrounding background region is greater than the target contrast threshold.

[0076] In this embodiment, it can be ensured that the detected defects are indeed significant visual anomalies in the original image.

[0077] In some embodiments, the target filtering criteria may further include: the standard deviation of the gray values ​​of the pixels covered by the connected region is less than the target standard deviation threshold.

[0078] In this embodiment, a real white line defect should have relatively uniform (bright) gray values ​​inside, and a black line defect should have relatively uniform (dark) gray values ​​inside. If the gray values ​​fluctuate drastically within a region, it may be a pseudo-defect caused by its complex texture or mixed noise.

[0079] In some embodiments, target screening conditions can also be determined based on features such as the centroid arrangement pattern of connected regions, the distance from the barcode boundary, and the interval pattern between defects, in order to make a comprehensive judgment.

[0080] In some embodiments, the filtering may be performed using only the aspect ratio condition, or only the area condition, or both the aspect ratio condition and the area condition may be used for filtering. This application does not impose any limitations on these aspects.

[0081] In some embodiments, step 120 may include: Perform a difference operation on at least two target feature images to obtain candidate defect images.

[0082] In this embodiment, a difference operation is performed on at least two target feature images to calculate the difference in gray values ​​at corresponding pixel positions between the two target feature images, thereby obtaining a difference image, i.e., a candidate defect image.

[0083] Regions in the candidate defect image whose grayscale values ​​are outside the preset grayscale range are used to characterize candidate defect regions.

[0084] In a candidate defect image, in an ideal normal region where there is no directional gray-level anomaly, the gray values ​​of the two target feature images at corresponding positions should be close, and the difference between the gray values ​​of the two target feature images at corresponding positions (i.e., the gray value of the candidate defect image) should fluctuate slightly around zero.

[0085] The preset grayscale range can be set to a symmetrical interval centered at zero with a small span, such as [-T, +T], where T is a small positive threshold.

[0086] For example, if the gray value is greater than the upper limit of the preset gray value range or less than the lower limit of the preset gray value range, the region can represent a candidate defect region.

[0087] Pixels whose grayscale values ​​are outside the preset grayscale range are initially identified as candidate locations for potential defects. The connected regions formed by these adjacent candidate pixels constitute the candidate defect region.

[0088] In some embodiments, step 110 may include: The initial image is filtered along the first direction to obtain the first target feature image; The first target feature image is filtered along the second direction to obtain the second target feature image.

[0089] In this embodiment, for a standard one-dimensional barcode, the bars (black and white bars) are usually arranged vertically, and the direction of the bar's gaze is generally the vertical direction (Y-axis direction) in the image coordinate system, i.e., the second direction.

[0090] The first direction is the horizontal direction (X-axis direction) that is perpendicular to the second direction.

[0091] Filtering the initial image along the first direction means that the filter kernel (or the main extension direction of the operation) of the filtering operation is designed and applied along the first direction.

[0092] For example, the initial image can be subjected to horizontal mean filtering with an N×1 filter kernel to obtain the first target feature image. Then, the first target feature image can be subjected to vertical mean filtering to obtain the second target feature image, where the filter kernel is 1×N.

[0093] In some embodiments, other filtering operators, such as Gaussian filtering or median filtering, may be selected according to the actual scenario, and this application does not limit them.

[0094] In this application, filtering the first target feature image, which has already been horizontally smoothed, again along the vertical direction can perform further global smoothing. The resulting second target feature image can significantly blur or weaken the grayscale changes in the vertical direction of the image, including the grayscale changes in the vertical direction caused by normal bar edges and potential defects.

[0095] Through the above filtering process, in the subsequent difference operation, the first target feature image (which retains the vertical line features) and the second target feature image (which weakens the vertical line features) produce significant grayscale differences in areas where there are real vertical line defects, while in areas with normal texture and uniformity or in areas with non-vertical line interference, the difference between the two is small, thus enabling the difference operation to highlight the real defects.

[0096] During the research and development process, the inventors discovered that black and white line defects in one-dimensional barcodes exhibit good continuity in the horizontal direction (perpendicular to the direction of barcode bar extension). If a white line defect runs through a row, the average gray level of that row will be higher than that of a defect-free position. Conversely, if a black line defect runs through a row, the gray level of the defective row will be lower than that of the normal position. Defect detection can be performed based on the gray level difference between the defective and normal positions.

[0097] In this application, the initial image is filtered in different directions. For example, the image is first filtered along the horizontal direction to enhance the overall grayscale performance of the entire row of pixels. For rows with continuity defects, the abnormal high or low grayscale is smoothed, and the entire row will form a more uniform bright or dark band. That is, the average grayscale abnormality of the row is highlighted, and the first target feature image is obtained.

[0098] Then, filtering the above results in the vertical direction will blur the differences between rows, which is equivalent to weakening the features of the rows, resulting in a second target feature image where the gray levels of each row tend to be consistent.

[0099] The first target feature image and the second target feature image are subtracted. For normal areas, the grayscale difference between the two images is very small, and the difference is close to zero. For defective row areas, since the row is enhanced as a bright / dark band in the first target feature image, while the feature is weakened in the second target feature image, the subtraction of the two will produce a strong positive or negative difference. Through the difference operation, the weak continuous grayscale differences that were originally scattered on the row can be aggregated and amplified into a high-contrast bright or dark line in the image.

[0100] Then, by filtering the candidate connected regions extracted from the difference image, the target defect region can be obtained.

[0101] The defect detection method provided in this application can be executed by a defect detection device. This application uses the example of a defect detection device executing the defect detection method to illustrate the defect detection device provided in this application.

[0102] This application also provides a defect detection device.

[0103] like Figure 3 As shown, the defect detection device includes: a first processing module 310, a second processing module 320 and a third processing module 330.

[0104] The first processing module 310 is used to perform at least two filtering processes on the initial image corresponding to the barcode to be tested to obtain at least two target feature images; wherein the filtering directions of the at least two filtering processes are different. The second processing module 320 is used to obtain candidate defect images based on the difference information between at least two target feature images; The third processing module 330 is used to process the candidate defect image and determine the target defect region from the candidate defect image.

[0105] According to the defect detection device provided in the embodiments of this application, feature images are obtained by multi-directional filtering of barcode images, and candidate defect images are obtained based on the difference information between the feature images. Then, the candidate defect images are processed to determine the target defect area from the candidate defect images. This can effectively supervise the barcode appearance problems generated during the inkjet printing process, improve packaging quality and product appearance, and has high sensitivity and accuracy in detecting appearance defects in barcodes.

[0106] In some embodiments, the third processing module 330 can also be used for: The candidate defect image is binarized and segmented to obtain a binary image; Based on the shape feature information of connected regions in a binary image, the target defect region is obtained from the connected regions.

[0107] In some embodiments, the third processing module 330 can also be used for: The candidate defect image is segmented using at least two different segmentation thresholds to obtain at least two binary images.

[0108] In some embodiments, where at least two different segmentation thresholds include a first threshold and a second threshold, the third processing module 330 can also be used to: The candidate defect image is segmented using a first threshold to obtain a first binary image; The candidate defect image is segmented using a second threshold to obtain a second binary image; wherein the absolute value of the first threshold is greater than the absolute value of the second threshold.

[0109] In some embodiments, the third processing module 330 can also be used for: The connected regions in the first binary image are filtered to obtain the first type of defect region; the shape feature information of the first type of defect region satisfies the target filtering condition. The connected regions in the second binary image are filtered to obtain the second type of defect region; the corresponding position of the second type of defect region in the first binary image is not identified as the first type of defect region, and the shape feature information of the second type of defect region meets the target filtering conditions. The first type of defect area and the second type of defect area are identified as the target defect areas.

[0110] In some embodiments, the third processing module 330 may also be used to set target filtering conditions including: the ratio of the width to the height of the minimum bounding rectangle of the connected region is less than a target ratio threshold, and / or the area of ​​the connected region is greater than a target area threshold.

[0111] In some embodiments, the second processing module 320 may also be used for: Perform a difference operation on at least two target feature images to obtain candidate defect images; wherein, the region in the candidate defect image whose gray value is outside the preset gray value range is used to characterize the candidate defect region.

[0112] In some embodiments, the first processing module 310 may also be used for: The initial image is filtered along the first direction to obtain the first target feature image; The first target feature image is filtered along the second direction to obtain the second target feature image; the second direction is parallel to the bar extension direction of the barcode to be tested; the first direction is perpendicular to the second direction.

[0113] The defect detection device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.

[0114] The defect detection device in this application embodiment can be a device with an operating system. This operating system can be a Microsoft (Windows) operating system, an Android operating system, an iOS operating system, or other possible operating systems; this application embodiment does not specifically limit the specific operating system.

[0115] The defect detection device provided in this application embodiment can achieve... Figures 1 to 2 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.

[0116] In some embodiments, such as Figure 4 As shown, this application embodiment also provides an electronic device 400, including a processor 401, a memory 402, and a computer program stored in the memory 402 and executable on the processor 401. When the program is executed by the processor 401, it implements the various processes of the above-described defect detection method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0117] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0118] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described defect detection method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0119] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0120] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described defect detection method.

[0121] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0122] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described defect detection method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0123] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0124] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0125] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the related technology, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0126] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

[0127] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0128] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.

Claims

1. A defect detection method, characterized in that, include: The initial image corresponding to the barcode to be tested is subjected to at least two filtering processes to obtain at least two target feature images; wherein the filtering directions of the at least two filtering processes are different. Based on the difference information between the at least two target feature images, candidate defect images are obtained; The candidate defect image is processed to determine the target defect region from the candidate defect image.

2. The defect detection method according to claim 1, characterized in that, The step of processing the candidate defect image to determine the target defect region from the candidate defect image includes: The candidate defect image is subjected to binarization segmentation to obtain a binary image; Based on the shape feature information of the connected regions in the binary image, the target defect region is obtained from the connected regions.

3. The defect detection method according to claim 2, characterized in that, The step of performing binarization segmentation on the candidate defect image to obtain a binary image includes: The candidate defect image is segmented using at least two different segmentation thresholds to obtain at least two binary images.

4. The defect detection method according to claim 3, characterized in that, When the at least two different segmentation thresholds include a first threshold and a second threshold, the segmentation process of the candidate defect image using at least two different segmentation thresholds to obtain at least two binary images includes: The candidate defect image is segmented using a first threshold to obtain a first binary image; The candidate defect image is segmented using a second threshold to obtain a second binary image; wherein the absolute value of the first threshold is greater than the absolute value of the second threshold.

5. The defect detection method according to claim 4, characterized in that, The step of obtaining the target defect region from the connected regions based on the shape feature information of the connected regions in the binary image includes: The connected regions in the first binary image are filtered to obtain a first type of defect region; the shape feature information of the first type of defect region satisfies the target filtering condition. The connected regions in the second binary image are filtered to obtain the second type of defect region; the corresponding position of the second type of defect region in the first binary image is not determined to be the first type of defect region, and the shape feature information of the second type of defect region satisfies the target filtering condition. The first type of defect region and the second type of defect region are determined as the target defect region.

6. The defect detection method according to claim 5, characterized in that, The target filtering conditions include: the ratio of the width to the height of the smallest bounding rectangle of the connected region is less than the target ratio threshold, and / or the area of ​​the connected region is greater than the target area threshold.

7. The defect detection method according to any one of claims 1-6, characterized in that, The process of obtaining candidate defect images based on the difference information between the at least two target feature images includes: The candidate defect image is obtained by performing a difference operation on the at least two target feature images; wherein, the region in the candidate defect image whose gray value is outside the preset gray value range is used to characterize the candidate defect region.

8. The defect detection method according to any one of claims 1-6, characterized in that, The initial image corresponding to the barcode to be tested is subjected to at least two filtering processes to obtain at least two target feature images, including: The initial image is filtered along a first direction to obtain a first target feature image; The first target feature image is filtered along the second direction to obtain the second target feature image; the second direction is parallel to the bar extension direction of the barcode to be tested; the first direction is perpendicular to the second direction.

9. A defect detection device, characterized in that, include: The first processing module is used to perform at least two filtering processes on the initial image corresponding to the barcode to be tested to obtain at least two target feature images; wherein the filtering directions of the at least two filtering processes are different; The second processing module is used to obtain candidate defect images based on the difference information between the at least two target feature images; The third processing module is used to process the candidate defect image and determine the target defect region from the candidate defect image.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the defect detection method as described in any one of claims 1-8.