Bar code recognition method and apparatus
Patent Information
- Application Number
- CN202511325546.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-17
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2045-09-17
AI Technical Summary
[0002]流水线场景下,某些生产工艺可能会造成二维码的大面积缺失或脏污,当缺失面积大于二维码容错率时会解码失败,导致产线解码率偏低
[0016] The aforementioned barcode recognition method, apparatus, computer equipment, computer-readable storage medium, and computer program product acquire a template database, determine the target template with the highest matching degree to the barcode image from the template database, and use the image information of the target template to repair the barcode image. Using the image information of the target template with the highest matching degree to repair the barcode image helps to fill in unclear parts of the barcode image, accurately restore missing barcodes, reduce the recognition difficulty of the decoder, and thus improve the decoding rate.
Smart Images

Figure CN121328588B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of barcode recognition technology, and in particular to a barcode recognition method and apparatus. Background Technology
[0002] In assembly line scenarios, certain production processes may cause large areas of missing or dirty QR codes. When the missing area is greater than the QR code's fault tolerance rate, decoding will fail, resulting in a low decoding rate on the production line. Summary of the Invention
[0003] Therefore, it is necessary to provide a barcode recognition method, device, computer equipment, computer-readable storage medium, and computer program product that can improve the decoding rate in response to the above-mentioned technical problems.
[0004] Firstly, this application provides a barcode recognition method, including:
[0005] Obtain the template database; each template in the template database includes basic information and image information; image information refers to the image area corresponding to the encoding overlap rate of all barcode images with the same basic information that is greater than the preset overlap rate;
[0006] If barcode image recognition fails, determine the target template for the barcode image; the target template is one of multiple templates in the template database.
[0007] The barcode image is repaired using the image information of the target template to obtain the repaired barcode image, and the repaired barcode image is then recognized.
[0008] Secondly, this application provides a barcode recognition device, comprising:
[0009] The template acquisition module is used to acquire the template database. Each template in the template database includes basic information and image information. The image information refers to the image area corresponding to the encoding overlap rate of all barcode images with the same basic information that is greater than the preset overlap rate.
[0010] The template confirmation module is used to determine the target template for the barcode image when barcode image recognition fails; the target template is one of multiple templates in the template database.
[0011] The image restoration module uses the image information of the target template to restore the barcode image, resulting in a restored barcode image.
[0012] The barcode recognition module is used to recognize barcode images.
[0013] Thirdly, this application provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps in the method described above.
[0014] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above-described method.
[0015] Fifthly, this application provides a computer program product comprising a computer program that, when executed by a processor, implements the steps of the method described above.
[0016] The aforementioned barcode recognition method, apparatus, computer equipment, computer-readable storage medium, and computer program product acquire a template database, determine the target template with the highest matching degree to the barcode image from the template database, and use the image information of the target template to repair the barcode image. Using the image information of the target template with the highest matching degree to repair the barcode image helps to fill in unclear parts of the barcode image, accurately restore missing barcodes, reduce the recognition difficulty of the decoder, and thus improve the decoding rate. Attached Figure Description
[0017] Figure 1 A flowchart illustrating a barcode recognition method provided in an embodiment of this application;
[0018] Figure 2 A flowchart illustrating another barcode recognition method provided in this application embodiment;
[0019] Figure 3 A flowchart illustrating another barcode recognition method provided in this application embodiment;
[0020] Figure 4 A flowchart illustrating another barcode recognition method provided in this application embodiment;
[0021] Figure 5 A flowchart illustrating another barcode recognition method provided in this application embodiment;
[0022] Figure 6 A structural block diagram of a barcode recognition device provided in an embodiment of this application;
[0023] Figure 7 A structural block diagram of another barcode recognition device provided in the embodiments of this application;
[0024] Figure 8 An internal structural diagram of a computer device provided in an embodiment of this application;
[0025] Figure 9 An internal structural diagram of another computer device provided in an embodiment of this application;
[0026] Figure 10 This is an internal structural diagram of a computer-readable storage medium provided in an embodiment of this application. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0028] The barcode recognition method provided in this application can be applied to barcodes on assembly lines. Since each run of the assembly line produces the same type of product, to ensure product consistency, the barcode printing process follows a fixed procedure, such as white background with black barcodes, and consistent barcode width and density. Product coding generally follows certain rules, such as including manufacturer identification code, serial number, batch number, and production date. If product batches are similar, the barcode content used for information traceability will also be similar. Therefore, missing or dirty barcodes on the assembly line can be repaired using similar barcodes.
[0029] like Figure 1 As shown in the figure, this application provides a barcode recognition method, which includes the following steps:
[0030] S102: Obtain the template database. Each template in the template database includes basic information and image information. Image information refers to the image areas corresponding to the encoding overlap rate of all barcode images with the same basic information that is greater than a preset overlap rate.
[0031] The image information is a binarized image.
[0032] Templates can be obtained from clear and complete barcode images that have already been identified. For example, a set of clear and complete barcode images with identical basic information can be obtained. This set of barcode images is used to generate the template. The image regions corresponding to the portions of the barcode image set with an encoding overlap rate greater than a preset overlap rate are used as the image information of the template. The higher the preset overlap rate, the more barcode images containing image information are included, and the greater the likelihood that the barcode image to be identified contains image information. Simultaneously, the area of the barcode image contained within the image information may be smaller. The specific preset overlap rate is limited according to requirements and will not be elaborated here.
[0033] Barcodes with identical basic information on an assembly line may belong to the same or similar batches of products. These barcodes share most of the same encoding, resulting in identical portions of their corresponding images. By capturing the areas of barcodes from the same or similar batches with the highest overlap rate, it's helpful to recover parts of the image from dirty or missing barcodes, thus making the barcode image more complete.
[0034] S104: If barcode image recognition fails, determine the target template with the highest matching degree to the barcode image. The target template is one of multiple templates in the template database.
[0035] To facilitate the distinction between ordinary barcode images and barcode images that failed to be recognized, barcode images that failed to be recognized will be referred to as barcode images to be recognized.
[0036] Generally, barcode recognition has a certain error tolerance rate. When the barcode is partially contaminated, damaged, blurred, or obscured beyond this tolerance, recognition usually fails. In other words, when the native error correction mechanism cannot recover the missing information, recognition typically fails. In such cases, other information or methods are needed to recover the barcode.
[0037] To repair a barcode image to be recognized, it is necessary to identify the template with the highest matching degree from the templates generated by previously recognized barcode images. This means identifying a template generated from a barcode image that has the same or similar basic information as the barcode image to be recognized. Finding the template that is closest to the barcode image to be recognized provides a foundation for maximizing the recovery of the barcode image.
[0038] S106: Use the image information of the target template to repair the barcode image to be recognized, obtain the repaired barcode image to be recognized, and recognize the repaired barcode image to be recognized.
[0039] Since product codes generally include manufacturer identification codes, serial numbers, batch numbers, and production dates, and similar products often share almost identical manufacturer identification codes, serial numbers, and batch numbers (meaning their product codes are largely the same), it can be concluded that the image information of similar products is also largely identical. This suggests that the image information of the template likely constitutes a large proportion of the entire barcode image information. Therefore, it can be determined that the target template's image information may contain most of the image information of the barcode to be recognized. Using the target template's image information to repair the barcode image can restore it as accurately as possible, making the image more complete and clearer, thereby reducing the difficulty of scanning and improving the decoding rate.
[0040] In some embodiments, such as Figure 2 As shown, determining the target template with the highest matching degree to the barcode image to be recognized includes the following steps:
[0041] S1042: Obtain basic information about the barcode image to be recognized.
[0042] S1044: Match the basic information of the barcode image to be recognized with the basic information of the templates in the template database, determine the successfully matched templates as primary matching templates, and form a primary matching template set.
[0043] A successful basic information match means that the basic information of the barcode image to be recognized is the same as or similar to the basic information of the template. Same basic information means that the product corresponding to the barcode image to be recognized and the product corresponding to the template are from the same or similar batch; similar basic information means that the product corresponding to the barcode image to be recognized and the product corresponding to the template may be from similar batches. Images corresponding to product codes from similar batches also share some identical parts.
[0044] By filtering templates corresponding to products from the same or similar batches, templates corresponding to products from similar batches can be determined when no templates for the same batch are available, thereby ensuring that the image to be identified is repaired and recognized as much as possible.
[0045] S1046: Determine the primary matching template with the highest similarity to the barcode image to be recognized from the primary matching template set as the target template.
[0046] By initially screening primary matching templates, templates that clearly do not meet the conditions can be quickly eliminated, significantly reducing the range of subsequent similarity calculations and improving the efficiency of target template selection.
[0047] In another embodiment, the method further includes: if the similarity between the primary matching template and the barcode image to be identified is lower than a similarity threshold, then a matching failure is output. If the matching fails, it indicates that the barcode image to be identified cannot be restored and traced, and NG (No Good) can be output to indicate that the product corresponding to the barcode image to be identified is an untraceable defective product.
[0048] The similarity threshold can be set within the range of 0.4-0.6. A higher similarity threshold results in a higher degree of overlap between the template and the barcode image to be recognized, leading to higher accuracy in barcode image recovery. A lower similarity threshold allows for a wider selection of templates. The specific setting depends on your needs.
[0049] In some embodiments, the basic information includes:
[0050] The basic information can include one or more of the following: barcode polarity, barcode density, barcode length, and barcode width. Specifically, it can include any one of these parameters. Alternatively, it can include any three of these parameters, such as barcode polarity, barcode length, and barcode density, or a combination thereof. The specific settings depend on the requirements and are not limited here.
[0051] Barcode polarity typically refers to the contrast between the bars and spaces in a barcode image. In normal polarity, the areas with lower reflectivity are called bars, and the areas with higher reflectivity are called spaces. In reverse polarity, bars are the areas with higher reflectivity, and spaces are the areas with lower reflectivity. Lower reflectivity is usually associated with darker colors, such as black, while higher reflectivity is usually associated with lighter colors, such as white. For example, barcode polarity can include black on a white background and white on a black background; in normal polarity, it's white on a black background, and in reverse polarity, it's black on a white background.
[0052] For one-dimensional barcodes, barcode density refers to the number of barcode modules per unit length. For two-dimensional barcodes, barcode density refers to the number of barcode modules per row multiplied by the number of barcode modules per column. For example, the density of version 1 of the matrix-style two-dimensional barcode (Quick Response Code, QR) is 21*21, meaning there are 21 barcode modules per row and per column. The density of version 40 of the QR code is 177*177, meaning there are 177 barcode modules per row and per column.
[0053] The unit for barcode length and width can be pixels, which are used to measure the length and width of the barcode.
[0054] In some embodiments, when the basic information includes barcode polarity or barcode density, determining a successfully matched template as a primary matching template includes:
[0055] The templates whose barcode polarity or density corresponds to the barcode polarity or density of the barcode image to be identified are the primary matching templates.
[0056] In some embodiments, when the basic information includes barcode polarity and barcode density, determining a successfully matched template as a primary matching template includes: determining a template whose barcode polarity and barcode density correspond to the barcode polarity and barcode image of the barcode image to be identified as a primary matching template.
[0057] In some embodiments, when the basic information includes barcode length or barcode width, determining a successfully matched template as a primary matching template includes: determining a template whose barcode length is within a preset length range and whose barcode width is within a preset width range and whose barcode width is within a preset width range.
[0058] In some embodiments, when the basic information includes barcode length and barcode width, determining a successfully matched template as a primary matching template includes: determining a template whose barcode length is within a preset length range and whose barcode width is within a preset range.
[0059] In some embodiments, when the basic information includes barcode polarity, barcode length, and barcode width, determining a successfully matched template as a primary matching template includes: determining a template whose barcode polarity is the same as that of the barcode image to be identified, whose barcode length is within a preset length range and whose barcode width is within a preset range.
[0060] In some embodiments, when the basic information includes barcode polarity, barcode density, barcode length, and barcode width, determining a successfully matched template as a primary matching template includes: determining that a template whose barcode polarity is the same as the barcode polarity of the barcode image to be identified, whose barcode density is the same as the barcode density of the barcode image to be identified, whose barcode length is within a preset length range, and whose barcode width is within a preset range, is a primary matching template.
[0061] Basic information includes barcode density, barcode length, and barcode width; basic information includes barcode polarity, barcode density, and barcode length; and basic information includes barcode polarity, barcode density, and barcode width, and so on. These will not be elaborated here.
[0062] A larger preset width and length setting provides a wider range of templates to choose from, but may also increase the margin of error. Conversely, a smaller preset width and length setting results in a smaller range of templates to choose from, but with higher accuracy. Therefore, the preset width and length can be set according to your needs.
[0063] Barcodes are encoded using the width ratio of bars and spaces, which is fundamental to barcode recognition. Barcode polarity and density are both related to bars and spaces, determining their recognition logic. When selecting a template to repair a barcode image, the barcode polarity must be identical; otherwise, bars will be misinterpreted as empty spaces, the encoding logic will be completely reversed, and decoding will fail. Similarly, consistent barcode density is essential; otherwise, encoding and decoding errors will occur.
[0064] The length and width of a barcode only affect the adaptation range during recognition and do not change the core ratio of the internal bars and spaces. Therefore, within a certain error range, they have little impact on the accuracy of recognition.
[0065] By restricting the barcode polarity and density to be the same, and the barcode width and length to within a certain error range, it is possible to filter as many templates with the same recognition logic as possible, thus expanding the range of templates that can be selected.
[0066] In some embodiments, such as Figure 3 As shown, the template with the highest similarity to the barcode image to be recognized in the primary matching templates is determined as the target template, including:
[0067] S10462: Binarize the barcode image.
[0068] S10464: Calculate the similarity between the binarized barcode image and the image information of the primary matching template.
[0069] S10466: Determine the primary matching template with the highest similarity as the target template.
[0070] Because the barcode image to be identified is dirty or incomplete, and the target template image is a common image extracted from multiple barcode images, it is not a complete barcode image either. Therefore, when calculating similarity, only the pixel values of the barcode images to be identified and the target template image information are considered. Furthermore, since the target template only contains common images and not non-common images, the amount of data that needs to be calculated for similarity can be reduced to some extent, thus improving the efficiency of matching.
[0071] Different similarity calculation methods can be used for different barcodes. For example, for one-dimensional barcodes, the width sequences of two barcode images can be normalized, and the Pearson correlation coefficient between the sequences can be calculated. The closer the calculated Pearson correlation coefficient is to 1, the higher the similarity. For two-dimensional barcodes, the binarized image can be converted into a one-dimensional vector, and the cosine similarity value between the two one-dimensional vectors can be calculated. The closer the cosine similarity value is to 1, the higher the similarity. Other existing similarity calculation methods can also be used; no limitation is placed on the methods used here.
[0072] The template with the highest similarity has a higher consistency in image structure with the barcode to be identified, which can provide a foundation for more accurate subsequent repair of the barcode image.
[0073] In some embodiments, the image information of the target template is used to repair the barcode image to be recognized, resulting in a repaired barcode image to be recognized, including:
[0074] The image information of the target template is used to determine whether the code dots in the corresponding area of the barcode image to be recognized are bars or spaces, thus obtaining the repaired barcode image.
[0075] A barcode dot is the smallest unit of information in barcode encoding logic. It has only two states: bar and space, and is composed of pixels. When the size of a barcode dot is extremely small, one pixel constitutes one barcode dot. Generally, a barcode dot is composed of multiple pixels; for example, a barcode dot might be a 3×3 pixel black block. In the embodiments of this application, barcode dots are composed of multiple pixels, and the specific size of the barcode dot is not limited.
[0076] By using the image information of the target template to determine whether the code points in the corresponding area of the barcode image to be recognized are bars or empty, it is possible to correct code points that are misjudged due to dirt in the barcode image to be recognized, and to fill in missing code points, thereby improving the decoding rate and the accuracy of recognition.
[0077] In some embodiments, such as Figure 4 As shown, determining whether pixels in a barcode image corresponding to image information are bars or empty areas includes:
[0078] S1062: Determine the absolute value of the first difference between the average pixel value of all pixels within the code point of the binarized barcode image and the pixel value of the corresponding code point in the image information of the target template.
[0079] In an 8-bit grayscale image, each pixel is represented by 8 binary bits, and the pixel value ranges from 0 to 255. For images with higher bit counts, the range of pixel values is even larger. In this embodiment, a common 8-bit grayscale image is used as an example. In an 8-bit grayscale image, the binarized pixel value is either 255 or 0. In a black background with white code, the pixel value corresponding to a bar is 0, and the pixel value corresponding to a space is 255. In a white background with black code, the pixel value corresponding to a bar is 255, and the pixel value corresponding to a space is 0.
[0080] The target template image information is a binarized image with pixel values of 0 and 255. The average pixel value of all pixels within the code point of the binarized barcode image to be recognized is subtracted from the corresponding pixel value of the code point in the target template image information to obtain the first difference value. The absolute value of the first difference value is at most 255 and at least 0. An absolute value of 255 indicates that the polarity of the code point in the target template image information and the barcode image to be recognized is completely opposite; one is a bar, and the other is empty. If the absolute value of the first difference value is 0, it indicates that the polarity of the code point in the target template image information and the barcode image to be recognized is exactly the same. If the absolute value of the first difference value is between 0 and 255, it means that the code point may be a bar or an empty bar.
[0081] S1064: If the absolute value of the first difference is less than the first preset difference, determine that the barcode image corresponds to a bar or a space.
[0082] If the absolute value of the first difference is greater than or equal to the first preset difference, the barcode point corresponding to the barcode is determined to be an uncertain point.
[0083] To reduce computational complexity and accurately determine whether a code point is a bar or an empty space, the absolute value of a first difference is compared with a first preset difference. If it is less than the first preset difference, it indicates that the difference between the pixel value of the code point in the target template and the pixel value in the barcode image to be recognized is small. This code point can be determined based on the binarization result of the barcode image to be recognized. If the binarization result corresponds to a bar, then the code point is determined to be a bar. If the binarization result corresponds to an empty space, then the code point is determined to be empty. If it is greater than or equal to the first preset difference, it indicates that the difference between the pixel value of the code point in the target template and the pixel value in the barcode image to be recognized is large. This code point is an uncertain point and requires further judgment.
[0084] The first preset difference can range from 20 to 50. The larger the first preset difference, the higher the efficiency of determining whether the code point is a bar or a space, but the lower the accuracy. The specific value of the first preset difference is determined according to the requirements.
[0085] S1066: For uncertain points, set multiple binarization thresholds to perform binarization processing on the barcode image, and determine whether the uncertain point is a bar or a blank based on the binarization processing result.
[0086] First, determine whether the more accurate code point is a bar or a space, and then make a judgment on the uncertain points. This can simplify the judgment process, improve judgment efficiency, and increase the accuracy of the judgment.
[0087] In some embodiments, such as Figure 5 As shown, multiple binarization thresholds are set to perform binarization processing on the barcode image to be recognized. Based on the binarization processing results, uncertain points are determined to be bars or spaces, including:
[0088] S10662: Determine n binarization thresholds.
[0089] Where n is an odd number and the n binarization thresholds are not equal. The n binarization thresholds can be set empirically, or the Otsu's method can be used to determine the (n+1) / 2th binarization threshold. Based on the (n+1) / 2th binarization threshold, extend (n-1) / 2 binarization thresholds to both sides. The step size between adjacent binarization thresholds can be equal or unequal, and the step size can be set arbitrarily, as long as the pixel values of the first and nth binarization thresholds do not exceed the pixel value range. The value of n can be in the range of 5 to 15, that is, n can be 5, 7, 9, 11, 13, 15, etc., without restriction. For example, n is 11, the 6th binarization threshold is determined to be 100 using the Otsu thresholding method, the step size between adjacent binarization thresholds is 3, and the 11 binarization thresholds are 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, and 115 respectively.
[0090] S10664: Based on n binarization thresholds, determine the n binarized pixel values of uncertain points in the barcode image to be recognized.
[0091] Since the binarization result of the barcode image to be recognized is easily affected by illumination, by setting multiple binarization thresholds, multiple binarization results can be obtained, which can reduce misjudgment caused by improper selection of a single threshold.
[0092] S10666: Determine the absolute values of the n second differences between the n binary pixel values of the uncertain point and the pixel values of the corresponding region pixels of the target template.
[0093] If the absolute value of the second difference is less than the second preset difference, the uncertain point is determined to be a bar or a blank.
[0094] The second preset difference is selected in the same range and method as the first preset difference.
[0095] In this embodiment, the pixel value ranges from 0 to 255. Therefore, the binarized pixel value corresponds to 0 or 255.
[0096] If the absolute value of the second difference is less than the second preset difference, the result of the uncertain point is still uncertain. S10668: Obtain the number of times the uncertain point is a bar and the number of times it is empty. If the number of bars is greater than the number of empty points, determine that the uncertain point is a bar. If the number of empty points is greater than the number of bars, determine that the uncertain point is empty.
[0097] If the total number of uncertain points being bars or empty is less than the number of uncertain points, it indicates that the probability of uncertainty is relatively high. You can choose to repeat steps S10662 to S10666. The newly determined binarization threshold should be different from the previous binarization threshold. Then proceed to S10668 for judgment until the result of the uncertain point can be determined.
[0098] For example, if n is 11, and one of the uncertain points is 5 times that it is a bar and 6 times that it is empty, then the uncertain point is empty.
[0099] Since n is odd, the number of binarized results is also odd, meaning the number of uncertain points that are bars and the number of uncertain points that are empty will not be equal. Furthermore, since different binarization thresholds can capture different features of the barcode, multiple results can be combined to select the most reliable barcode features, identifying the results with more occurrences as uncertain points. This improves the robustness of recognition and avoids misjudgments caused by improper selection of a single threshold.
[0100] In some embodiments, based on n binarization thresholds, determining n binary pixel values for uncertain points in the barcode image to be recognized includes:
[0101] The pixel value of the pixel within the uncertain point in the barcode image is compared with the nth binarization threshold. If it is greater than or equal to the nth binarization threshold, the binarized pixel value of the pixel within the uncertain point in the barcode image is determined to be the first binarized pixel value; if it is less than the nth binarization threshold, the binarized pixel value of the pixel within the uncertain point in the barcode image is determined to be the second binarized pixel value. The average value of the binarized pixel values of all pixels within the uncertain point is determined to be the binarized pixel value of the uncertain point. This process is repeated n times to obtain n binarized pixel values of the uncertain point.
[0102] When the pixel value is in the range of 0 to 255, and the barcode polarity is black background with white code, the first binarized pixel value is 0, and the second binarized pixel value is 255. When the barcode polarity is white background with black code, the first binarized pixel value is 255, and the second binarized pixel value is 0.
[0103] For example, n is 11, and the 11 binarization thresholds are 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, and 115. A code point consists of 2×2 pixels, with pixel values of 90, 100, 105, and 110 for the four pixels. Based on the first binarization threshold of 85, since the pixel values of all four pixels are greater than 85, their binarized pixel values are all 255, and correspondingly, the binarized pixel value of the code point is also 255. For the second binarization threshold, the judgment method is the same as for the first, and the binarized pixel value of the code point is also 255. Based on the third binarization threshold of 91, one pixel has a pixel value less than 91, while the pixel values of the other three pixels are greater than 91. Therefore, one pixel has a binarized pixel value of 0, the other three pixels have a binarized pixel value of 255, and the binarized pixel value of the code point is 191.3. The judgment process for the fourth binarization threshold 94, the fifth binarization threshold 97, and the sixth binarization threshold 100 is the same as that for the third binarized pixel value. The binarized pixel value of the code point is also 191.3. Based on the seventh binarization threshold 103, where two pixels have pixel values less than 103 and two pixels have pixel values greater than 103, the binarized pixel values of the four pixels are 0, 0, 255, and 255, respectively, and the binarized pixel value of the code point is 127.5. The remaining binarization thresholds are determined similarly, resulting in binarized pixel values of 63.8, 63.8, 0, and 0 for the code point.
[0104] By obtaining n binarization thresholds and determining n binarization results, misjudgments caused by image noise, uneven lighting, etc. can be reduced.
[0105] In some embodiments, after decoding the repaired barcode image to be identified, the method further includes: if the basic information of the repaired barcode image is the same as the basic information of the target template, using the repaired barcode image to be identified to iteratively update the image information of the target template.
[0106] Iterative updates refer to comparing the repaired barcode image to be recognized with the image information of the target template, and selecting the overlapping parts as the new image information of the target template. Through continuous iteration, it can be ensured that the image information of the template is common to barcodes of the same or similar batches of products.
[0107] In another embodiment, the barcode image further includes common encoding information. This common encoding information corresponds to the image information and is used to determine whether the barcode image has a corresponding template.
[0108] Specifically, if the basic information of subsequently identified barcode images is the same, it can be further determined whether the overlap between the barcode image's encoding and the template's common encoding reaches a preset overlap level. If the preset overlap level is reached, it is determined that the barcode image has a template, and this barcode image can be used to update the template image. If the preset overlap level is not reached, a new template can be generated. Since there is only one barcode information at this time, it is impossible to determine the image overlap rate; therefore, the image information in this case is the entire barcode image. The template image information can be updated after the next acquisition of a clear and complete barcode image with the same basic information.
[0109] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps.
[0110] Based on the same inventive concept, this application also provides a barcode recognition device. The solution provided by this device is similar to the solution described in the above method. Therefore, the specific limitations of one or more barcode recognition device embodiments provided below can be found in the limitations of the barcode recognition method above, and will not be repeated here.
[0111] like Figure 6 As shown, this application embodiment provides a barcode recognition device 600, including:
[0112] The template acquisition module 602 is used to acquire the template database; each template in the template database includes basic information and image information. The image information refers to the image area corresponding to the encoding overlap rate of all barcode images with the same basic information that is greater than a preset overlap rate.
[0113] The template confirmation module 604 is used to determine the target template with the highest matching degree to the barcode image when barcode image recognition fails; the target template is one of multiple templates in the template database.
[0114] The image restoration module 606 uses the image information of the target template to restore the barcode image, thereby obtaining the restored barcode image.
[0115] The barcode recognition module 608 is used to recognize barcode images.
[0116] By obtaining a target template with a high degree of matching to repair the barcode image, the likelihood of the barcode image being recognized can be increased, thereby improving the decoding rate.
[0117] In some embodiments, such as Figure 7 As shown, the barcode recognition device also includes:
[0118] The template update module 610 is used to iteratively update the image information of the target template using the repaired barcode image when the basic information of the repaired barcode image is the same as the basic information of the target template.
[0119] Through continuous iteration, it can be ensured that the image information of the template is shared by the barcodes of the same or similar batches of products.
[0120] Each module in the aforementioned barcode recognition device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0121] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8 As shown, the computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data related to barcode images. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements the steps in the barcode recognition method described above.
[0122] In some embodiments, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 9As shown, the computer device includes a processor, memory, input / output interface, communication interface, display unit, and input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interface. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The input / output interface is used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements the steps in the barcode recognition method described above. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen; the input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs or touchpads set on the casing of the computer device, or external keyboards, touchpads or mice, etc.
[0123] Those skilled in the art will understand that Figure 8 or Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0124] In some embodiments, a computer device is provided, the computer device including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps in the above method embodiments.
[0125] In some embodiments, such as Figure 10 The diagram shows the internal structure of a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the above-described method embodiments.
[0126] In some embodiments, a computer program product is provided, which includes a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0127] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0128] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0129] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0130] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A barcode recognition method, characterized in that, include: Obtain the template database; each template in the template database includes basic information and image information; the image information refers to the image area corresponding to the encoding overlap rate of all barcode images with the same basic information that is greater than a preset overlap rate; If barcode image recognition fails, determine the target template with the highest matching degree to the barcode image; The target template is one of multiple templates in the template database; Using the image information of the target template, determine whether the code dots in the barcode image corresponding to the image information are bars or empty, and obtain the repaired barcode image; The step of determining whether the barcode dots in the region corresponding to the image information in the barcode image are bars or empty using the image information of the target template includes: Determine the absolute value of the first difference between the average pixel value of all pixels within the code point of the binarized barcode image and the pixel value of the corresponding code point in the image information of the target template; If the absolute value of the first difference is less than the first preset difference, the barcode image is determined to have either a bar or a space. If the absolute value of the first difference is greater than or equal to the first preset difference, the barcode point corresponding to the barcode is determined to be an uncertain point. Determine n binarization thresholds; Based on the n binarization thresholds, determine the n binarized pixel values of the uncertain points in the barcode image; Determine the absolute values of the n binary pixel values of the uncertain point and the n second differences between the pixel values of the corresponding region pixels of the target template; If the absolute value of the second difference is less than the second preset difference, the uncertain point is determined to be a bar or a blank. The number of times the uncertain point is a bar and the number of times it is empty are obtained. If the number of times the bar is a bar is greater than the number of times it is empty, the uncertain point is determined to be a bar; if the number of times the bar is empty is greater than the number of times the bar is a bar, the uncertain point is determined to be empty. Where n is an odd number and the n binarization thresholds are not equal; The repaired barcode image is then recognized.
2. The method according to claim 1, characterized in that, The process of determining the target template with the highest matching degree to the barcode image includes: Obtain the basic information of the barcode image; The basic information of the barcode image is matched with the basic information of the templates in the template database. The templates that match successfully are identified as primary matching templates, and a primary matching template set is formed. The primary matching template with the highest similarity to the barcode image in the primary matching template set is identified as the target template.
3. The method according to claim 2, characterized in that, The basic information includes: One or more of the following: barcode polarity, barcode density, barcode length, and barcode width; When the basic information includes the barcode polarity and / or the barcode density, the template for determining a successful match is a primary matching template, including: The template with the same barcode polarity and / or barcode density is identified as the primary matching template; When the basic information includes the barcode length and / or the barcode width, the template for determining a successful match is a primary matching template, including: The templates whose barcode length of the template is within a preset length range and whose barcode width is within a preset width range are the primary matching templates.
4. The method according to claim 2, characterized in that, The step of determining the template with the highest similarity to the barcode image among the primary matching templates as the target template includes: The barcode image is binarized; Calculate the similarity between the binarized barcode image and the image information of the primary matching template; The primary matching template with the highest similarity is determined as the target template.
5. The method according to claim 1, characterized in that, The step of determining the n binary pixel values of the uncertain points in the barcode image based on the n binary thresholds includes: The pixel value of the pixel within the uncertain point in the barcode image is compared with the nth binarization threshold. If it is greater than or equal to the nth binarization threshold, the binarized pixel value of the pixel within the uncertain point in the barcode image is determined to be the first binarized pixel value; if it is less than the nth binarization threshold, the binarized pixel value of the pixel within the uncertain point in the barcode image is determined to be the second binarized pixel value. The average value of the binarized pixel values of all pixels within the uncertain point is determined to be the binarized pixel value of the uncertain point. This process is repeated n times to obtain n binarized pixel values of the uncertain point.
6. The method according to claim 1, characterized in that, After decoding the repaired barcode image, the process also includes: If the basic information of the repaired barcode image is the same as the basic information of the target template, the image information of the target template is iteratively updated using the repaired barcode image.
7. A barcode recognition device, characterized in that, include: The template acquisition module is used to acquire a template database; each template in the template database includes basic information and image information; the image information refers to the image area corresponding to the encoding overlap rate of all barcode images with the same basic information that is greater than a preset overlap rate. The template confirmation module is used to determine the target template with the highest matching degree to the barcode image when barcode image recognition fails. The target template is one of multiple templates in the template database; The image restoration module uses the image information of the target template to determine whether the code dots in the barcode image corresponding to the image information are bars or empty, and obtains the restored barcode image. The step of determining whether a barcode point in the barcode image corresponding to the image information of the target template is a bar or a blank area using the image information of the target template includes: determining the absolute value of a first difference between the average pixel value of all pixels within the barcode point in the binarized barcode image and the pixel value of the corresponding barcode point in the image information of the target template; determining whether the barcode point is a bar or a blank area if the absolute value of the first difference is less than a first preset difference; determining whether the barcode point is an uncertain point if the absolute value of the first difference is greater than or equal to the first preset difference; and setting multiple binarization thresholds to binarize the barcode image for the uncertain point, and determining the uncertain point as an uncertain point based on the binarization result. The method further includes: determining n binarization thresholds; determining n binarized pixel values of the uncertain point in the barcode image based on the n binarization thresholds; determining the absolute values of n second differences between the n binarized pixel values of the uncertain point and the pixel values of the corresponding region pixels of the target template; determining the uncertain point as either a bar or an empty point if the absolute value of the second difference is less than a second preset difference; obtaining the number of times the uncertain point is a bar and the number of times it is an empty point, determining the uncertain point as a bar if the number of times it is a bar is greater than the number of times it is an empty point; determining the uncertain point as an empty point if the number of times it is an empty point is greater than the number of times it is a bar; wherein n is an odd number and the n binarization thresholds are not equal; A barcode recognition module is used to recognize the barcode image.
8. A computer device, characterized in that, The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, It stores a computer program thereon, which, when executed by a processor, implements the steps of the method as described in any one of claims 1 to 6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the method as claimed in any one of claims 1 to 6.
Citation Information
Patent Citations
Two-dimensional code recognition method and device, electronic equipment and storage medium
CN111523340A
Method and system for quickly identifying bar code based on code scanner
CN113111675A