A barcode decoding method and device

By redefining edge points and attributes in barcode decoding, the problem of low-quality barcode decoding failure is solved, and the accurate decoding of low-quality barcodes is achieved.

CN115510889BActive Publication Date: 2025-04-15BEIJING LUSTER LIGHTTECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211357905.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-01
Publication Date
2025-04-15
Estimated Expiration
2042-11-01

AI Technical Summary

Technical Problem

The prior art is difficult to successfully decode low-quality barcodes, especially due to decoding failures caused by the presence of through-white lines on the black bars.

Method used

By determining the first edge point based on the edge point of the barcode, the width of each black bar and the width of each white space in the barcode are determined. If the decoding fails, the second edge point is re-determined based on the width of the white space, and re-decoded until the decoding is successful.

Benefits of technology

This method can overcome the interference of white lines in the barcode on decoding, accurately decode low-quality barcodes, and improve the success rate of decoding.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115510889B_ABST
    Figure CN115510889B_ABST
Patent Text Reader

Abstract

The present application provides a barcode decoding method and device, which can successfully decode low-quality barcodes. The method includes: based on the first edge point of the barcode to be decoded, determining the width of each black bar and the width of each white space contained in the barcode, the first edge point is the pixel point between adjacent black bars and white spaces in the barcode that meets the first preset condition; decoding the barcode according to the properties of the barcode, the properties of the barcode include the width of each black bar and the width of each white space contained in the barcode, and the arrangement order of the black bars and white spaces; if the decoding fails, determining the second edge point according to the width of each white space, and re-determining the properties of the barcode according to the second edge point, the second edge point is an edge point in the first edge point; decoding the barcode according to the re-determined properties of the barcode. If the decoding fails, re-determine the second edge point in the second edge point determined last time based on the above method until the decoding is successful.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a barcode decoding method and device. Background Art

[0002] Barcode technology is an emerging technology developed on the basis of computer technology and information technology, which integrates coding, printing, identification, data collection and processing. Barcode technology is widely used in commerce, library management, warehousing, post and telecommunications, transportation and industrial control due to its advantages of fast, accurate, reliable identification and low cost.

[0003] A barcode is a pattern of parallel lines composed of black bars (referred to as bars) and white spaces (referred to as spaces) with greatly different reflectivity. The width and arrangement order of the black bars and white spaces represent a group of information such as numbers or letters. Therefore, in the process of barcode decoding, it is first necessary to determine the width and arrangement order of the black bars and white spaces in the barcode, and then determine the information represented by the barcode based on this.

[0004] However, in the current process of printing barcodes, due to hardware failure and other factors, the barcode printing quality is poor, and sometimes there will be white lines running through the black bars of the barcode (for example, Figure 1 As shown in the figure, a barcode with this problem can be called a low-quality barcode. When decoding a low-quality barcode, the white line that runs through the black bar will be recognized as a white space, changing the width of the original black bar and the arrangement order of the black bar and the white space. Therefore, decoding a low-quality barcode will result in a barcode decoding failure.

[0005] How to successfully decode low-quality barcodes has become an urgent problem to be solved. Summary of the invention

[0006] The present application provides a barcode decoding method and device, which can successfully decode low-quality barcodes.

[0007] In a first aspect, the present application provides a barcode decoding method, comprising:

[0008] Determine the width of each black bar and each white space contained in the barcode based on a first edge point of the barcode to be decoded, wherein the first edge point is a pixel point between adjacent black bars and white spaces in the barcode that meets a first preset condition;

[0009] Decoding the barcode according to the properties of the barcode, wherein the properties of the barcode include the width of each black bar and the width of each white space contained in the barcode, and the arrangement order of the black bars and the white spaces;

[0010] If the decoding fails, a second edge point is determined according to the width of each white space, and the properties of the barcode are re-determined according to the second edge point, where the second edge point is an edge point among the first edge points;

[0011] The barcode is decoded according to the attributes of the re-determined barcode. If the decoding fails, the second edge point is re-determined according to the width of each white space in the re-determined barcode, and the barcode is decoded according to the re-determined second edge point until the decoding is successful. The re-determined second edge point is an edge point among the second edge points determined last time.

[0012] In one example, determining the second edge point according to the width of each white space includes:

[0013] Determine the white space with the smallest width according to the width of each white space;

[0014] The second edge point is determined according to the edge point corresponding to the white space with the smallest width and the first edge point.

[0015] In one example, determining the second edge point according to the edge point corresponding to the white space with the smallest width and the first edge point includes:

[0016] Delete all edge points corresponding to the white space with the smallest width;

[0017] The edge points other than all the edge points in the first edge points are taken as the second edge points.

[0018] In one example, determining the second edge point according to the edge point corresponding to the white space with the smallest width and the first edge point includes:

[0019] Delete some edge points corresponding to the white space with the smallest width in order from left to right or from right to left;

[0020] The edge points other than some edge points in the first edge points are taken as the second edge points.

[0021] In one example, decoding the barcode according to the attributes of the barcode includes:

[0022] Determine multiple calculation methods of the encoding used by the barcode, each calculation method is used to calculate the width ratio of the first area, the first area includes at least one black bar and / or at least one white space, the width ratio is the number of modules included in the first area, the module is a basic area that constitutes the black bars or white spaces in the barcode, and the first area of ​​different calculation methods includes different numbers of black bars and / or white spaces;

[0023] Determine a first calculation method for encoding the barcode according to the sum of the number of black bars and white spaces included in the first area, where the first calculation method belongs to multiple calculation methods;

[0024] Based on the first calculation method, a first width ratio group consisting of width ratios corresponding to the first regions in the barcode is obtained;

[0025] Determine each first similarity between the first width ratio group and each first candidate width ratio group in the first association relationship, the first similarity being the ratio of the number of width ratios in the first width ratio group that are the same as the first candidate width ratio group to the total number after the first width ratio group is compared with the first candidate width ratio group in sequence according to position, the total number being the total number of width ratios included in the first width ratio group, and the first association relationship being used to associate each first candidate width ratio group with a character represented by the barcode;

[0026] Determine a first target similarity that is greater than a first threshold among the first similarities;

[0027] The barcode is decoded according to a first candidate width ratio group corresponding to the first target similarity.

[0028] In one example, determining a first calculation method for encoding a barcode according to the sum of the number of black bars and white spaces included in the first area includes:

[0029] According to the sum of the numbers of black bars and white spaces included in the first area, a calculation method corresponding to the maximum number is determined as a first calculation method, and the first calculation method is used to encode the barcode.

[0030] In one example, decoding a barcode according to a candidate width ratio group corresponding to a first target similarity includes:

[0031] If the number of the first target similarities is multiple, determine a second calculation method for barcode encoding according to the sum of the number of black bars and white spaces included in the first area, the second calculation method being a calculation method other than the first calculation method among the multiple calculation methods;

[0032] Based on the second calculation method, obtaining a second width ratio group consisting of width ratios corresponding to each first area in the barcode;

[0033] Determine each second similarity between the second width ratio group and each second candidate width ratio group in the second association relationship, the second similarity being the ratio of the number of width ratios in the second width ratio group obtained after sequentially comparing the second width ratio group with the second candidate width ratio group according to position to the total number, the total number being the total number of width ratios included in the second width ratio group, and the second association relationship being used to associate each second candidate width ratio group with a character represented by the barcode;

[0034] Determine a second target similarity that is greater than a second threshold value among the second similarities;

[0035] The barcode is decoded according to the second candidate width ratio group corresponding to the second target similarity.

[0036] In one example, decoding the barcode according to the second candidate width ratio group corresponding to the second target similarity includes:

[0037] If there are multiple second target similarities, determine two largest second similarities among the second target similarities, and determine two second candidate width ratio groups corresponding to the two second similarities;

[0038] Determine, according to the second association relationship, two characters corresponding to the two second candidate width ratio groups;

[0039] The character that satisfies the verification rule among the two characters is determined as the decoding result of the barcode.

[0040] In one example, the method further includes:

[0041] Binarization of the collected barcode image;

[0042] Positioning the barcode image based on projection analysis;

[0043] According to the coordinates of the four affine rectangle vertices obtained by positioning, the barcode image is distorted and corrected, thereby obtaining the barcode to be decoded.

[0044] In a second aspect, the present application provides a barcode decoding device, comprising:

[0045] A barcode attribute determination module, used to determine the width of each black bar and each white space contained in the barcode based on a first edge point of the barcode to be decoded, wherein the first edge point is a pixel point between adjacent black bars and white spaces in the barcode that meets a first preset condition;

[0046] A barcode decoding module, used to decode the barcode according to the properties of the barcode, wherein the properties of the barcode include the width of each black bar and the width of each white space contained in the barcode, and the arrangement order of the black bars and the white spaces;

[0047] The barcode attribute determination module is also used to determine a second edge point according to the width of each white space if decoding fails, and to re-determine the attribute of the barcode according to the second edge point, wherein the second edge point is an edge point among the first edge points;

[0048] The barcode decoding module is also used to decode the barcode according to the re-determined barcode attributes. If the decoding fails, the second edge point is re-determined according to the width of each white space in the re-determined barcode, and the barcode is decoded according to the re-determined second edge point until the decoding is successful. The re-determined second edge point is an edge point among the second edge points determined last time.

[0049] Since the white line running through the black bar in the barcode will be identified as white space during the recognition process, and the width of the white line running through is significantly different from the width of the normal white space. Therefore, in the above embodiment of the present application, the barcode is decoded based on the edge point of the barcode. If the decoding fails, the second edge point for the next decoding is determined from the first edge point according to the width of the white space, and the width of each black bar and the width of each white space in the barcode are re-determined according to the second edge point, and then the barcode is decoded again based on the re-determined width of each black bar and the width of each white space in the barcode, and the cycle is repeated until the decoding is successful. This method can overcome the interference of the white line running through the barcode on the decoding and accurately decode low-quality barcodes. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0051] Figure 1 This is an example of a low-quality barcode provided by this application;

[0052] Figure 2 is a flowchart of a barcode decoding method provided by an exemplary embodiment of the present application;

[0053] Figure 3 is a schematic diagram of a first area of ​​a barcode provided by an exemplary embodiment of the present application;

[0054] Figure 4 is a schematic diagram of a first area of ​​a barcode provided by yet another exemplary embodiment of the present application;

[0055] Figure 5 is a flowchart of a barcode decoding method provided by yet another exemplary embodiment of the present application;

[0056] Figure 6 It is a schematic diagram of a barcode decoding device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0057] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.

[0058] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0059] Figure 2 FIG. 1 is a flow chart of a barcode decoding method provided by an exemplary embodiment of the present application. This embodiment can be applied to electronic devices, such as Figure 1 As shown, the barcode decoding method includes the following steps:

[0060] S110 , determining the width of each black bar and the width of each white space contained in the barcode based on the first edge point of the barcode to be decoded.

[0061] The first edge point is a pixel point between adjacent black bars and white spaces in the barcode that meets a first preset condition.

[0062] Exemplarily, the pixel point that meets the first preset condition refers to the pixel point whose corresponding grayscale gradient is greater than the preset threshold. Since the grayscale of the pixel points belonging to the black bar and the pixel points belonging to the white space at the boundary between the adjacent black bar and the white space varies greatly, that is, the grayscale gradient corresponding to the pixel points on both sides of the boundary is greater than the preset threshold. The first edge point can be a pixel point located at the boundary of the black bar, or a pixel point located at the boundary of the white space adjacent to the black bar.

[0063] Further illustratively, if there are multiple pixel points between adjacent black bars and white spaces that meet the first preset condition, a pixel point with the largest contrast among the multiple pixel points is taken as the first edge point.

[0064] Specifically, an edge detection algorithm or a projection analysis algorithm may be used to obtain the position (including horizontal coordinates and vertical coordinates) of the first edge points of the boundaries of adjacent black bars and white spaces, and then the width of the black bar or white space is determined according to the difference between the horizontal coordinates of two adjacent first edge points.

[0065] Exemplarily, before determining the width of each black bar and the width of each white space contained in the barcode based on the first edge point of the barcode to be decoded, the method further includes:

[0066] The collected barcode image is binarized to extract the barcode features. Then the barcode image is located based on projection analysis. Finally, the barcode image is distorted according to the coordinates of the four affine rectangle vertices obtained by location.

[0067] S120, decoding the barcode according to the attributes of the barcode.

[0068] The attributes of the barcode include the width of each black bar and the width of each white space contained in the barcode, as well as the arrangement order of the black bars and the white spaces.

[0069] Exemplarily, the width of the module in the barcode is first determined, and then the number of modules included in each black bar (which can be called the width ratio of the black bar) is determined based on the width of each black bar and the width of the module. The module is the basic area that constitutes the black bar or white space in the barcode. Similarly, the number of modules included in each white space (which can be called the width ratio of the white space) is determined based on the width of each white space and the width of the module. Then, the arrangement order of each width ratio is determined based on the arrangement order of the black bars and white spaces. Finally, based on the width ratio group composed of the arranged width ratios, the character represented by the barcode is determined in combination with the association relationship to decode the barcode, wherein the association relationship is used to associate each candidate width ratio group with the character represented by the barcode.

[0070] The module width is the result of dividing the width of the entire barcode by the number of modules.

[0071] In one example, according to the attributes of the barcode, the method of decoding the barcode includes:

[0072] S121, determining multiple calculation methods of the encoding used by the barcode, each calculation method is used to calculate the width ratio of the first area, the first area includes at least one black bar and / or at least one white space, the width ratio is the number of modules included in the first area, the module is a basic area that constitutes the black bars or white spaces in the barcode, and the first area of ​​different calculation methods includes different numbers of black bars and / or white spaces.

[0073] Exemplarily, the first area includes a black bar or a white space.

[0074] Exemplarily, the first area includes a black bar and a white space adjacent to each other.

[0075] Taking the barcode code as Code 128 as an example, calculation method A and calculation method B can be used. Figure 3As shown, the first area in calculation method A includes a black bar or a white space, and the width ratio of the first area = the width of a black bar or the width of a white space / the width of the module. The width ratio group composed of multiple width ratios is represented by 6 width ratios, and the first areas are p1, p2, p3, p4, p5 and p6. Among them, the first area p1 includes 1 black bar with a width of 2; the first area p2 includes 1 white space with a width of 1; the first area p3 includes 1 black bar with a width of 3; the first area p4 includes 1 white space with a width of 1; the first area p5 includes 1 black bar with a width of 1; the first area p6 includes 1 white space with a width of 3. Therefore, Figure 3 The width ratio of the barcode shown is 213113.

[0076] like Figure 4 As shown, the first area in calculation method B includes an adjacent black bar and a white space, and the width ratio of the first area = the sum of the width of the adjacent black bar and the width of the white space / the width of the module. The width ratio group composed of multiple width ratios is represented by 4 width ratios. The first areas are e1, e2, e3 and e4. It can be seen that the areas of e1 and e2 are crossed, the areas of e2 and e3 are crossed, and the areas of e3 and e4 are crossed. Among them, the first area e1 includes 1 black bar and 1 white space, and its width is 3; the first area e2 includes 1 white space and 1 black bar, and its width is 4; the first area e3 includes 1 black bar and 1 white space, and its width is 4; the first area e4 includes 1 white space and 1 black bar, and its width is 2. Therefore, Figure 4 The width ratio group of the barcode shown is 3442.

[0077] S122: Determine a first calculation method for encoding the barcode according to the sum of the numbers of black bars and white spaces included in the first area, where the first calculation method belongs to multiple calculation methods.

[0078] In one example, according to the sum of the numbers of black bars and white spaces included in the first area, a calculation method corresponding to the maximum sum is determined as a first calculation method, and the first calculation method is used to encode the barcode.

[0079] Since the number of modules of the barcode is fixed, the more the number of black bars and white spaces in the first area, the smaller the number of digits in the corresponding width ratio group, and the less calculation amount is required for decoding, the higher the efficiency is. Therefore, firstly using the largest number and the corresponding calculation method to decode the barcode, compared to selecting any calculation method to decode the barcode, on the premise that all decoding can be successful, it can reduce the time consumption of barcode decoding and improve efficiency.

[0080] S123: Based on the first calculation method, obtain a first width ratio group consisting of width ratios corresponding to the first regions in the barcode.

[0081] S124, determining each first similarity between the first width ratio group and each first candidate width ratio group in the first association relationship, the first similarity being the ratio of the number of width ratios in the first width ratio group that are the same as the first candidate width ratio group to the total number after comparing the first width ratio group with the first candidate width ratio group in sequence according to position, the total number being the total number of width ratios included in the first width ratio group, and the first association relationship being used to associate each first candidate width ratio group with the character represented by the barcode.

[0082] It should be understood that the first candidate width ratio group includes the same number of width ratios as the first width ratio group.

[0083] For example, a first candidate width ratio group of the first association relationship is 312132, and the first width ratio group is 312131, then the similarity between the first width ratio group and the first candidate width ratio group is 5 / 6.

[0084] S125: Determine a first target similarity that is greater than a first threshold among the first similarities.

[0085] Exemplarily, the first threshold is 0.7. The first threshold can be set according to actual needs, and this application does not limit this.

[0086] S126: Decode the barcode according to the first candidate width ratio group corresponding to the first target similarity.

[0087] In the above embodiment, the present application determines the first calculation method for encoding the barcode according to the sum of the number of black bars and white spaces included in the first area, thereby obtaining the first width ratio group corresponding to the barcode based on the first calculation method. Then, according to the first width ratio group and each first candidate width ratio group in the first association relationship, the target first similarity greater than the first threshold value among each first similarity is determined, and the barcode is decoded according to the first candidate width ratio group corresponding to the first target similarity, which can ensure the accuracy of decoding the barcode.

[0088] In one example, a method of decoding a barcode according to a candidate width ratio group corresponding to a first target similarity includes:

[0089] S1261, if there are multiple first target similarities, determine a second calculation method for barcode encoding according to the sum of the numbers of black bars and white spaces included in the first area, where the second calculation method is a calculation method other than the first calculation method among the multiple calculation methods.

[0090] Exemplarily, the sum of the numbers of black bars and white spaces included in the first area corresponding to the second calculation method is the largest among the calculation methods other than the first calculation method among the multiple calculation methods.

[0091] For example, the first calculation method is the calculation method B, and the sum of the numbers of black bars and white spaces included in the corresponding first area is 2; the second calculation method is the calculation method A, and the sum of the numbers of black bars and white spaces included in the corresponding first area is 1.

[0092] S1262: Based on the second calculation method, obtain a second width ratio group consisting of width ratios corresponding to the first regions in the barcode.

[0093] S1263, determining each second similarity between the second width ratio group and each second candidate width ratio group in the second association relationship, the second similarity being the ratio of the number of width ratios in the second width ratio group that are the same as the second candidate width ratio group to the total number after comparing the second width ratio group with the second candidate width ratio group in sequence according to position, the total number being the total number of width ratios included in the second width ratio group, and the second association relationship being used to associate each second candidate width ratio group with the character represented by the barcode.

[0094] It should be understood that the second candidate width ratio group includes the same number of width ratios as the second width ratio group.

[0095] S1264: Determine a second target similarity that is greater than a second threshold among the second similarities.

[0096] S1265 , decoding the barcode according to the second candidate width ratio group corresponding to the second target similarity.

[0097] Since the number of width ratios included in the width ratio group calculated by the second calculation method is greater than that of the first calculation method, the accuracy of decoding the barcode using the second calculation method is higher than that of the first calculation method. Therefore, if the number of first target similarities is multiple, in order to improve the accuracy of decoding the barcode, the second calculation method with higher accuracy is continued to be used to determine the second width ratio group of the barcode, and the second target similarity is determined based on the second width ratio group and the second association relationship, so as to decode the barcode based on the second candidate width ratio group corresponding to the second target similarity. In this method, only when the first calculation method cannot determine the unique first target similarity, the second calculation method will be used to continue to calculate the second target similarity to decode the barcode, which can improve the decoding efficiency while ensuring the accuracy of the barcode decoding result.

[0098] Exemplarily, decoding the barcode according to the second candidate width ratio group corresponding to the second target similarity includes:

[0099] If there are multiple second target similarities, determine the largest M second similarities among the second target similarities, and determine the M second candidate width ratio groups corresponding to the M second similarities. Then, according to the second association relationship, determine the M characters corresponding to the M second candidate width ratio groups. Finally, determine the characters that meet the verification rule among the M characters as the decoding result of the barcode. Wherein, M is an integer, and M is greater than or equal to 2.

[0100] Further illustratively, M characters are recursively traversed to confirm whether the verification rule is satisfied, until the verification rule is satisfied, and the decoding is successful.

[0101] It should be understood that the largest M second similarities refer to the similarities that are in the first M positions after all the second similarities are sorted from largest to smallest, or the similarities that are in the last M positions after all the second similarities are sorted from smallest to largest.

[0102] If there are multiple second target similarities, if the corresponding characters are determined blindly based on the second candidate width ratio group corresponding to the largest second similarity, the barcode verification rules may not be met, but there may be characters corresponding to non-largest second similarities that meet the barcode verification rules. If other calculation methods are used to decode the barcode again, it will cause a waste of computing resources. Therefore, the above method verifies the M characters corresponding to the largest M second similarities until a character that meets the verification rules is found, so that decoding is successful. While ensuring successful decoding, computing resources can be reasonably used to decode the barcode.

[0103] S130: If the decoding fails, determine the second edge point according to the width of each white space, and redetermine the attributes of the barcode according to the second edge point.

[0104] The second edge point is an edge point among the first edge points.

[0105] Exemplarily, decoding failure means that the character determined according to the first association relationship and the width ratio group does not satisfy the verification rule. The verification rule can refer to the current barcode verification rule, which is not limited in this application.

[0106] In one example, determining the second edge point according to the width of each white space includes:

[0107] First, a white space with the smallest width is determined according to the width of each white space, and a second edge point is determined according to an edge point corresponding to the white space with the smallest width and the first edge point.

[0108] Considering that the white line running through the black bar in the barcode will be identified as white space during the recognition process, and the width of the white line running through the barcode is significantly smaller than the width of the normal white space, in the above method, the second edge point can be accurately and quickly determined according to the edge point corresponding to the white space with the smallest width and the first edge point, so that the black bar and the white space can be re-determined according to the second edge point, and the barcode can be re-decoded.

[0109] Exemplarily, all edge points corresponding to the white space with the smallest width are deleted, and then edge points other than the all edge points in the first edge points are used as second edge points.

[0110] For example, the width of each white space is sorted in ascending order, all edge points corresponding to the smallest white space are deleted, and the remaining edge points are used as the second edge points.

[0111] Barcode defects caused by printing failures are often consistent in the same batch of products, so filtering edge points according to width can improve the efficiency of barcode decoding.

[0112] Exemplarily, some edge points corresponding to the white space with the smallest width are deleted in a sequence from left to right or from right to left, and then edge points other than the some edge points in the first edge points are used as second edge points.

[0113] For example, the width of each white space is sorted in order from small to large, the edge points corresponding to some of the smallest white spaces are deleted, and the remaining edge points are used as the second edge points. Furthermore, each time the width of the white space is re-determined, the edge points corresponding to some of the smallest white spaces can also be deleted in order from left to right. For example, the smallest white space width is 5 pixels, and the pixel points corresponding to the first two white spaces with a width of 5 pixels are deleted in order from left to right for the first time, and the barcode is decoded according to the pixel points corresponding to the remaining three white spaces with a width of 5 pixels and the pixel points corresponding to white spaces of other widths. If the decoding fails, the pixel points corresponding to the first two white spaces with a width of 5 pixels are deleted in order from left to right, and then the barcode is decoded according to the pixel points corresponding to the last white space with a width of 5 pixels and the pixel points corresponding to white spaces of other widths until the decoding is successful.

[0114] The present application also considers that the width of the abnormal white space may be the same as the width of the normal white space. If all edge points corresponding to the smallest white space are deleted, the edge points of the normal white space may be deleted, thereby affecting the decoding result of the barcode. Therefore, in the above method, only some edge points corresponding to the smallest white space are deleted, and the barcode is decoded according to the remaining edge points, which can improve the success rate of barcode decoding.

[0115] S140, decoding the barcode according to the attributes of the re-determined barcode. If the decoding fails, re-determine the second edge point according to the width of each white space in the re-determined barcode, and decode the barcode according to the re-determined second edge point until the decoding is successful. The re-determined second edge point is an edge point among the second edge points determined last time.

[0116] Since the white line running through the black bar in the barcode will be identified as white space during the recognition process, and the width of the white line running through is significantly different from the width of the normal white space. Therefore, the present application first decodes the barcode based on the edge points of the barcode. If the decoding fails, the second edge point for the next decoding is determined from the first edge point according to the width of the white space, and the width of each black bar and each white space in the barcode is re-determined according to the second edge point. Then, the barcode is decoded again based on the re-determined width of each black bar and each white space, and the cycle is repeated until the decoding is successful. This method can overcome the interference of the white line running through the barcode on the decoding and accurately decode low-quality barcodes.

[0117] In one example, if Figure 5 As shown, S120, S130 and S140 include:

[0118] S127, decoding the barcode according to the attributes of the barcode. If the decoding is successful, the process ends; if the decoding fails, executing S128, wherein the attributes of the barcode include the width of each black bar and the width of each white space contained in the barcode, and the arrangement order of the black bars and the white spaces.

[0119] S128, re-determine the second edge point according to the width of each white space, and re-determine the attribute of the barcode according to the second edge point, and execute S127, wherein the re-determined second edge point is an edge point among the second edge points determined last time, or an edge point among the first edge points.

[0120] Based on the above barcode decoding method, the present application also provides a barcode decoding device, such as Figure 6 As shown, the device 2 comprises:

[0121] The barcode attribute determination module 210 is used to determine the width of each black bar and each white space contained in the barcode based on the first edge point of the barcode to be decoded, wherein the first edge point is a pixel point between adjacent black bars and white spaces in the barcode that meets a first preset condition;

[0122] The barcode decoding module 220 is used to decode the barcode according to the properties of the barcode, wherein the properties of the barcode include the width of each black bar and the width of each white space contained in the barcode, and the arrangement order of the black bars and the white spaces;

[0123] The barcode attribute determination module 210 is further used to determine a second edge point according to the width of each white space if decoding fails, and to re-determine the attribute of the barcode according to the second edge point, wherein the second edge point is an edge point among the first edge points;

[0124] The barcode decoding module 220 is also used to decode the barcode according to the re-determined barcode attributes. If the decoding fails, the second edge point is re-determined according to the width of each white space in the re-determined barcode, and the barcode is decoded according to the re-determined second edge point until the decoding is successful. The re-determined second edge point is an edge point among the second edge points determined last time.

[0125] For other implementation methods and effects of the device, please refer to the description of the barcode decoding method, which will not be repeated here.

[0126] The basic principles of the present application are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present application are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present application. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, not for limitation, and the above details do not limit the present application to being implemented by adopting the above specific details.

[0127] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0128] The block diagrams of the devices, apparatuses, equipment, and systems involved in this application are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagram. As will be appreciated by those skilled in the art, these devices, apparatuses, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including", "comprising", "having", etc. are open words, referring to "including but not limited to", and can be used interchangeably with them. The words "or" and "and" used here refer to the words "and / or" and can be used interchangeably with them, unless the context clearly indicates otherwise. The words "such as" used here refer to the phrase "such as but not limited to", and can be used interchangeably with them.

[0129] It should also be noted that in the apparatus, device and method of the present application, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present application.

[0130] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present application. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present application. Therefore, the present application is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

[0131] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present application to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.

Claims

1. A barcode decoding method, characterized in that: include: Determining the width of each black bar and each white space contained in the barcode based on a first edge point of the barcode to be decoded, wherein the first edge point is a pixel point between adjacent black bars and white spaces in the barcode that meets a first preset condition; Decoding the barcode according to the properties of the barcode, wherein the properties of the barcode include the width of each black bar and the width of each white space contained in the barcode, and the arrangement order of the black bars and the white spaces, wherein decoding the barcode according to the properties of the barcode includes: Determine multiple calculation methods of the encoding used by the barcode, each calculation method is used to calculate the width ratio of the first area, the first area includes at least one black bar and / or at least one white space, the width ratio is the number of modules included in the first area, the module is a basic area constituting the black bars or white spaces in the barcode, and the first area of ​​different calculation methods includes different numbers of black bars and / or white spaces; Determining a first calculation method for encoding the barcode according to the sum of the numbers of black bars and white spaces included in the first area, wherein the first calculation method belongs to the multiple calculation methods; Based on the first calculation method, obtaining a first width ratio group consisting of width ratios corresponding to each of the first regions in the barcode; determining each first similarity between the first width ratio group and each first candidate width ratio group in the first association relationship, the first similarity being the ratio of the number of width ratios in the first width ratio group that are the same as the first candidate width ratio group to the total number obtained after sequentially comparing the first width ratio group with the first candidate width ratio group according to position, the total number being the total number of width ratios included in the first width ratio group, and the first association relationship being used to associate each first candidate width ratio group with the character represented by the barcode; Determine a first target similarity that is greater than a first threshold value among the first similarities; If the number of the first target similarity is one, decoding the barcode according to a first candidate width ratio group corresponding to the first target similarity; If there are multiple first target similarities, determine a second calculation method for encoding the barcode according to the sum of the numbers of black bars and white spaces included in the first area, where the second calculation method is a calculation method other than the first calculation method among the multiple calculation methods; Based on the second calculation method, obtaining a second width ratio group consisting of width ratios corresponding to each of the first regions in the barcode; determining each second similarity between the second width ratio group and each second candidate width ratio group in the second association relationship, the second similarity being the ratio of the number of width ratios in the second width ratio group that are the same as the second candidate width ratio group to the total number obtained after sequentially comparing the second width ratio group with the second candidate width ratio group according to position, the total number being the total number of width ratios included in the second width ratio group, and the second association relationship being used to associate each second candidate width ratio group with the character represented by the barcode; Determine a second target similarity that is greater than a second threshold value among the second similarities; decoding the barcode according to a second candidate width ratio group corresponding to the second target similarity; If decoding fails, determining a second edge point according to the width of each white space, and re-determining the attribute of the barcode according to the second edge point, wherein the second edge point is an edge point among the first edge points, wherein determining the second edge point according to the width of each white space includes: Determining a white space with the smallest width according to the width of each white space; Delete all edge points corresponding to the white space with the smallest width; taking edge points other than all the edge points in the first edge points as second edge points; The barcode is decoded according to the re-determined attributes of the barcode. If the decoding fails, the second edge point is re-determined according to the re-determined width of each white space in the barcode, and the barcode is decoded according to the re-determined second edge point until the decoding is successful. The re-determined second edge point is an edge point among the second edge points determined last time.

2. The method according to claim 1, characterized in that The determining of the second edge point according to the edge point corresponding to the white space with the smallest width and the first edge point comprises: Deleting some edge points corresponding to the white space with the smallest width in a sequence from left to right or from right to left; The edge points other than the part of the edge points in the first edge points are used as second edge points.

3. The method according to claim 1, characterized in that The determining, according to the sum of the number of black bars and white spaces included in the first area, a first calculation method for encoding the barcode includes: According to the sum of the numbers of black bars and white spaces included in the first area, a calculation method corresponding to the maximum sum of the numbers is determined as a first calculation method, and the first calculation method is used to encode the barcode.

4. The method according to claim 1, characterized in that: The decoding of the barcode according to the second candidate width ratio group corresponding to the second target similarity includes: If there are multiple second target similarities, determine two largest second similarities among the second target similarities, and determine two second candidate width ratio groups corresponding to the two second similarities; Determine, according to the second association relationship, two characters corresponding to the two second candidate width ratio groups; The character satisfying the verification rule among the two characters is determined as the decoding result of the barcode.

5. The method according to claim 1, characterized in that The method further comprises: Binarization of the collected barcode image; Positioning the image of the barcode based on projection analysis; According to the coordinates of the four affine rectangle vertices obtained by positioning, the image of the barcode is subjected to distortion correction, thereby obtaining the barcode to be decoded.

6. A barcode decoding device, characterized in that: include: A barcode attribute determination module, configured to determine the width of each black bar and each white space contained in the barcode based on a first edge point of the barcode to be decoded, wherein the first edge point is a pixel point between adjacent black bars and white spaces in the barcode that meets a first preset condition; A barcode decoding module is used to decode the barcode according to the properties of the barcode, wherein the properties of the barcode include the width of each black bar and the width of each white space contained in the barcode, and the arrangement order of the black bars and the white spaces, wherein decoding the barcode according to the properties of the barcode includes: Determine multiple calculation methods of the encoding used by the barcode, each calculation method is used to calculate the width ratio of the first area, the first area includes at least one black bar and / or at least one white space, the width ratio is the number of modules included in the first area, the module is a basic area constituting the black bars or white spaces in the barcode, and the first area of ​​different calculation methods includes different numbers of black bars and / or white spaces; Determining a first calculation method for encoding the barcode according to the sum of the numbers of black bars and white spaces included in the first area, wherein the first calculation method belongs to the multiple calculation methods; Based on the first calculation method, obtaining a first width ratio group consisting of width ratios corresponding to each of the first regions in the barcode; determining each first similarity between the first width ratio group and each first candidate width ratio group in the first association relationship, the first similarity being the ratio of the number of width ratios in the first width ratio group that are the same as the first candidate width ratio group to the total number obtained after sequentially comparing the first width ratio group with the first candidate width ratio group according to position, the total number being the total number of width ratios included in the first width ratio group, and the first association relationship being used to associate each first candidate width ratio group with the character represented by the barcode; Determine a first target similarity that is greater than a first threshold value among the first similarities; If the number of the first target similarity is one, decoding the barcode according to a first candidate width ratio group corresponding to the first target similarity; If there are multiple first target similarities, determine a second calculation method for encoding the barcode according to the sum of the numbers of black bars and white spaces included in the first area, where the second calculation method is a calculation method other than the first calculation method among the multiple calculation methods; Based on the second calculation method, obtaining a second width ratio group consisting of width ratios corresponding to each of the first regions in the barcode; determining each second similarity between the second width ratio group and each second candidate width ratio group in the second association relationship, the second similarity being the ratio of the number of width ratios in the second width ratio group that are the same as the second candidate width ratio group to the total number obtained after sequentially comparing the second width ratio group with the second candidate width ratio group according to position, the total number being the total number of width ratios included in the second width ratio group, and the second association relationship being used to associate each second candidate width ratio group with the character represented by the barcode; Determine a second target similarity that is greater than a second threshold value among the second similarities; decoding the barcode according to a second candidate width ratio group corresponding to the second target similarity; The barcode attribute determination module is further configured to, if decoding fails, determine a second edge point according to the width of each white space, and re-determine the attribute of the barcode according to the second edge point, wherein the second edge point is an edge point among the first edge points, wherein determining the second edge point according to the width of each white space includes: Determining a white space with the smallest width according to the width of each white space; Delete all edge points corresponding to the white space with the smallest width; taking edge points other than all the edge points in the first edge points as second edge points; The barcode decoding module is also used to decode the barcode according to the re-determined attributes of the barcode. If the decoding fails, the second edge point is re-determined according to the re-determined width of each white space in the barcode, and the barcode is decoded according to the re-determined second edge point until the decoding is successful. The re-determined second edge point is an edge point among the second edge points determined last time.

Citation Information

Patent Citations

  • Barcode identification method, device and apparatus

    CN108073848A

  • Barcode recognition method and device and electronic equipment

    CN113869077A