A method for detecting barcode defects on milk powder food packaging based on image processing

Through image processing technology, the rectangular block purity and missing indicators of milk powder food packaging barcodes are calculated, and combined with adjacent block information, the accuracy of barcode defect detection is improved, solving the problem of low accuracy in the existing technology, and achieving a more reliable Defect detection.

CN118364839BActive Publication Date: 2024-09-24XIAN YANLIANG DISTRICT SUNSHINE DAIRY IND CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410774405.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-24
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

The accuracy of barcode defect detection in the existing technology is low, and false detection may occur due to decoding equipment or software problems, which affects the detection effect of barcodes on milk powder and food packaging.

Method used

Using an image processing-based method, the grayscale image of the barcode is obtained, divided into rectangular blocks, and the purity and missing indicators of each rectangular block are calculated. The defect index is calculated based on the information of adjacent rectangular blocks, and the barcode is judged according to the defect threshold. There are flaws.

Benefits of technology

It improves the accuracy of barcode defect detection, can more accurately identify barcode defects, reduces false detections, and enhances the reliability of barcode detection for milk powder and food packaging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118364839B
    Figure CN118364839B
Patent Text Reader

Abstract

The present invention relates to the technical field of image processing. The present invention relates to a method for detecting defects in a milk powder food package barcode based on image processing, comprising: obtaining a rectangular block of a grayscale image of a barcode; taking any rectangular block as a target block, and calculating the purity of the target block based on the gradient amplitude and grayscale mean of non-edge pixel points of the target block; calculating the missing index of the target block based on the purity and the discrete degree of the bar height of the first and second bar graphs of the target block, wherein the bar height of the first and second bar graphs is the sum of the grayscale values ​​of pixels with the same horizontal and vertical coordinates, respectively; calculating the defect index of the target block based on the missing index and purity; calculating the defect value of the barcode based on the defect index of the rectangular block; and considering that the barcode has a defect in response to the defect value being greater than a defect threshold. The present invention improves the accuracy of defect detection on barcodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing and a method for detecting barcode defects on milk powder food packaging based on image processing. Background Art

[0002] Barcode technology is an automatic identification technology that was generated and developed in the application of computers. Barcode technology is also needed in the production process of milk powder food to obtain information about milk powder food. In the process of printing barcodes on milk powder food packaging, defects may occur on the barcodes on milk powder food packaging due to barcode printer failure or insufficient consumables, such as incomplete barcode printing and blurred barcodes.

[0003] In the related art, for example, the patent application document with application publication number CN116739017A discloses a barcode defect detection method based on image segmentation and recognition. The method discloses: first, the barcode in the image is decoded. If the decoding fails, it means that the defective area of ​​the barcode may be large and has affected the reading of the information; if the decoding is successful, the barcode is segmented to obtain multiple sub-areas, and then each sub-area is decoded; if all sub-areas are decoded successfully, a "no defect found" result is returned, otherwise, a "defect detected" result is returned, and the coordinates of the sub-area with defects are returned.

[0004] When the above method is used to detect barcode defects, the entire barcode is first decoded. If the decoding fails, it is directly considered that the barcode has defects. However, it should be noted that the reason for the failure of decoding the barcode may also be problems with the decoding device, decoding software, etc., so the above method may result in false detection. Therefore, the above solution has a low accuracy rate for barcode defect detection. Summary of the invention

[0005] In order to solve the above-mentioned technical problem of low accuracy in barcode defect detection, the present invention proposes a method for detecting barcode defects on milk powder food packaging based on image processing.

[0006] In an embodiment of the present invention, a method for detecting barcode defects on milk powder food packaging based on image processing is provided, comprising:

[0007] Get a rectangular block of the grayscale image of the barcode;

[0008] Take any rectangular block as the target block and calculate the purity of the target block , , where I is the grayscale mean of the target block, e is a natural constant, and the cumulative sum of the gradient amplitudes of the non-edge pixels in the target block is called the gradient feature. The gradient feature is normalized to obtain the value T;

[0009] A coordinate system is established with the long side of the target block as the vertical axis, and the first and second bar graphs are determined. The height of the first bar of the first bar graph is the grayscale sum of the pixels with the same horizontal coordinate, and the category of the first bar graph is the same horizontal coordinate. The height of the second bar of the second bar graph is the grayscale sum of the pixels with the same vertical coordinate, and the category of the second bar graph is the same vertical coordinate. The first discrete degree of the first bar height is positively correlated and normalized to obtain the first index. , the second discrete degree corresponding to the second bar height is normalized by positive correlation to obtain the second index ; Calculate the missing index of the target block , , where e is a natural constant;

[0010] Calculating a defect index of the target block, wherein the defect index is positively correlated with the missing index, and the defect index is negatively correlated with the purity;

[0011] Based on the defect index of the rectangular block, a defect value of the barcode is calculated; in response to the defect value being greater than a defect threshold, it is considered that the barcode has a defect.

[0012] In one embodiment, the process of obtaining the defect index of any rectangular block includes: the expression of the defect index of the rectangular block is:

[0013] ;

[0014] , ;in, is the defect index of the i-th rectangular block in the grayscale image, is the missing index of the i-th rectangular block, For the The missing index of the rectangular block, For the The missing index of the rectangular block, is the missing weight, e is a natural constant, is the purity of the i-th rectangular block, For the The purity of a rectangular block, For the The purity of a rectangular block, is the purity weight, n is the total number of rectangular blocks in the grayscale image;

[0015] in, , , and It has no actual physical meaning and is used to calculate the defect index of rectangular blocks;

[0016] in, and Used to calculate the defect index of the first rectangular block, and Used to calculate the defect index of the nth rectangular block.

[0017] Due to the special structure of barcode printers, when a barcode rectangle has defects, the adjacent rectangles of the barcode are more likely to have defects. The reason is that barcode printers usually use thermal or thermal transfer technology to print barcodes. In both printing processes, the heating elements of the print head continuously act on the label paper or thermal paper to produce the barcode pattern. If a part of the print head fails or heats unevenly, it will not only affect the printing effect of the current rectangle, but also may affect the printing quality of the adjacent rectangles due to the continuous transfer of heat or uneven transfer of the ink ribbon.

[0018] Based on this, in order to improve the accuracy of calculating the defect index of the target block, the missing index and purity of the adjacent rectangular blocks of the target block can be involved in the calculation process of the defect index of the target block.

[0019] The larger it is, the more likely it is that the i-th rectangular block has more interrupted areas, the more likely it is that the i-th rectangular block has defects, or the greater the degree of defects in the i-th rectangular block; conversely, the greater the possibility that the degree of defects in the i-th rectangular block is smaller. The larger the value is, the more likely it is that the grayscale difference of the pixels in the ith rectangular block is smaller, and the more likely it is that the defect degree of the ith rectangular block is smaller; conversely, the greater the defect degree of the ith rectangular block is, the more likely it is. Based on this, the defect index of the ith rectangular block can be determined.

[0020] In one embodiment, the process of obtaining the defect index of any rectangular block includes: the expression of the defect index of the rectangular block is:

[0021] ;

[0022] in, is the defect index of the i-th rectangular block in the grayscale image, is the missing index of the ith rectangular block, e is a natural constant, is the purity of the i-th rectangular block.

[0023] The larger the value is, the greater the possibility that the i-th rectangular block has defects, or the greater the possibility that the degree of defects in the i-th rectangular block is; conversely, the smaller the degree of defects in the i-th rectangular block is, the greater the possibility. The larger the value is, the more likely it is that the defect level of the i-th rectangular block is smaller; conversely, the more likely it is that the defect level of the i-th rectangular block is larger. Based on this, the defect index of the i-th rectangular block can be determined.

[0024] In one embodiment, based on the defect index of the rectangular block, the defect value of the barcode is calculated; in response to the defect value being greater than the defect threshold, the barcode is considered to have a defect, including: the defect value The expression is:

[0025] , , where n is the total number of rectangular blocks in the grayscale image, is the defect index of the i-th rectangular block in the grayscale image, is the weight of the defect index of the i-th rectangular block;

[0026] In response to the defect value being greater than a first defect threshold, the barcode is deemed defective.

[0027] Since the importance of data corresponding to different rectangular blocks may be different, the data corresponding to some rectangular blocks are more important, so the weight of the defect index of some rectangular blocks is made larger.

[0028] In one embodiment, based on the defect index of the rectangular block, a defect value of the barcode is calculated, and in response to the defect value being greater than a defect threshold, it is considered that the barcode has a defect, including:

[0029] The maximum value of the defect index of the rectangular block is taken as the defect value M1 of the barcode;

[0030] In response to the defect value M1 being greater than a second defect threshold, it is considered that the barcode has a defect.

[0031] In one embodiment, the envelope of the first bar graph is determined, and the first discrete degree is the variance of the slope of the envelope corresponding to the first bar height; the envelope of the second bar graph is determined, and the second discrete degree is the variance of the slope of the envelope corresponding to the second bar height.

[0032] The larger the variance of the envelope slope corresponding to the first bar height, the greater the possibility that the envelope of the first bar graph has a greater degree of fluctuation, and the greater the possibility that the envelope fluctuation is more frequent. The larger the variance of the envelope slope corresponding to the second bar height, the greater the possibility that the envelope of the second bar graph has a greater degree of fluctuation, and the greater the possibility that the envelope fluctuation is more frequent. Based on this, the possibility that the target block has a defect can be determined.

[0033] In one embodiment, the barcode comprises an EAN-13 barcode.

[0034] In one embodiment, the rectangular blocks are modules.

[0035] Beneficial effects:

[0036] The grayscale image of the barcode can be divided into rectangular blocks, and the defect index of each rectangular block can be calculated subsequently to determine the defect value of the barcode. Finally, the defect value can be compared with the defect threshold. If the defect value is less than or equal to the defect threshold, it is considered that the defect index of the barcode can be ignored. If the defect value is greater than the defect threshold, it is considered that the defect index of the barcode has reached a certain level. At this time, it can be considered that the barcode has defects, which improves the accuracy of defect detection on the barcode.

[0037] If the target block has no defects, the grayscale values ​​of the pixels in the target block are all close to 0 or 255, that is, the target block is "pure white" or "pure black", so the grayscale mean of the target block is close to 0 or 255. The closer the grayscale mean of the target block is to 0 or 255, The larger the value is, the more pixels in the target block have grayscale values ​​close to 0 or 255, which means that the grayscale difference of the pixels in the target block is small and the possibility that the target block has defects is smaller; conversely, the possibility that the target block has defects is greater.

[0038] If the target block has no defects, the grayscale difference between the pixels in the target block is small, and the gradient amplitude of the non-edge pixels (internal pixels) in the target block is small. On the contrary, the probability that the grayscale difference between the pixels in the target block is large is high, and the probability that the gradient amplitude of the non-edge pixels in the target block is large is high. Therefore, the larger the cumulative sum of the gradient amplitudes of the non-edge pixels in the target block, the greater the grayscale difference between the pixels in the target block, and the greater the possibility that the target block has defects; on the contrary, the smaller the possibility that the target block has defects.

[0039] If the target block has no defects, the first discrete degree corresponding to the first bar graph of the target block is smaller, and the first discrete degree corresponding to the second bar graph of the target block is smaller. The larger the first discrete degree or the second discrete degree, the greater the possibility that the height fluctuation of the bars in the bar graph is greater, and the more frequent the fluctuation of the height of the bars in the bar graph is, the greater the possibility that the target block has more interrupted areas (i.e., areas where the grayscale is discontinuous compared to other areas), and the greater the possibility that the target block has defects; conversely, the smaller the possibility that the target block has defects.

[0040] The greater the purity of the target block, the more completely the target block is printed, and the greater the possibility that the target block has fewer interruption areas. Conversely, the greater the possibility that the target block has more interruption areas.

[0041] Based on this, the purity and missing index of the target block can be obtained, which are related to the defect index of the target block. The purity and missing index of the target block are involved in the subsequent calculation process of the defect index of the target block, which can improve the accuracy of the defect index of the target block.

[0042] The defect index indicates the degree of defect. Through the above analysis, it can be known that the defect index of the target block is related to the missing index and purity of the target block. Therefore, the defect index of the target block can be calculated based on the missing index and purity of the target block. It can be understood that the defect index of the barcode, that is, the defect value, can be calculated based on the defect index of all rectangular blocks in the grayscale image. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:

[0044] Figure 1 is a flow chart schematically showing a method for detecting barcode defects on milk powder food packaging based on image processing according to an embodiment of the present invention;

[0045] Figure 2 is a diagram schematically illustrating an EAN-13 barcode according to an embodiment of the present invention. DETAILED DESCRIPTION

[0046] In some of the processes described in the specification and claims of the present invention and the above-mentioned figures, multiple operations that appear in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this article or executed in parallel. The serial numbers of the operations, such as 101, 102, etc., are only used to distinguish different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this article are used to distinguish different messages, devices, modules, etc., do not represent the order of precedence, and do not limit the "first" and "second" to be different types.

[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0048] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0049] Figure 1 FIG. 1 is a flow chart schematically showing a method for detecting barcode defects on milk powder food packaging based on image processing according to an embodiment of the present invention. Figure 1 As shown, according to the present invention, a method for detecting barcode defects on milk powder food packaging based on image processing is provided.

[0050] The specific instructions are as follows: Figure 1 As shown, steps S1 to S7 are included:

[0051] In step S1, a grayscale image of a barcode to be detected is obtained.

[0052] In one embodiment, a barcode image can be obtained through a camera. Since the acquired image includes background information, which has certain complexity and uncertainty, and when processing the barcode in the image, the background information is likely to interfere with the identification of barcode defects, the barcode area in the image can be segmented out through semantic segmentation before proceeding to subsequent steps.

[0053] The relevant steps of semantic segmentation are:

[0054] 1. Image data acquisition: Collect images of milk powder food packaging containing barcodes under different lighting conditions and shooting angles.

[0055] 2. The labels are divided into two categories: image barcode area and background area. That is, the pixels in the image barcode area are marked as 1, and the pixels corresponding to the background area are marked as 0.

[0056] 3. The network adopts Unet structure and uses cross entropy loss function.

[0057] The obtained milk powder food packaging image containing the barcode is processed using the trained semantic segmentation model to extract the barcode area, thereby obtaining the barcode image, which is then grayscaled to obtain a grayscale image of the barcode.

[0058] The reason for converting the barcode image into a grayscale image is that the barcode on the milk powder food packaging is black and white, and the multi-channel image is not conducive to subsequent image processing. In order to facilitate subsequent image processing, the barcode image is converted into a grayscale image. For example, a grayscale image is more convenient for subsequent calculation of image gradients.

[0059] In one embodiment, the barcode comprises an EAN-13 barcode.

[0060] In step S2, the grayscale image is divided into rectangular blocks.

[0061] Because the barcode is black and white, the grayscale image can be divided into at least two rectangular blocks, where the rectangular blocks are not black and white, that is, the rectangular blocks are "pure" colors (for a defect-free barcode, the average grayscale value of each rectangular block is close to 0 or 255). Each rectangular block can be analyzed later to obtain the purity, missing index, and defect index of each rectangular block, and then the defect value of the barcode can be obtained.

[0062] In one embodiment, the rectangular blocks are modules.

[0063] Figure 2 Schematic diagram schematically showing an EAN-13 barcode according to an embodiment of the present invention. Figure 2 As shown, this embodiment takes the EAN-13 barcode as an example for explanation. The EAN-13 barcode consists of 95 modules, except for the blank area on the left and the blank area on the right, and each module (strip) is of equal width. Therefore, for the grayscale image of the barcode, the barcode can be divided into 95 parts by 94 equal points of the horizontal length of the barcode, and each part corresponds to one module.

[0064] It should be noted that, in order to facilitate the processing of the barcode, the barcode can be divided into 95 modules, and each module is subsequently analyzed and processed. In order to facilitate understanding and explanation, the subsequent analysis and processing are all based on the modules of the barcode.

[0065] In another embodiment: Since the result of semantic segmentation may have certain errors, it may not be possible to directly obtain a more accurate barcode area through semantic segmentation. Therefore, the left edge of the leftmost module of the barcode in the image can be determined, and the right edge of the rightmost module of the barcode in the image can be determined. The area between the left edge and the right edge is taken as the overall area of ​​the barcode, and then the image of the barcode is obtained, which is grayed to obtain a grayscale image of the barcode.

[0066] In step S3, any rectangular block is taken as a target block, and the purity of the target block is calculated.

[0067] Specific:

[0068] Take the rectangular block as an example to analyze the module. Analyze any module: the module is called the target block. The target blocks described later are all modules.

[0069] Under normal circumstances, the grayscale values ​​of pixels in the target block are close to 0 or close to 255, that is, the target block is "pure white" or "pure black".

[0070] Each module of the barcode may have defects, such as module interruption (i.e., the grayscale value of pixels in a part of the module is significantly different from that in adjacent areas), module blurring, unevenness (i.e., the grayscale value difference between pixels in the module is significantly different), etc.

[0071] It can be understood that when there are defects in the target block, there are certain differences between the pixel grayscale value and image gradient in the target block and the normal module.

[0072] From the above analysis, we can know that the larger the sum of the gradient amplitudes of all non-edge pixels in the target block, the greater the possibility that the grayscale difference between the pixels in the target block is, and thus the greater the possibility that the target block has defects; conversely, the smaller the possibility that the target block has defects.

[0073] Among them, the method for obtaining pixel gradient is a prior art, and the method for determining edge pixel is also a prior art. It should be noted that, because the gradient amplitude of the pixel points at the edge of the target block may also be very large under normal circumstances, in order to improve the accuracy of the obtained purity, the gradient amplitude of the pixel points at the edge of the target block is not involved in the calculation of purity.

[0074] The larger it is, where I is the grayscale mean of the target block, it means that there are more pixels in the target block with grayscale values ​​close to 0, or close to 255, which means that the possibility that the target block has defects is smaller; conversely, the possibility is greater.

[0075] Preferably, in one embodiment, the process of obtaining the purity of the target block includes:

[0076] Purity of target block The expression is:

[0077] ,in, is the sum of the grayscale values ​​of all pixels in the target block, N is the total number of all pixels in the target block, e is a natural constant, and T is the normalized gradient of the target block; wherein, the sum of the gradient amplitudes of all non-edge pixels in the target block is positively normalized to obtain the normalized gradient of the target block; 128 in the expression can be replaced by other values, for example, it can be replaced by 127.5.

[0078] in, The closer it is to 1, that is The larger it is, the purer the target block is and the less likely it is that the target block has defects. The smaller it is, the more likely it is that the target block contains both pixels with larger grayscale values ​​and pixels with smaller grayscale values, and the target block is less "pure". .

[0079] The larger T is, The smaller it is, the greater the grayscale difference between the pixels in the target block, which means that the target block is less "pure" and the possibility that the target block has defects is greater; conversely, it means that the target block is more "pure".

[0080] Traverse all remaining modules and get the purity of each remaining module.

[0081] Other expressions of purity can be obtained by connecting the context and based on the correlation between purity and the gradient amplitude and pixel grayscale value corresponding to the target block.

[0082] Preferably, in one embodiment, the normalized gradient T of the target block can be obtained by a positively correlated maximum and minimum normalized function. Specifically, the expression of the normalized gradient is:

[0083] , where t is the target gradient of the target block, and the target gradient is the sum of the gradient amplitudes of all non-edge pixels in the corresponding module. The maximum target gradient for the modules in the barcode, Minimum target gradient for the modules in the barcode.

[0084] The normalization function in this article can be selected from other conventional normalization functions in the prior art.

[0085] In step S4, the missing index of the target block is calculated based on the purity of the target block and the grayscale distribution of the pixels in the target block.

[0086] When some modules of the barcode are not fully printed to a certain extent, the barcode is defective. It should be noted that at this time, the barcode may be successfully scanned, but as the printer continues to run, the incomplete printing problem corresponding to the barcode will continue to worsen, which will reduce the probability of the barcode being successfully scanned. Therefore, it is necessary to calculate the missing index of each module of the barcode based on the distribution of the grayscale value of the pixel points in each module. The missing index reflects the degree of printing missing of the corresponding module.

[0087] Specifically, in one embodiment, a two-dimensional rectangular coordinate system is established with the line connecting the lower left corner and the lower right corner of the target block as the horizontal axis and the line connecting the lower left corner and the upper left corner of the target block as the vertical axis (the vertical axis of the coordinate system is parallel to an edge of the target block, and one corner of the target block coincides with the origin of the coordinate system), thereby obtaining the first bar graph and the second bar graph of the target block (for ease of understanding, the first bar graph may be referred to as a horizontal bar graph, and the second bar graph may be referred to as a vertical bar graph), wherein the first bar height of the first bar graph is the sum of the grayscale values ​​of all pixels with the same horizontal coordinate, for example, for any first bar height, the sum of the grayscale values ​​of all corresponding pixels with the same horizontal coordinate is taken as the bar height. In other words, in the coordinate system, all pixels in the target block are projected onto the horizontal axis along the vertical axis direction, and the sum of the grayscales of the pixels at the same horizontal coordinate (same position) is calculated, thereby obtaining the heights of each bar of the first bar graph. The categories of the first bar graph are the horizontal coordinates of the pixels with the same horizontal coordinates. In other words, the order of the horizontal coordinates corresponding to the first bar heights is the same as the order of the horizontal coordinates of the corresponding pixels with the same horizontal coordinates.

[0088] For example, for all pixels with a horizontal coordinate of 6, the sum of the grayscale of all pixels is calculated, and the sum is used as the corresponding first bar height, and the category or order of the first bar height is 6; for all pixels with a horizontal coordinate of 5, the corresponding first bar height and category can also be obtained.

[0089] Similarly, the height of each second bar of the second bar graph can be obtained. The second bar height of the second bar graph is the sum of the grayscale values ​​of all pixels with the same ordinate, and the category of the second bar height is the ordinate of the pixel with the same ordinate. Specifically, in the second bar graph, all pixels in the target block are projected along the horizontal axis to the vertical axis, and the sum of the grayscales of the pixels at the same ordinate (same position) is calculated to obtain the height of each bar of the second bar graph.

[0090] It should be noted that the first bar height is the height of the bar in the first bar graph, and the second bar height is the height of the bar in the second bar graph; the bar height can be called frequency.

[0091] In one embodiment, the envelopes of the first bar graph and the second bar graph of the target block may be obtained based on a moving average method.

[0092] In another embodiment, the bar height may be a grayscale average. For example, the bar height of the second bar graph is an average of the grayscale values ​​of all pixels having the same vertical coordinate.

[0093] Preferably, in one embodiment, the process of obtaining the missing indicator of the target block includes: The expression is: , where is the first index of the target block, is the second index of the target block, e is a natural constant, is the purity of the target block; wherein the acquisition process of the first index and the second index is:

[0094] Calculate the slope A1 of the envelope corresponding to the height of each bar of the first bar graph of the target block, normalize the variance of all slopes A1 by positive correlation, and obtain the first index Similarly, calculate the slope A2 of the envelope corresponding to the height of each bar of the second bar graph of the target block, normalize the variance of all slopes A2 by positive correlation, and obtain the second index . The bar height corresponds to the line slope of the envelope.

[0095] Further explanation is as follows:

[0096] The missing index reflects the degree of printing missing of the module.

[0097] The larger, or The larger it is, the greater the discreteness of the slope of the envelope line corresponding to the bar height is, the greater the possibility that the corresponding envelope line fluctuates more, and the greater the possibility that the corresponding envelope line fluctuates more frequently. Therefore, it is more likely that there are more interrupted areas (i.e., areas with discontinuous grayscale) in the target block, and the greater the possibility that the target block has a greater degree of printing defects, which means the target block is more likely to have defects. Conversely, the smaller the degree of printing defects in the target block is, the less likely the target block is to have defects.

[0098] Understandably, The larger, or The larger it is, the greater the possibility that the grayscale difference between pixels in the target block is.

[0099] The larger the value is, the more completely the target block is printed, and the more likely it is that the target block has a smaller printing defect; conversely, the more likely it is that the target block has a larger printing defect.

[0100] Traverse all remaining modules and get the missing index of each remaining module.

[0101] It should be noted that the standard deviation can also indicate the degree of dispersion.

[0102] Other expressions for the missing indicator can be obtained by taking into account the context and based on the correlation between the missing indicator and the degree of dispersion of purity and bar height.

[0103] In one embodiment, the dispersion degree of the slope of the envelope line is the standard deviation of the slope of the envelope line.

[0104] Preferably, in one embodiment, the first index and the second index corresponding to the target block can be obtained by a positively correlated maximum and minimum normalized function. Specifically:

[0105] The expression of the first indicator is:

[0106] ,in, For the variance of all slopes A1, compare the variance of the slopes of the envelopes of the first bar graphs of all modules and take the largest variance as , taking the minimum variance as .

[0107] The expression of the second indicator is:

[0108] ,in, For the variance of all slopes A2, compare the variance of the slopes of the envelopes of the second bar graphs of all modules and take the largest variance as , taking the minimum variance as .

[0109] In step S5 , based on the purity and the defect index of the target block, the defect index of the target block is calculated.

[0110] From the above analysis, we can know that: the greater the purity of the target block, the greater the possibility that the target block has a smaller defect degree; conversely, the greater the possibility that the target block has a larger defect degree. The greater the missing index of the target block, the greater the possibility that the target block has a larger defect degree; conversely, the greater the possibility that the target block has a smaller defect degree.

[0111] In one embodiment, the process of obtaining the defect indicator of any module includes:

[0112] The expression of the module defect index is:

[0113] ;

[0114] in, is the defect index of the i-th module in the grayscale image, is the missing index of the ith module, e is a natural constant, is the purity of the i-th module.

[0115] The defect index indicates the degree of defect.

[0116] In another embodiment, the defect index of the target block is also positively correlated with the missing index of the adjacent module of the target block, and the defect index of the target block is also negatively correlated with the purity of the adjacent module of the target block. The reason is that due to the special structure of the barcode printer, when a module of the barcode has a defect, the adjacent module of the module is more likely to have a defect.

[0117] Preferably, in one embodiment, the process of obtaining the defect index of any module includes:

[0118] The expression of the module defect index is:

[0119] ;

[0120] , ;in, is the defect index of the i-th module in the grayscale image, is the missing index of the i-th module, For the The missing indicators of the modules, For the The missing indicators of the modules, is the missing weight, e is a natural constant, is the purity of the ith module, For the The purity of each module, For the The purity of each module, is the purity weight, n is the total number of modules in the grayscale image, and the total number is 95.

[0121] Implementers can set up according to specific scenarios and . It can be an experience value of 0.1. Can be an experience value of 0.1.

[0122] The explanation is as follows: Due to ,when When it is equal to 1 or 95, Each module has only one adjacent module. In order to calculate the defect index, let , .

[0123] The range is [0,2]. The role is to make The value range is [0,1].

[0124] The specific description is as follows: Due to the particularity of the barcode printer structure, when the target block has defects such as missing prints, the modules adjacent to the target block are more likely to have defects such as missing prints. If the purity of the adjacent modules of the target block is greater, it means that the probability that the degree of defects of the adjacent modules of the target block is smaller is greater, and the probability that the degree of defects of the target block is smaller is greater; conversely, the probability that the degree of defects of the target block is greater is greater. If the missing index of the adjacent modules of the target block is greater, it means that the probability that the degree of missing prints of the adjacent modules of the target block is greater is greater, and thus the probability that the degree of defects of the adjacent modules of the target block is greater is greater, and the probability that the degree of defects of the target block is greater is greater; conversely, the probability that the degree of defects of the target block is smaller is greater.

[0125] The larger the value is, the more likely it is that the defect level of the i-th module is greater; conversely, the more likely it is that the defect level of the i-th module is smaller. The larger the value is, the more likely it is that the defect degree of the i-th module is smaller; conversely, the more likely it is that the defect degree of the i-th module is larger.

[0126] Traverse all remaining modules and obtain the defect index of each remaining module.

[0127] Other expressions of the defect index can be obtained by connecting the context and based on the relationship between the defect index and the missing index and purity.

[0128] In step S6, the defect value of the barcode is calculated based on the defect index of the rectangular block, where the rectangular block is a module.

[0129] The defect index indicates the degree of defect, for example, the degree of defect is positively correlated with the defect index.

[0130] It can be understood that the defect level of the corresponding barcode, ie, the defect value, can be calculated through the defect indicators of all modules.

[0131] Preferably, in one embodiment, the defect value of the barcode is calculated based on the defect index of the module, including:

[0132] Defect value The expression is:

[0133] , , where n is the total number of modules in the grayscale image, is the defect index of the i-th module in the grayscale image, is the weight of the defect index of the i-th module.

[0134] The role of weight is to pay more attention to the defects of some important modules.

[0135] More specifically, in the EAN-13 barcode protocol and standard, the barcode is composed of 95 white modules and black modules of equal width, with a total of 6 barcode symbols, from left to right, respectively, the start symbol (3), the left data symbol (42), the middle separator (5), the right data symbol (35), the check symbol (7), and the end symbol (3). The number of modules that make up the corresponding barcode symbol is in brackets. Since the left data symbol and the right data symbol are the main data of the barcode, when calculating the barcode defect index, the weight of the defect index of the module corresponding to the left data symbol should be greater, and the weight of the defect index of the right data symbol should be greater. Specifically, the defect value of the barcode The calculation method is as follows:

[0136] ;

[0137] ;

[0138] in, is the weight of the defect index of the i-th module, is the defect index of the i-th module.

[0139] The larger it is, the more likely it is that the barcode is more defective.

[0140] In step S7, in response to the defect value being greater than a defect threshold, it is considered that the barcode has a defect.

[0141] In one embodiment, in response to the defect value of the bar code If it is greater than the first defect threshold, it is considered that the barcode has defects, or in other words, the degree of defects in the barcode has reached a certain level. At this time, an "early warning" should be issued, or in other words, it is considered that the degree of defects in the barcode has reached the standard that requires printer debugging, and the equipment status of the printer needs to be checked; otherwise, it is considered that the degree of defects in the barcode is small, the degree of defects is within the allowable range, and the degree of defects can be ignored.

[0142] The implementer may set the first defect threshold according to the specific scenario, and the first defect threshold may take an empirical value of 0.1.

[0143] In another embodiment, the maximum value of the defect index of the module is used as the defect value M1 of the barcode. In response to the defect value M1 being greater than the second defect threshold, it is considered that the barcode has a defect.

[0144] Among them, the implementer can set the second defect threshold according to the specific scenario, and the second defect threshold can take the empirical value of 0.9.

[0145] In other embodiments, the defect indicators of all modules in the grayscale image are sorted from large to small, and the average of the preset number of defect indicators is calculated, which is recorded as the defect value M2 of the barcode, where the larger the defect indicator, the higher the defect indicator. In response to the defect value M2 being greater than the second defect threshold, it is considered that the barcode has a defect. The reason is that when a barcode has a defect, usually, multiple modules in the barcode have defects.

[0146] The preset number may be an empirical value of 3. The implementer may set the preset number according to the specific implementation scenario.

[0147] For example, the average of the first two consecutive defect indicators is calculated, that is, the average of the largest and second largest defect indicators is calculated.

[0148] Summary: The present invention determines the defect index (defect degree) of each module by analyzing the grayscale and its distribution of each module and the gradient amplitude of the non-edge pixels in the module, and then obtains the defect value (defect degree) of the barcode. If the defect value is greater than the defect threshold, the barcode is considered to have defects, and the accuracy of defect detection on the barcode is relatively high. It should be noted that for a barcode defect detection method based on image segmentation and recognition disclosed in the patent application document with application publication number CN116739017A, if the number of sub-regions for segmenting the barcode is small, the accuracy of defect detection on the barcode will be low. The reason is that if the defective area of ​​the barcode is small, the sub-region can still be successfully decoded.

[0149] By setting a suitable defect threshold, the present invention can detect the defects of the barcode when the degree of the defect of the barcode is relatively small, and then analyze the cause of the defect. If the defect is caused by a printer failure, the printer can be repaired in time to eliminate the defect of the printed barcode.

[0150] In the description of this specification, "plurality" or "several" means at least two, such as two, three or more, etc., unless otherwise clearly and specifically defined.

[0151] Although this specification has shown and described a number of embodiments of the present invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Those skilled in the art will conceive of many modifications, changes and alternatives without departing from the ideas and spirit of the present invention. It should be understood that in the practice of the present invention, various alternatives to the embodiments of the present invention described herein may be employed.

Claims

1. A method for detecting barcode defects on milk powder food packaging based on image processing, characterized in that: include: Get a rectangular block of the grayscale image of the barcode; Take any rectangular block as the target block and calculate the purity of the target block , , where I is the grayscale mean of the target block, e is a natural constant, the cumulative sum of the gradient amplitudes of the non-edge pixels in the target block is called the gradient feature, and the gradient feature is normalized to obtain the value T; A coordinate system is established with the long side of the target block as the vertical axis to determine the first and second bar graphs. The height of the first bar of the first bar graph is the grayscale sum of the pixels with the same horizontal coordinate, and the height of the second bar of the second bar graph is the grayscale sum of the pixels with the same vertical coordinate. The first discrete degree of the first bar height is positively correlated and normalized to obtain the first index. , the second discrete degree corresponding to the second bar height is normalized by positive correlation to obtain the second index ; Calculate the missing index of the target block , , where e is a natural constant; Calculating a defect index of the target block, wherein the defect index is positively correlated with the missing index, and the defect index is negatively correlated with the purity; Calculating a defect value of the barcode based on the defect index of the rectangular block; in response to the defect value being greater than a defect threshold, considering that the barcode has a defect; The expression of defect index is: ; in, is the defect index of the i-th rectangular block in the grayscale image, is the missing index of the ith rectangular block, e is a natural constant, is the purity of the i-th rectangular block; Based on the defect index of the rectangular block, the defect value of the barcode is calculated; in response to the defect value being greater than the defect threshold, it is considered that the barcode has a defect, including: the defect value The expression is: , , where n is the total number of rectangular blocks in the grayscale image, is the defect index of the i-th rectangular block in the grayscale image, is the weight of the defect index of the i-th rectangular block; In response to the defect value being greater than a first defect threshold, the barcode is deemed defective.

2. The method for detecting barcode defects on milk powder food packaging based on image processing according to claim 1, characterized in that: Calculating a defect value of the barcode based on the defect index of the rectangular block, and considering that the barcode has a defect in response to the defect value being greater than a defect threshold, including: The maximum value of the defect index of the rectangular block is taken as the defect value M1 of the barcode; In response to the defect value M1 being greater than a second defect threshold, it is considered that the barcode has a defect.

3. The method for detecting barcode defects on milk powder food packaging based on image processing according to claim 1, characterized in that: The first discrete degree is the variance of the slope A1, wherein the slope A1 is the slope of the first envelope corresponding to the first bar height, and the first envelope is the envelope of the first bar graph; The second discrete degree is the variance of the slope A2, wherein the slope A2 is the slope of the second envelope corresponding to the second bar height, and the second envelope is the envelope of the second bar graph.

4. The method for detecting barcode defects on milk powder food packaging based on image processing according to claim 1, characterized in that: The barcode comprises an EAN-13 barcode.