Code128 bar code reconstruction method and device and terminal equipment

By standardizing and reconstructing the width of the Code128 barcode area, the problem of low barcode recognition accuracy with low image quality is solved, and high accuracy recognition is achieved in blurred or low contrast scenarios.

CN120258019APending Publication Date: 2025-07-04SHENZHEN YANXIANG JINMA SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510337815.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

The prior art has the problem of low accuracy in the recognition of Code128 barcodes in scenarios with low image quality, especially when the edges of the barcode are broken or blurred, which can easily lead to identification errors.

Method used

By standardizing the width of the barcode area to be identified, and rounding the width of the bar empty, determining whether it complies with the Code128 encoding rules, reconstructing if necessary, obtaining multiple barcode combinations that comply with the encoding rules, and selecting barcode combinations that comply with the verification rules as the target barcode.

Benefits of technology

In scenarios with low image quality, the recognition accuracy of Code128 barcodes is improved, ensuring that the recognition results comply with the encoding and verification rules, and improving the recognition accuracy and confidence.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120258019A_ABST
    Figure CN120258019A_ABST
Patent Text Reader

Abstract

The invention relates to a Code128 bar code reconstruction method and apparatus, and a terminal device. The method comprises the steps of standardizing the width of each bar code region in a to-be-identified bar code into a target width; rounding the width of each blank in the bar code area to obtain the first width of each blank; for the same bar code area, if the sum of the first widths of the bar spaces is equal to the target width and accords with the coding rule, taking the bar code area as a first area; if the sum of the first widths is not equal to the target width or does not accord with the coding rule, reconstructing the bar code area to obtain a plurality of second areas; and obtaining a plurality of bar code combinations corresponding to the to-be-identified bar code according to the first area or the plurality of second areas corresponding to each bar code area, and selecting a bar code combination conforming to the verification rule from the plurality of bar code combinations as a target bar code. According to the method and the device, the problem of low recognition accuracy of the Code128 bar code in a scene with relatively low image quality is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the technical field of bar code recognition, and particularly relates to a Code128 bar code reconstruction method, device, and terminal device. Background Art

[0002] The Code128 bar code is a commonly used linear bar code symbol that can represent a total of 128 characters from ASCII 0 to ASCII 127 (including numbers, letters, and symbol characters). Each character of the Code128 bar code consists of 11 units including 3 black bars and 3 white spaces. Currently, the general method for recognizing the Code128 bar code is as follows: recognizing the width ratio of each black bar / white space; reading the string according to the width ratio of each black bar / white space; dividing the string into groups of 6; after removing the start bit and end bit, querying the Code128 character table to determine the character corresponding to each group of strings.

[0003] However, this recognition method is greatly affected by the image quality. Once there are breaks, blurs, etc. at the edges of some bar codes. For example, the width ratio of the black bar / white space of a certain character in the Code128 bar code is actually {1, 1, 1, 3, 2, 3}, and the character it represents is "A". When the image is not clear (for example, with low contrast and blurred image), the above width ratio may be recognized as {1, 1, 2, 3, 1, 3}, that is, the actually represented character "A" is misrecognized as "D", which will cause an error in reading the string and further cause a decoding error.

[0004] Currently, there is no effective solution to the problem of low recognition accuracy of the Code128 bar code in scenarios with low image quality in the related art. Summary of the Invention

[0005] Embodiments of this application provide a Code128 bar code reconstruction method, device, and terminal device to at least solve the problem of low recognition accuracy of the Code128 bar code in scenarios with low image quality in the related art.

[0006] In a first aspect, an embodiment of the present application provides a Code128 barcode reconstruction method, including: standardizing the widths of barcode regions in a barcode to be recognized to a target width; rounding the widths of bars and spaces in the barcode regions to obtain first widths of the bars and spaces; for the same barcode region, if the sum of the first widths of the bars and spaces is equal to the target width and the barcode region conforms to the Code128 encoding rule, then taking the barcode region as a first region; if the sum of the first widths is not equal to the target width or the barcode region does not conform to the Code128 encoding rule, then reconstructing the barcode region to obtain a plurality of second regions, where the sum of second widths of the bars and spaces in the second regions is equal to the target width and the second regions conform to the Code128 encoding rule; obtaining a plurality of barcode combinations corresponding to the barcode to be recognized according to the first regions or the plurality of second regions corresponding to the barcode regions, and selecting a barcode combination that conforms to the Code128 check rule from the plurality of barcode combinations as the target barcode.

[0007] In some embodiments, standardizing the widths of barcode regions in a barcode to be recognized to a target width includes: obtaining the minimum width of the bars and spaces from the barcode to be recognized; according to the minimum width of the bars and spaces, standardizing the widths of the barcode regions to the target width, where the target width is 11 times the minimum width, and the barcode to be recognized includes a plurality of barcode regions and an end-bit region.

[0008] In some embodiments, obtaining the minimum width of the bars and spaces from the barcode to be recognized includes: obtaining the total width of the barcode to be recognized; obtaining the total number of the bars and spaces from the barcode to be recognized, where the bars and spaces include black bars and white spaces in the barcode to be recognized; determining the number of barcode regions in the barcode to be recognized based on the total number of the bars and spaces; and obtaining the minimum width of the bars and spaces according to the number of barcode regions and the total width.

[0009] In some embodiments, before standardizing the widths of the barcode regions to the target width according to the minimum width of the bars and spaces, the method further includes: dividing the barcode to be recognized into the plurality of barcode regions and the end-bit region along a preset barcode direction according to the number of barcode regions.

[0010] In some embodiments, before dividing the barcode to be recognized into the multiple barcode regions and the end-bit region along a preset barcode direction according to the number of the barcode regions, the method further includes: dividing the barcode to be recognized into the multiple barcode regions and the end-bit region along a first direction according to the number of the barcode regions, calculating the sum of the error between the width of each barcode region and the target width and the error between the end-bit region and the end-bit width as a first error, where the end-bit width is 13 times the minimum width; dividing the barcode to be recognized into the multiple barcode regions and the end-bit region along a second direction according to the number of the barcode regions, calculating the sum of the error between the width of each barcode region and the target width and the error between the end-bit region and the end-bit width as a second error, where the second direction forms an angle of 180° with the first direction; if the first error is less than the second error, taking the first direction as the barcode direction; otherwise, taking the second direction as the barcode direction.

[0011] In some embodiments, reconstructing the barcode region to obtain multiple second regions includes: performing an addition operation on the width of the bar and space in the barcode region with a preset value and then performing a rounding operation, taking the width after the addition operation and the rounding operation as the second width of the bar and space, to obtain multiple reconstructed regions corresponding to the barcode region, where each reconstructed region corresponds to a preset value; selecting, from the multiple reconstructed regions, the reconstructed region in which the sum of the second widths of the bars and spaces is equal to the target width and that conforms to the Code128 encoding rule as the second region.

[0012] In some embodiments, selecting a barcode combination that conforms to the Code128 check rule from the multiple barcode combinations as the target barcode includes: selecting a barcode combination that conforms to the Code128 check rule from the multiple barcode combinations as a preliminary screening barcode combination; in the case where there is more than one preliminary screening barcode combination, calculating the similarity between each preliminary screening barcode combination and the barcode to be recognized; selecting, from the multiple preliminary screening barcode combinations, the preliminary screening barcode combination with the highest similarity to the barcode to be recognized as the target barcode.

[0013] In a second aspect, an embodiment of the present application provides a Code128 barcode reconstruction device, including: a standardization module for standardizing the width of each barcode area in the barcode to be recognized to a target width; a calculation module for rounding the width of each bar and space in the barcode area to obtain a first width of each bar and space; a reconstruction module for, for the same barcode area, if the sum of the first widths of each bar and space is equal to the target width and the barcode area conforms to the Code128 encoding rule, taking the barcode area as a first area; and if the sum of the first widths is not equal to the target width or the barcode area does not conform to the Code128 encoding rule, reconstructing the barcode area to obtain a plurality of second areas, wherein the sum of the second widths of each bar and space in the second area is equal to the target width and the second area conforms to the Code128 encoding rule; a selection module for obtaining a plurality of barcode combinations corresponding to the barcode to be recognized according to the first area or the plurality of second areas corresponding to each barcode area, and selecting a barcode combination that conforms to the Code128 check rule from the plurality of barcode combinations as the target barcode.

[0014] In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the Code128 barcode reconstruction method according to any one of the above first aspects is implemented.

[0015] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is run, the Code128 barcode reconstruction method according to any one of the above first aspects is executed.

[0016] Compared with the related art, the Code128 barcode reconstruction method, device, and terminal device provided by the embodiments of the present application standardize the widths of the barcode regions in the barcode to be recognized, round the widths of each bar and space, and obtain the first widths of each bar and space; then, for the same barcode region, determine whether the barcode region needs to be reconstructed by judging whether the sum of the first widths of the bars and spaces it contains is equal to the target width and whether the barcode region conforms to the Code128 encoding rule; reconstruct the barcode regions whose sum of the first widths of the bars and spaces contained is not equal to the target width or does not conform to the Code128 encoding rule, and obtain multiple barcode combinations corresponding to the barcode to be recognized based on the multiple second regions obtained by the reconstruction; finally, a barcode combination that conforms to the Code128 verification rule can be selected from the multiple barcode combinations as the target barcode. In this way, in a scenario with low image quality, multiple second regions that conform to the Code128 encoding rule can be obtained through barcode reconstruction operations, and then multiple barcode combinations that conform to the Code128 encoding rule can be obtained. Then, a barcode combination that conforms to the Code128 verification rule is selected from the multiple barcode combinations as the target barcode, which can ensure that the target barcode corresponding to the barcode to be recognized conforms to both the Code128 encoding rule and the Code128 verification rule, thereby improving the recognition accuracy of the barcode to be recognized. Through the present application, the problem of low recognition accuracy of Code128 barcodes in scenarios with low image quality in the related art is solved, and the technical effect of improving the recognition accuracy of Code128 barcodes in scenarios with low image quality is achieved.

[0017] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more concise and understandable. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0019] Figure 1 is a schematic structural diagram of a Code128 barcode according to an embodiment of the present application;

[0020] Figure 2 is a flowchart of a Code128 barcode reconstruction method according to an embodiment of the present application;

[0021] Figure 3 is a schematic structural diagram of a Code128 barcode reconstruction device according to an embodiment of the present application;

[0022] Figure 4 It is a schematic structural diagram of a terminal device according to an embodiment of the present application. Detailed implementation manners

[0023] In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structures and technologies are presented in order to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.

[0024] It should be understood that when used in the specification and claims of the present application, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0025] It should also be understood that the term "and / or" as used in the specification and claims of the present application refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0026] As used in the specification and claims of the present application, the term "if" can be interpreted as "when", "once", "in response to determining", or "in response to detecting" according to the context. Similarly, the phrase "if determined" or "if detecting [the described condition or event]" can be interpreted as meaning "once determined", "in response to determining", "once detecting [the described condition or event]", or "in response to detecting [the described condition or event]" according to the context.

[0027] In addition, in the description of the specification and claims of the present application, the terms "first", "second", "third", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0028] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that specific features, structures or characteristics described in connection with that embodiment are included in one or more embodiments of this application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments" etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in another way. The terms "comprising", "including", "having" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in another way.

[0029] The Code128 barcode is a commonly used linear barcode symbol that can represent a total of 128 characters from ASCII 0 to ASCII 127 (including numbers, letters, and symbol characters). Each character of the Code128 barcode consists of 11 units, namely 3 black bars and 3 white spaces. Currently, the general method for identifying the Code128 barcode is as follows: identify the width ratios of each black bar / white space; read the character string according to the width ratios of each black bar / white space; divide the character string into groups of 6; after removing the start bit and the end bit, query the Code128 character table to determine the character corresponding to each group of character strings.

[0030] However, this identification method is greatly affected by the image quality. Once there are breaks, blurs, etc. at the edges of some barcodes. For example, the width ratio of the black bar / white space of a certain character of the Code128 barcode is actually {1, 1, 1, 3, 2, 3}, and the character it represents is "A". When the image is not clear (for example, with low contrast and blurred image), the above width ratio may be identified as {1, 1, 2, 3, 1, 3}, that is, the actually represented character "A" is misidentified as "D", which will cause an error in reading the character string and further cause a decoding error.

[0031] Currently, no effective solution has been proposed for the problem of low recognition accuracy of the Code128 barcode in scenarios with low image quality in the related art.

[0032] In view of this, an embodiment of the present application provides a Code128 barcode reconstruction method. By standardizing the widths of each barcode area in the barcode to be recognized and rounding the widths of each bar and space, the first widths of each bar and space are obtained. Then, for the same barcode area, it is determined whether the barcode area needs to be reconstructed by judging whether the sum of the first widths of the bars and spaces it contains is equal to the target width and whether the barcode area conforms to the Code128 encoding rule. By reconstructing the barcode areas whose sum of the first widths of the bars and spaces is not equal to the target width or does not conform to the Code128 encoding rule, and obtaining multiple barcode combinations corresponding to the barcode to be recognized based on the multiple second areas obtained by the reconstruction. Finally, a barcode combination that conforms to the Code128 check rule can be selected from the multiple barcode combinations as the target barcode. In this way, in a scenario with low image quality, through barcode reconstruction operations, multiple second areas that conform to the Code128 encoding rule can be obtained, and then multiple barcode combinations that conform to the Code128 encoding rule can be obtained. Then, by selecting a barcode combination that conforms to the Code128 check rule from the multiple barcode combinations as the target barcode, it can be ensured that the target barcode corresponding to the barcode to be recognized conforms to both the Code128 encoding rule and the Code128 check rule, thereby improving the recognition accuracy of the barcode to be recognized. Through the present application, the problem of low recognition accuracy of Code128 barcodes in scenarios with low image quality in the related art is solved, and the technical effect of improving the recognition accuracy of Code128 barcodes in scenarios with low image quality is achieved.

[0033] Figure 1 is a schematic structural diagram of a Code128 barcode according to an embodiment of the present application, as Figure 1 shown, a Code128 barcode generally includes: a start bit a, a data area b, a check bit c, and an end bit d. Among them, except for the end bit d, each character area included in the start bit a, the check bit c, and the data area b is composed of 11 units including 3 black bars and 3 white spaces, while the end bit d is composed of 13 units including 4 black bars and 3 white spaces. The forms of the start bit and the end bit are generally fixed.

[0034] Specifically, the start bit has three versions, namely Start A (indicating that the Code128 barcode includes numbers, uppercase letters, control characters, and special characters), Start B (indicating that the Code128 barcode includes numbers, uppercase and lowercase letters, control characters, and special characters), and Start C (indicating that the Code128 barcode includes numbers from 0 to 99). The width ratio of the black bars / white spaces corresponding to Start A is {2, 1, 1, 4, 1, 2}, the width ratio of the black bars / white spaces corresponding to Start B is {2, 1, 1, 2, 1, 4}, and the width ratio of the black bars / white spaces corresponding to Start C is {2, 1, 1, 2, 3, 2}.

[0035] As an example, please refer to Figure 1 , the width ratio of the black bars / white spaces of the start bit a of this Code128 barcode is {2, 1, 1, 2, 3, 2}, so this Code128 barcode includes numbers from 0 to 99.

[0036] In addition, the form of the end bit is fixed, and the width ratio of the black bars / white spaces is {2, 3, 3, 1, 1, 1, 2}, indicating that the Code128 barcode has ended. The check digit is used to check whether the Code128 barcode is correctly encoded.

[0037] Specifically, the check digit = (the character set ID value corresponding to the start bit + the ID value of the first character area in the data area * 1 + the ID value of the second character area in the data area * 2 +... + the ID value of the nth character area in the data area * n) % 103.

[0038] As an example, please refer to Figure 1 , the character set ID value corresponding to the start bit a is 105, the data area b includes a total of 6 character areas, and the corresponding ID values are 12, 34, 56, 78, 90, 12 respectively. The width ratio of the black bars / white spaces of the check digit c is {3, 1, 1, 1, 2, 3}, representing the number "54", and (105 + 12 * 1 + 34 * 2 + 56 * 3 + 78 * 4 + 90 * 5 + 12 * 6) % 103 = 54.

[0039] Therefore, it is possible to check whether the Code128 barcode is correctly encoded through the check digit.

[0040] Next, the Code128 barcode reconstruction method provided by an embodiment of the present application will be described in conjunction with Figure 2 Please refer to Figure 2 , Figure 2 is a flowchart of the Code128 barcode reconstruction method according to an embodiment of the present application. As shown in Figure 2 shown, the method includes:

[0041] Step S201, standardize the width of each barcode area in the barcode to be recognized to a target width.

[0042] In this embodiment, the barcode to be recognized includes a plurality of barcode areas and an end bit area, where the plurality of barcode areas include a start bit area, a plurality of character areas included in the data area, and a check bit area.

[0043] In addition, the image containing the barcode to be recognized can be segmented and binarized, the black and white bar areas therein can be extracted, and a vertical projection histogram can be constructed, so as to extract the barcode to be recognized. The barcode to be recognized contains a plurality of bars and spaces, and the bars and spaces include black bars and white spaces.

[0044] Since the image containing the barcode to be recognized may have problems such as partial blurring and incorrect barcode orientation, it is necessary to first standardize the width of each barcode area included in the barcode to be recognized to the target width, so as to improve the accuracy of subsequent recognition of the barcode to be recognized.

[0045] Specifically, standardizing the width of each barcode area in the barcode to be recognized to the target width includes the following steps:

[0046] Step 1, obtain the minimum width of the bars and spaces from the barcode to be recognized.

[0047] In this embodiment, obtaining the minimum width of the bars and spaces from the barcode to be recognized includes: obtaining the total width of the barcode to be recognized; obtaining the total number of bars and spaces from the barcode to be recognized, where the bars and spaces include the black bars and white spaces in the barcode to be recognized; determining the number of barcode areas in the barcode to be recognized based on the total number of bars and spaces; and obtaining the minimum width of the bars and spaces according to the number of barcode areas and the total width.

[0048] Specifically, the minimum width of the bars and spaces can be calculated based on the following mathematical expression:

[0049]

[0050] where a is the minimum width, D is the total width, and N is the number of barcode areas.

[0051] In this embodiment, first, the width of each bar and space in the barcode to be recognized can be calculated where and are the start position and end position of the i-th bar and space. Through the total width of the barcode to be recognized can be obtained.

[0052] Then, since the barcode areas (excluding the end bit area) in the barcode to be recognized are fixed to be composed of 3 black bars and 3 white spaces, and the end bit area is fixed to be composed of 4 black bars and 3 white spaces. Therefore, through Calculate the number of barcode regions in the barcode to be recognized, where A is the total number of bars and spaces in the barcode to be recognized.

[0053] Finally, it can be achieved through Calculate the minimum width of the bars and spaces, and the minimum width of the bars and spaces can be used as the basic width unit, and the relative widths of each bar and space are normalized

[0054] Step 2, according to the minimum width of the bars and spaces, standardize the widths of each barcode region to the target width, where the target width is 11 times the minimum width.

[0055] In this embodiment, according to the minimum width of the bars and spaces, the width of the barcode region in the barcode to be recognized can be standardized to 11 times the minimum width. In addition, the width of the end bit region in the barcode to be recognized can also be standardized to 13 times the minimum width.

[0056] In addition, for all the bars and spaces in a barcode region, if there is a bar or space with a width less than 1 basic width unit, its width can be reset to 1; if there is a bar or space with a width greater than 4 basic width units, its width can be reset to 4. Through this standardization process, it can be ensured that all barcode regions maintain a consistent size, effectively avoiding problems such as stretching or compression of barcode regions caused by image background distortion, etc., thereby improving the accuracy of subsequent recognition of the barcode to be recognized.

[0057] In one embodiment, before standardizing the widths of each barcode region to the target width according to the minimum width of the bars and spaces, the method further includes: dividing the barcode to be recognized into multiple barcode regions and an end bit region along the preset barcode direction according to the number of barcode regions.

[0058] In this embodiment, the preset barcode direction can be the arrangement direction of the barcode to be recognized obtained from the image containing the barcode to be recognized. For example, please refer to Figure 1 , the x - direction can be used as the preset barcode direction. However, the image may have problems such as blurring and low contrast. At this time, the arrangement direction of the barcode to be recognized cannot be obtained. Therefore, it is necessary to judge the front - back direction of the barcode to be recognized.

[0059] Specifically, before dividing the barcode to be recognized into multiple barcode regions and an end bit region along the preset barcode direction according to the number of barcode regions, the method further includes the following steps:

[0060] Step 1: Divide the barcode to be recognized into multiple barcode regions and an end-bit region along the first direction according to the number of barcode regions, and calculate the sum of the errors between the widths of each barcode region and the target width and the error between the end-bit region and the end-bit width as the first error, where the end-bit width is 13 times the minimum width.

[0061] Step 2: Divide the barcode to be recognized into multiple barcode regions and an end-bit region along the second direction according to the number of barcode regions, and calculate the sum of the errors between the widths of each barcode region and the target width and the error between the end-bit region and the end-bit width as the second error, where the second direction forms an angle of 180° with the first direction.

[0062] Step 3: If the first error is less than the second error, take the first direction as the barcode direction; otherwise, take the second direction as the barcode direction.

[0063] In this embodiment, since each barcode region except the end-bit region in the barcode to be recognized includes three black bars and three white spaces, and the width of each barcode region should be 11 times the basic width unit, while the width of the end-bit region should be 13 times the basic width unit. Therefore, the barcode to be recognized can be first divided into multiple barcode regions and an end-bit region along the first direction, and then the error between each barcode region and the target width and the error between the end-bit region and the end-bit width are calculated. Subsequently, repeat the above operations along the second direction that forms an angle of 180° with the first direction, and select the direction with the smaller total error as the barcode direction. In this way, it can be ensured that the multiple barcode regions and the end-bit region obtained by dividing the barcode to be recognized are consistent with the actual situation, thereby improving the accuracy of subsequent recognition of the barcode to be recognized.

[0064] Step S202: Round the widths of each bar and space in the barcode region to obtain the first width of each bar and space.

[0065] In this embodiment, a rounding operation can be performed on the widths of each bar and space in the barcode region. For example, if the width of a certain bar or space is 1.73 (it should be noted that the width here refers to the relative width with respect to the basic width unit (i.e., the minimum width of the bar and space), and 1.73 means 1.73 times the minimum width), it is rounded to 2.

[0066] Step S203: For the same barcode region, if the sum of the first widths of each bar and space is equal to the target width and the barcode region conforms to the Code128 encoding rule, take the barcode region as the first region.

[0067] In this embodiment, if the sum of the first widths of all the empty bars and spaces is equal to the target width and the barcode area conforms to the Code128 encoding rule, then the barcode area can be directly recognized without performing a barcode reconstruction operation. The "Code128 encoding rule" in step S203 includes that while the sum of the first widths of the bars and spaces included in the barcode area (excluding the end bit area) in the barcode to be recognized is equal to 11 times the minimum width, and the sum of the first widths of the bars and spaces included in the end bit area in the barcode to be recognized is equal to 13 times the minimum width, the width ratio of the black bars / white spaces in the barcode area also needs to conform to the Code128 barcode encoding table.

[0068] As an example, the bars and spaces included in the barcode area are {3, 1, 1, 1, 2, 3}, and their sum is equal to the target width (the target width refers to the relative width with respect to the basic width unit, that is, the minimum width of the bars and spaces, which is 11 times the minimum width). By referring to the Code128 barcode encoding table, it can be obtained that the barcode area represents the number "54". Therefore, this barcode area also conforms to the Code128 encoding rule, and thus, this barcode area can be directly recognized without performing a barcode reconstruction operation.

[0069] Or, the bars and spaces included in the barcode area are {2, 3, 3, 1, 1, 1}. Although the sum of the first widths of all the bars and spaces included in this barcode area is equal to 11 times the minimum width, by referring to the Code128 barcode encoding table, it will be found that no corresponding character can be found in the Code128 barcode encoding table for this barcode area. Therefore, this barcode area does not conform to the Code128 encoding rule and cannot be directly recognized, so a barcode reconstruction operation is required.

[0070] Step S204, if the sum of the first widths is not equal to the target width, or the barcode area does not conform to the Code128 encoding rule, then reconstruct the barcode area to obtain a plurality of second areas, where the sum of the second widths of the bars and spaces in each second area is equal to the target width, and each second area conforms to the Code128 encoding rule.

[0071] In this embodiment, due to problems such as distortion, blurring, and noise in the image, there may be some barcode areas where the sum of the first widths of the bars and spaces included is not equal to the target width, or the sum of the first widths of the bars and spaces included in some barcode areas is equal to the target width, but they do not conform to the Code128 encoding rule, that is, no character matching this barcode area can be found in the Code128 barcode encoding table. At this time, a barcode reconstruction operation needs to be performed on this barcode area to obtain a plurality of second areas corresponding to the barcode area, and the sum of the second widths of the bars and spaces in each second area should be equal to the target width, and each second area should conform to the Code128 encoding rule.

[0072] Specifically, the step of "reconstructing the barcode area to obtain multiple second areas" in step S204 includes the following steps:

[0073] Step 1: Perform an addition operation on the width of the bars and spaces in the barcode area with a preset value, and then perform a rounding operation. Take the width after the addition operation and rounding operation as the second width of the bars and spaces, and obtain multiple reconstructed areas corresponding to the barcode area. Among them, each reconstructed area corresponds to a preset value.

[0074] Step 2: Select, from the multiple reconstructed areas, the reconstructed area where the sum of the second widths of each bar and space is equal to the target width and that conforms to the Code128 encoding rule as the second area.

[0075] In this embodiment, the decimal part of the width of the bars and spaces can be taken out as the preset value, or the preset value can also be set by oneself. For example, the preset value can be set to 0.5, 0.4, 0.3, 0.2, 0.1, etc. Perform an addition operation on the width of the bars and spaces with the preset value, and then perform a rounding operation. Take the width after the addition operation and rounding operation as the second width of the bars and spaces.

[0076] In addition, the integer part of the width of the bars and spaces can be taken out as the base value, and the decimal part of the width of the bars and spaces can be set as the probability value. For each bar and space, additions can be made to the base value in ascending order of each probability value to find all possible combinations where the sum of the second widths of each bar and space is equal to the target width.

[0077] It should be noted that multiple preset values can be set above. Therefore, there can also be multiple reconstructed areas corresponding to the barcode area, and each reconstructed area corresponds to a preset value. The reconstructed area where the sum of the second widths of each bar and space is equal to the target width and that conforms to the Code128 encoding rule can be selected from the multiple reconstructed areas as the second area. There can also be multiple such second areas.

[0078] Step S205: Obtain multiple barcode combinations corresponding to the barcode to be recognized according to the first area or multiple second areas corresponding to each barcode area, and select the barcode combination that conforms to the Code128 verification rule from the multiple barcode combinations as the target barcode.

[0079] In this embodiment, the step of "selecting the barcode combination that conforms to the Code128 verification rule from the multiple barcode combinations as the target barcode" in step S205 includes the following steps:

[0080] Step 1: Select the barcode combination that conforms to the Code128 verification rule from the multiple barcode combinations as the preliminary screening barcode combination.

[0081] Step 2, in the case where there is more than one pre-screened barcode combination, calculate the similarity between each pre-screened barcode combination and the barcode to be recognized.

[0082] Step 3, select the pre-screened barcode combination with the highest similarity to the barcode to be recognized from multiple pre-screened barcode combinations as the target barcode.

[0083] In this embodiment, for each barcode combination, it can be verified according to the Code128 verification rule. Specifically, the character corresponding to the verification bit area in the barcode to be recognized should be equal to (the character set ID value corresponding to the start bit area + the ID value of the first character area in the data area * 1 + the ID value of the second character area in the data area * 2 +... + the ID value of the nth character area in the data area * n) % 103.

[0084] As an example, please refer to Figure 1 , the character set ID value corresponding to the start bit a is 105, the data area b includes a total of 6 character areas, and the corresponding ID values are 12, 34, 56, 78, 90, 12 respectively. The black bar / white space width ratio of the verification bit c {3, 1, 1, 1, 2, 3} represents the number "54", and (105 + 12 * 1 + 34 * 2 + 56 * 3 + 78 * 4 + 90 * 5 + 12 * 6) % 103 = 54. Therefore, Figure 1 the Code128 barcode shown complies with the Code128 verification rule.

[0085] Since there may be a situation where there is more than one pre-screened barcode combination obtained by screening, therefore, the confidence levels of each pre-screened barcode combination can be calculated. For example, the similarity between the pre-screened barcode combination and the barcode to be recognized can be used as the confidence level:

[0086]

[0087] Among them, represents the width of the i-th bar / space in the s-th pre-screened barcode combination, and represents the width of the i-th bar / space in the barcode to be recognized, and Q is the similarity between the s-th pre-screened barcode combination and the barcode to be recognized.

[0088] Calculate the similarity between each pre-screened barcode combination and the barcode to be recognized through the above method, and then select the pre-screened barcode combination with the highest similarity to the barcode to be recognized from the pre-screened barcode combinations as the target barcode.

[0089] Then, decode each character area in the data area of the target barcode according to the Code128 barcode encoding table, and the recognition result corresponding to the barcode to be recognized can be obtained.

[0090] In the existing Code128 barcode recognition method, in the case of a blurred image scene, it is impossible to accurately segment the bars and spaces of the blurred Code128 barcode and convert them into a standard black-and-white barcode, and it is also impossible to remove some noise. It may also judge the noise part in the image as barcode content for recognition. Therefore, its recognition accuracy is relatively low, and the confidence level is insufficient, and problems such as decoding errors are likely to occur in the blurred image scene.

[0091] However, the Code128 barcode reconstruction method provided by the embodiments of the present application can improve the recognition accuracy of Code128 barcodes in scenes with blurred images and low contrast. By reconstructing and recognizing the barcode area, the recognition accuracy of Code128 barcodes in scenes with low image quality can be improved, and the recognition rate can reach more than 90% in some scene tests; in addition, the accuracy of the recognition result can be ensured. By finally calculating the confidence level and obtaining the initial screening barcode combination with the highest confidence level (i.e., the highest similarity) as the target barcode, the accuracy of the final recognition result can be improved, and in some actual scene tests, the result accuracy reaches 95%; in addition, the time cost can also be reduced. By standardizing the processing, the barcode area is closer to the actual situation, and reconstruction constraint rules can be set in the barcode reconstruction operation to reduce the possible number of barcode combinations. The reconstruction recognition time consumption in the actual scene test is less than 1 ms.

[0092] Through the above steps S201 to S205, the widths of the respective barcode regions in the barcode to be recognized are standardized, and the widths of the respective bars and spaces are rounded to obtain the first widths of the respective bars and spaces; then for the same barcode region, it is determined whether the barcode region needs to be reconstructed by judging whether the sum of the first widths of the bars and spaces it contains is equal to the target width and whether the barcode region conforms to the Code128 encoding rule; the barcode regions whose sum of the first widths of the bars and spaces they contain is not equal to the target width or does not conform to the Code128 encoding rule are reconstructed, and a plurality of barcode combinations corresponding to the barcode to be recognized are obtained based on the multiple second regions obtained by the reconstruction; finally, a barcode combination that conforms to the Code128 verification rule can be selected from the multiple barcode combinations as the target barcode. In this way, in a scenario with low image quality, multiple second regions that conform to the Code128 encoding rule can be obtained through barcode reconstruction operations, and then multiple barcode combinations that conform to the Code128 encoding rule can be obtained. Then, a barcode combination that conforms to the Code128 verification rule is selected from the multiple barcode combinations as the target barcode, which can ensure that the target barcode corresponding to the barcode to be recognized conforms to both the Code128 encoding rule and the Code128 verification rule, thereby improving the recognition accuracy of the barcode to be recognized. Through this application, the problem of low recognition accuracy of Code128 barcodes in a scenario with low image quality in the related art is solved, and the technical effect of improving the recognition accuracy of Code128 barcodes in a scenario with low image quality is achieved.

[0093] It should be understood that the magnitudes of the sequence numbers of the above steps in the above embodiments do not mean the order of execution is prior or posterior, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.

[0094] Corresponding to the Code128 barcode reconstruction method described in the above embodiments, Figure 3 The structural schematic diagram of a Code128 barcode reconstruction device according to an embodiment of the present application is shown. For the sake of convenience of description, only the parts related to the embodiments of the present application are shown.

[0095] Please refer to Figure 3, the Code128 barcode reconstruction device 3 includes: a normalization module 30 for normalizing the widths of the barcode regions in the barcode to be recognized to a target width; a calculation module 31 for rounding the widths of the bars and spaces in the barcode region to obtain the first widths of the bars and spaces; a reconstruction module 32 for, for the same barcode region, if the sum of the first widths of the bars and spaces is equal to the target width and the barcode region conforms to the Code128 encoding rule, taking the barcode region as the first region; and if the sum of the first widths is not equal to the target width or the barcode region does not conform to the Code128 encoding rule, reconstructing the barcode region to obtain a plurality of second regions, where the sum of the second widths of the bars and spaces in the second region is equal to the target width and the second region conforms to the Code128 encoding rule; a selection module 33 for obtaining a plurality of barcode combinations corresponding to the barcode to be recognized based on the first region or the plurality of second regions corresponding to each barcode region, and selecting the barcode combination that conforms to the Code128 check rule from the plurality of barcode combinations as the target barcode.

[0096] In one embodiment, the normalization module 30 is further configured to obtain the minimum width of the bars and spaces from the barcode to be recognized; and normalize the widths of the barcode regions to the target width according to the minimum width of the bars and spaces, where the target width is 11 times the minimum width, and the barcode to be recognized includes a plurality of barcode regions and an end bit region.

[0097] In one embodiment, the normalization module 30 is further configured to obtain the total width of the barcode to be recognized; obtain the total number of bars and spaces from the barcode to be recognized, where the bars and spaces include the black bars and white spaces in the barcode to be recognized; determine the number of barcode regions in the barcode to be recognized based on the total number of bars and spaces; and obtain the minimum width of the bars and spaces according to the number of barcode regions and the total width.

[0098] In one embodiment, the normalization module 30 is further configured to divide the barcode to be recognized into a plurality of barcode regions and an end bit region along a preset barcode direction according to the number of barcode regions.

[0099] In one embodiment, the normalization module 30 is further configured to divide the barcode to be recognized into a plurality of barcode regions and an end bit region along a first direction according to the number of barcode regions, and calculate the sum of the error between the width of each barcode region and the target width and the error between the end bit region and the end bit width as the first error, where the end bit width is 13 times the minimum width; divide the barcode to be recognized into a plurality of barcode regions and an end bit region along a second direction according to the number of barcode regions, and calculate the sum of the error between the width of each barcode region and the target width and the error between the end bit region and the end bit width as the second error, where the second direction forms an angle of 180° with the first direction; if the first error is less than the second error, then take the first direction as the barcode direction; otherwise, take the second direction as the barcode direction.

[0100] In one embodiment, the reconstruction module 32 is further configured to perform an addition operation on the widths of the bars and spaces in the barcode area and a rounding operation, and use the width after the addition operation and the rounding operation as the second width of the bars and spaces, so as to obtain a plurality of reconstruction areas corresponding to the barcode area, wherein each reconstruction area corresponds to a preset value; select, from the plurality of reconstruction areas, the reconstruction area where the sum of the second widths of each bar and space is equal to the target width and conforms to the Code128 encoding rule as the second area.

[0101] In one embodiment, the selection module 33 is further configured to select, from a plurality of barcode combinations, the barcode combinations that conform to the Code128 verification rule as the preliminary screening barcode combinations; in the case where the number of preliminary screening barcode combinations is more than one, calculate the similarity between each preliminary screening barcode combination and the barcode to be recognized; select, from the plurality of preliminary screening barcode combinations, the preliminary screening barcode combination with the highest similarity to the barcode to be recognized as the target barcode.

[0102] It should be noted that, for the information interaction, execution process, etc. between the above-mentioned device / units, since they are based on the same concept as the method embodiment of the present application, for the specific functions and the technical effects brought thereby, reference may be specifically made to the method embodiment part, and details are not described herein again.

[0103] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is used as an example for illustration. In practical applications, the above-mentioned functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of the present application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.

[0104] Figure 4 is a schematic structural diagram of a terminal device according to an embodiment of the present application. As Figure 4 shown, the terminal device 4 includes: at least one processor 40 ( Figure 4 only one is shown in the figure), a memory 41, and a computer program 42 stored in the memory 41 and executable on at least one processor 40. When the processor 40 executes the computer program 42, the steps in any of the above-mentioned Code128 barcode reconstruction method embodiments are implemented.

[0105] The terminal device 4 may be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The terminal device 4 may include, but is not limited to, a processor 40 and a memory 41. Those skilled in the art can understand that Figure 4 merely examples of the terminal device 4, which do not constitute a limitation on the terminal device 4, may include more or fewer components than shown in the figure, or combine certain components, or different components. For example, it may also include input / output devices, network access devices, etc.

[0106] The processor 40 may be a central processing unit (CPU), and the processor 40 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0107] The memory 41 may be an internal storage unit of the terminal device 4 in some embodiments, such as the hard disk or memory of the terminal device 4. The memory 41 may also be an external storage device of the terminal device 4 in other embodiments, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 4. In other embodiments, the memory 41 may also include both the internal storage unit and the external storage device of the terminal device 4. The memory 41 is used to store an operating system, application programs, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program 42. The memory 41 may also be used to temporarily store data that has been output or will be output.

[0108] The embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned embodiments of the Code128 barcode reconstruction method can be implemented.

[0109] An embodiment of the present application provides a computer program product. When the computer program product runs on a mobile terminal, it enables the mobile terminal to execute the steps implemented in each of the above-mentioned embodiments of the Code128 barcode reconstruction method when executed.

[0110] All or part of the processes in the above-mentioned embodiment methods of the present application can be completed by instructing relevant hardware through a computer program. This computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of each of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal, and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disc, etc.

[0111] In the above embodiments, the descriptions of each embodiment have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0112] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of the present application.

[0113] In the embodiments provided by the present application, it should be understood that the disclosed device / network device and method can be implemented in other ways. For example, the device / network device embodiments described above are only illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.

[0114] The unit described as a separation component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or may be distributed across multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0115] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A Code128 barcode reconstruction method, characterized in that, Including: Normalize the widths of the barcode regions in the barcode to be recognized to a target width; Round the widths of the bars and spaces in the barcode region to obtain the first widths of the bars and spaces; For the same barcode region, if the sum of the first widths of the bars and spaces is equal to the target width and the barcode region complies with the Code128 encoding rule, then regard the barcode region as the first region; If the sum of the first widths is not equal to the target width or the barcode region does not comply with the Code128 encoding rule, then reconstruct the barcode region to obtain a plurality of second regions, where the sum of the second widths of the bars and spaces in the second region is equal to the target width and the second region complies with the Code128 encoding rule; According to the first region or the plurality of second regions corresponding to each barcode region, obtain a plurality of barcode combinations corresponding to the barcode to be recognized, and select the barcode combination that complies with the Code128 check rule from the plurality of barcode combinations as the target barcode.

2. The method according to claim 1, wherein Normalize the widths of the barcode regions in the barcode to be recognized to a target width including: Obtain the minimum width of the bars and spaces from the barcode to be recognized; According to the minimum width of the bars and spaces, normalize the widths of the barcode regions to the target width, where the target width is 11 times the minimum width, and the barcode to be recognized includes a plurality of barcode regions and an end bit region.

3. The method according to claim 2, wherein Obtain the minimum width of the bars and spaces from the barcode to be recognized including: Obtain the total width of the barcode to be recognized; Obtain the total number of the bars and spaces from the barcode to be recognized, where the bars and spaces include the black bars and white spaces in the barcode to be recognized; Based on the total number of the bars and spaces, determine the number of the barcode regions in the barcode to be recognized; According to the number of the barcode regions and the total width, obtain the minimum width of the bars and spaces.

4. The method according to claim 3, characterized in that Before normalizing the widths of the barcode regions to the target width according to the minimum width of the bars and spaces, the method further includes: Divide the barcode to be recognized into the plurality of barcode regions and the end bit region along a preset barcode direction according to the number of the barcode regions.

5. The method according to claim 4, wherein Before dividing the barcode to be recognized into the plurality of barcode regions and the end bit region along a preset barcode direction according to the number of the barcode regions, the method further includes: Divide the barcode to be recognized into the plurality of barcode regions and the end bit region along a first direction according to the number of the barcode regions, and calculate the sum of the errors between the widths of the barcode regions and the target width and the errors between the end bit region and the end bit width as the first error, where the end bit width is 13 times the minimum width; Divide the barcode to be recognized into the multiple barcode regions and the end-bit region along the second direction according to the number of the barcode regions, and calculate the sum of the error between the width of each barcode region and the target width and the error between the end-bit region and the end-bit width as the second error, where the second direction forms an angle of 180° with the first direction; If the first error is less than the second error, then take the first direction as the barcode direction; otherwise, take the second direction as the barcode direction.

6. The method according to any one of claims 1 to 5, characterized in that, Reconstruct the barcode regions to obtain multiple second regions, including: Perform an addition operation and a rounding operation on the width of the bars and spaces in the barcode region, and take the width after the addition operation and the rounding operation as the second width of the bars and spaces, to obtain multiple reconstructed regions corresponding to the barcode region, where each reconstructed region corresponds to a preset value; Select, from the multiple reconstructed regions, the reconstructed regions where the sum of the second widths of the bars and spaces is equal to the target width and that conform to the Code128 encoding rule as the second regions.

7. The method according to any one of claims 1 to 5, characterized in that, Selecting a barcode combination that conforms to the Code128 verification rule as the target barcode from the multiple barcode combinations includes: Select a barcode combination that conforms to the Code128 verification rule from the multiple barcode combinations as a preliminary screening barcode combination; When there is more than one preliminary screening barcode combination, calculate the similarity between each preliminary screening barcode combination and the barcode to be recognized; Select, from the multiple preliminary screening barcode combinations, the preliminary screening barcode combination with the highest similarity to the barcode to be recognized as the target barcode.

8. A Code128 barcode reconstruction device, characterized in that, Including: A normalization module, configured to normalize the width of each barcode region in the barcode to be recognized to the target width; A calculation module, configured to round the width of each bar and space in the barcode region to obtain the first width of each bar and space; A reconstruction module, for the same barcode region, if the sum of the first widths of each bar and space is equal to the target width and the barcode region conforms to the Code128 encoding rule, then take the barcode region as the first region; And If the sum of the first widths is not equal to the target width, or the barcode region does not conform to the Code128 encoding rule, then reconstruct the barcode region to obtain multiple second regions, where the sum of the second widths of each bar and space in the second region is equal to the target width and the second region conforms to the Code128 encoding rule; A selection module, configured to obtain multiple barcode combinations corresponding to the barcode to be recognized according to the first region or the multiple second regions corresponding to each barcode region, and select a barcode combination that conforms to the Code128 verification rule from the multiple barcode combinations as the target barcode.

9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the Code128 barcode reconstruction method according to any one of claims 1 to 7.

10. A computer program product, characterized in that, Including a computer program which, when run, causes the Code128 barcode reconstruction method according to any one of claims 1 to 7 to be executed.