Decoding method, device and electronic equipment for distorted barcodes
By dynamically adjusting the scanning direction and width in the distorted barcode decoding method, the problem of distorted barcodes being undecoding is solved, and efficient barcode information acquisition is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI SUMI TECH CO LTD
- Filing Date
- 2022-11-03
- Publication Date
- 2026-06-16
AI Technical Summary
Existing technologies cannot effectively decode distorted barcodes, resulting in incomplete scanning and failure to obtain barcode information.
By scanning the target barcode area, the starting sub-region is obtained. Using the vertical direction of the texture direction of the previous sub-region as a reference, the scanning direction and width of the next sub-region are determined. The scanning position is dynamically adjusted to adapt to the distortion, and the barcode is decoded in combination with the encoding rules.
It achieves complete scanning and decoding of distorted barcodes, improving the scanning experience, and the calculation process is simple and requires little computation.
Smart Images

Figure CN115688826B_ABST
Abstract
Description
Technical Field
[0001] This invention relates primarily to the field of barcode recognition technology, and more particularly to a method, apparatus, and electronic device for decoding distorted barcodes. Background Technology
[0002] A barcode is a graphic identifier that uses multiple black bars and spaces of varying widths arranged according to specific encoding rules to represent a set of information. Common barcodes consist of parallel lines with significantly different reflectivities: black bars (simply called bars) and white spaces (simply called spaces). Barcodes can indicate information such as the country of origin, manufacturer, product name, production date, book classification number, mail origin and destination, category, and date, and are therefore widely used in many fields such as commodity circulation, library management, postal management, and banking systems.
[0003] Barcodes on some packaging bags are prone to distortion, wrinkling, and deformation. In existing technology, to obtain barcode information, the information is typically calculated by scanning all the bars and spaces along the scan lines. When distortion exists, no single scan line can completely scan all the bars and spaces of the barcode image, making effective decoding impossible.
[0004] For example, one method involves scanning a one-dimensional barcode image using multiple parallel scan lines, identifying the bar-space boundary points on each scan line, and matching these boundary points on adjacent scan lines to distinguish between contaminated and uncontaminated areas. Multiple uncontaminated areas are then combined to obtain the scanning information of the one-dimensional barcode image. This scanning method, based on matching the boundary points of adjacent parallel scan lines, relies heavily on the parallel scan lines and their coordinates, making it difficult to handle distorted barcodes. Another method involves dividing the folded barcode into regions, rotating each segment to a vertical orientation, and then stitching them together for decoding. However, this decoding method involves multiple rotations and stitching, which is complex, time-consuming, and prone to errors. Therefore, existing barcode decoding methods cannot completely scan all the bars and spaces of the barcode image, making effective decoding impossible. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a method, apparatus and electronic device for decoding distorted barcodes, so as to solve the problem that all bars and spaces of the barcode image cannot be completely scanned and the barcode cannot be effectively decoded.
[0006] To address the aforementioned technical problems, in a first aspect, the present invention provides a method for decoding distorted barcodes, comprising: scanning a target barcode region to obtain a starting sub-region; wherein the starting sub-region is a sub-region containing a start character or end character whose bar-to-space width ratio satisfies a specified requirement; starting from the starting sub-region, determining a scanning direction for the next sub-region with reference to the direction perpendicular to the texture direction of the previous sub-region; starting from the starting sub-region, determining a scanning width for the next sub-region with reference to the scanning width of the previous sub-region; and scanning the codeword information of the next sub-region with the determined scanning direction and scanning width.
[0007] Optionally, scanning the target barcode area to obtain the starting sub-region includes: scanning the target barcode area to obtain the bar width information of each scan line; normalizing the obtained bar width information to obtain the proportional relationship of each bar width; and obtaining the sub-region whose bar width ratio satisfies the start symbol or the end symbol according to the encoding rules.
[0008] Optionally, scanning the target barcode area to obtain the starting sub-region includes: scanning the target barcode area at multiple intervals to obtain the starting sub-region.
[0009] Optionally, the method further includes: determining the texture direction of the previous sub-region.
[0010] Optionally, determining the texture direction of the previous sub-region includes: selecting a rectangular region and dividing the rectangular region into several M×N pixel-sized modules; using the Sobel operator as a template for discrete convolution, calculating the gradient G of each pixel within each module in the horizontal and vertical directions. x (i,j) and G y (i,j); calculate the direction θ of each module. k The formula is as follows:
[0011]
[0012] The maximum response intensity value is selected as the texture direction of the rectangular region, where the maximum response intensity value represents the direction that appears most frequently.
[0013] Optionally, θ k The value range is -90 to 90, and according to θ k The size of the angle with the horizontal direction will be θ k Normalized to 0-90.
[0014] Optionally, the method further includes: determining the scan width of the previous sub-region.
[0015] Optionally, determining the scan width of the previous sub-region includes: scanning the sub-region multiple times with a plurality of parallel, spaced scan lines until the start symbol or the end symbol cannot be scanned; determining the start point and end point of each scan line that can scan the start symbol or the end symbol; and using the width between the midpoint of the line connecting all the start points and the midpoint of the line connecting all the end points as the scan width of the sub-region.
[0016] Optionally, determining the scan width of the next sub-region with reference to the scan width of the previous sub-region includes: extending the scan line width of the previous sub-region by a certain number of pixels to obtain the scan line width of the next sub-region.
[0017] Optionally, if more than a predetermined number of codewords satisfying the encoding rules are found in the currently scanned sub-region, the scanning ends.
[0018] Optionally, before scanning the target barcode region and obtaining the starting sub-region, the method further includes: using a gradient detection algorithm to cluster the target barcode region.
[0019] Optionally, the method further includes: combining the codeword information of each scanned sub-region, and according to the encoding rules, combining the codeword information in sequence; if the verification passes, then decoding the combined codeword information.
[0020] Optionally, the method further includes: if decoding the combined codeword information fails, then continuing to detect the next starting sub-region.
[0021] Secondly, the present invention provides a decoding device for a distorted barcode, comprising: an acquisition module for scanning a target barcode area to acquire a starting sub-region; wherein the starting sub-region is a sub-region containing a start character or an end character whose bar-to-space width ratio satisfies a specified condition; a first determination module for determining a scanning direction of the next sub-region, starting from the starting sub-region and with reference to a direction perpendicular to the texture direction of the previous sub-region; a second determination module for determining a scanning width of the next sub-region, starting from the starting sub-region and with reference to the scanning width of the previous sub-region; and a scanning module for scanning the codeword information of the next sub-region using the determined scanning direction and scanning width.
[0022] Optionally, it further includes a decoding module, which is used to combine the codeword information of each scanned sub-region, and according to the encoding rules, combine the codeword information in sequence. If the verification passes, the combined codeword information is decoded.
[0023] Thirdly, the present invention provides an electronic device comprising: a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps of the method for decoding distorted barcodes as described in the first aspect.
[0024] Fourthly, the present invention provides a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method for decoding distorted barcodes as described in the first aspect.
[0025] Compared with the prior art, the present invention has the following advantages: After determining the start or end symbol of the barcode, starting from the starting sub-region, the scanning direction of the next sub-region is determined with reference to the direction perpendicular to the texture direction of the previous sub-region, and the scanning width of the next sub-region is determined with reference to the scanning width of the previous sub-region. Then, the code information of the next sub-region is scanned with the determined scanning direction and scanning width. By continuously and dynamically adjusting the scanning position, the entire barcode area is scanned, which can flexibly adapt to various distorted barcode situations. Moreover, the calculation process is simple and the amount of computation is small, which greatly improves the scanning experience in practical application scenarios. Attached Figure Description
[0026] The accompanying drawings are included to provide a further understanding of this application; they are incorporated into and constitute a part of this application. The drawings illustrate embodiments of this application and, together with this specification, serve to explain the principles of this application. In the drawings:
[0027] Figure 1 This is a schematic diagram of the general format of the Code 128 barcode symbol;
[0028] Figure 2 This is a flowchart illustrating a method for decoding a distorted barcode according to an embodiment of the present invention;
[0029] Figure 3 This is a schematic diagram of the Code 128 barcode with the start symbol "START A";
[0030] Figure 4 This is a schematic diagram of segmented scanning of a method for decoding distorted barcodes in one embodiment of the present invention;
[0031] Figure 5 This is a diagram illustrating the result of obtaining the barcode texture direction in one embodiment of the present invention;
[0032] Figure 6 This is a schematic diagram of the structure of a decoding device for a distorted barcode according to an embodiment of the present invention;
[0033] Figure 7This is another structural schematic diagram of a decoding device for distorted barcodes according to an embodiment of the present invention;
[0034] Figure 8 This is a schematic diagram of the structure of an electronic device provided by the present invention. Detailed Implementation
[0035] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are merely some examples or embodiments of this application. For those skilled in the art, these drawings can be applied to other similar scenarios without creative effort. Unless obvious from the context or otherwise specified, the same reference numerals in the drawings represent the same structures or operations.
[0036] As indicated in this application and claims, unless the context clearly indicates otherwise, the words "a," "an," "an," and / or "the" are not specifically singular and may include plural forms. Generally speaking, the terms "comprising" and "including" only indicate the inclusion of explicitly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements.
[0037] Unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps described in these embodiments do not limit the scope of this application. It should also be understood that, for ease of description, the dimensions of the various parts shown in the drawings are not drawn to actual scale. Techniques, methods, and devices known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and devices should be considered part of the specification. In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values. It should be noted that similar reference numerals and letters in the following drawings denote similar items; therefore, once an item is defined in one drawing, it need not be further discussed in subsequent drawings.
[0038] Furthermore, it should be noted that the use of terms such as "first" and "second" to define components is merely for the purpose of distinguishing the corresponding components. Unless otherwise stated, these terms have no special meaning and therefore should not be construed as limiting the scope of protection of this application. In addition, although the terminology used in this application is selected from commonly known and used terms, some terms mentioned in this application's specification may have been chosen by the applicant according to his or her judgment, and their detailed meanings are explained in the relevant sections of this description. Moreover, this application should be understood not only through the actual terms used, but also through the meaning implied by each term.
[0039] Flowcharts are used in this application to illustrate the operations performed by the system according to embodiments of this application. It should be understood that the preceding or following operations are not necessarily performed in exact order. Instead, various steps can be processed in reverse order or simultaneously. Furthermore, other operations may be added to these processes, or one or more steps may be removed from these processes.
[0040] Example 1
[0041] Figure 1 This is a schematic diagram of the general format of the Code 128 barcode symbol. (See reference) Figure 1 A complete one-dimensional barcode consists of blank areas on both sides, a start character, data characters, a check character, and a stop character. It arranges multiple black bars and spaces of varying widths according to certain encoding rules to express a set of information.
[0042] Figure 2 This is a flowchart illustrating a method for decoding distorted barcodes according to an embodiment of the present invention. (Refer to...) Figure 2 Method 200 can be used for scanning and recognizing Code 128 barcodes, and can also be used for scanning and recognizing other related barcodes, without limitation, including:
[0043] S210. Scan the target barcode area to obtain the starting sub-region; wherein the starting sub-region is the sub-region where the start character or end character is located if the bar width ratio meets the specified requirements.
[0044] In barcode recognition, light (scanning lines) is shone onto the barcode. The "spaces" on the barcode reflect light highly, while the "bars" reflect light less. The reflected light is focused by a lens (i.e., isolated by a grating) and received by a photosensitive element, resulting in a set of high and low voltage signals. This signal is then converted into a digital signal by a decoding device, allowing the barcode to be recognized. Therefore, barcode recognition first requires identifying the barcode area and then performing the recognition. During the scanning process, the primary task is to identify the start or end character. Different start or end characters characterize the barcode's encoding method and type; therefore, identifying the start or end character is crucial. Taking the UCC / EAN-128 barcode as an example, each barcode character (excluding the stop character) consists of 6 units (11 modules), including 3 bars and 3 spaces. The width of each bar or space is 1 to 4 modules. The stop character consists of 4 bars and 3 spaces, totaling 7 units (13 modules). In this embodiment, after scanning the barcode area, the bar width information of this area can be obtained. The bar width ratio of the start character or end character of different encoding rules is unique. Therefore, the start character or end character can be determined by the bar width ratio. The area (sub-region) where the start character or end character is located is the start sub-region.
[0045] In some implementations, before scanning the target barcode region and obtaining the initial sub-region, a gradient detection algorithm can be used to cluster the target barcode region. Because barcodes have strong texture features, i.e., consistent gradient directions in local regions, the gradient detection algorithm can be used to cluster the target barcode region, which is then used for further barcode detection.
[0046] In some implementations, scanning the target barcode area to obtain the starting sub-region can be done as follows: First, scan the target barcode area to obtain the bar / space width information for each scan line; then, normalize the obtained bar / space width information to obtain the proportional relationship of each bar / space width. Normalization means using the minimum bar / space width as a base width of 1, and using the multiples of the base width for other bar / space widths as the normalized widths; finally, according to the encoding rules, obtain the sub-regions whose bar / space width ratios satisfy the start or end symbol. For example, the target barcode area is scanned horizontally and vertically to obtain the bar / space width information for each scan line, then the width information is normalized, and then, according to the encoding rules, the positions where the bar / space width ratios satisfy the start or end symbol are detected. Figure 3 As shown, Figure 3This is a structural diagram of a Code 128 barcode with the start symbol "START A". The start symbol A consists of 6 units and 11 modules, including 3 bars and 3 spaces. In a barcode character, the number of bar modules is even, and the number of space modules is odd. This parity characteristic ensures the self-verification function of the barcode character. Based on the above characteristics of the start symbol, when an area that meets the conditions of this start symbol is scanned, the starting sub-region of the current scan can be obtained.
[0047] In some implementations, scanning the target barcode area to obtain the starting sub-region can be achieved by scanning the target barcode area at intervals of multiple rows. This scanning method eliminates the need to scan the target barcode area continuously, row by row. Provided the starting sub-region can be effectively obtained, scanning the target barcode area at intervals can accelerate the detection speed of barcode-related areas.
[0048] S220. Starting from the initial sub-region, with reference to the direction perpendicular to the texture direction of the previous sub-region, determine the scanning direction of the next sub-region.
[0049] In this embodiment, for cases of barcode distortion, the positions of each codeword region and the start or end character region are not necessarily aligned, so subsequent scanning requires adjustment of the scanning direction. Although the barcode identified in this embodiment exhibits distortion, adjacent sub-regions still maintain a certain continuity. Therefore, the scanning direction of the next sub-region can be determined by using the direction perpendicular to the texture direction of the previous sub-region as a reference. In this embodiment, the "reference" can be the direction perpendicular to the texture direction of the previous sub-region as the scanning direction of the next sub-region, or it can be an adjustment based on the direction perpendicular to the texture direction of the previous sub-region, such as adaptively shifting the scanning direction according to the actual scanning situation, and then using the adjusted scanning direction as the scanning direction of the next sub-region.
[0050] In some implementations, the texture direction of the previous sub-region is determined so that it can be used to subsequently determine the scanning direction of the next sub-region with reference to the direction perpendicular to the texture direction of the previous sub-region. For example, referencing Figure 4 , Figure 4 This is a segmented scanning schematic diagram of a decoding method for a distorted barcode in one embodiment of the present invention. The distorted barcode shown is divided into ten sub-regions, S0 to S9, where the S0 sub-region represents the start symbol sub-region. The scanning direction of the S1 sub-region is determined as follows:
[0051] 1) Define a rectangular region for calculating the direction of the sub-region, as follows:
[0052] refer to Figure 4 Connect the two endpoints of all scan lines in the currently scanned sub-region into a single line segment, such as...Figure 4 For line segment AB, first calculate the angle between line segment AB and the horizontal direction. If the angle is no more than 45 degrees, extend the line segment AB vertically by a certain length with A and B as midpoints. The length of the extension is the length of line segment AB. If the angle is greater than 45 degrees, extend the line segment AB horizontally by a certain length with A and B as midpoints. Then, use the two extended lines as two opposite sides of a rectangle to form a minimum bounding rectangle region R. If the rectangular region R exceeds the boundary of the image (including the area containing the barcode) within the region, then take the intersection of the rectangular region R and the actual image.
[0053] 2) Divide the rectangular region R into several M×N pixel modules;
[0054] 3) Two 3×3 Sobel operators are used as templates for discrete convolution, and the gradient G of each pixel in each module in the horizontal and vertical directions is calculated. x (i,j) and G y (i,j);
[0055] 4) Calculate the direction of each module, that is, the direction θ of the k-th module. k The calculation formula is:
[0056]
[0057] 5)θ k The value range of θ is -90 to 90, and θ is determined according to the angle with the horizontal direction. k Normalized to 0–90;
[0058] 6) Divide the range 0 to 90 into t intervals. For example, when t = 9, the angles between 0 and 10 degrees can be unified into the same direction 1, the angles between 10 and 20 degrees can be unified into the same direction 2, and so on. Then, statistically select the maximum response intensity value as the texture direction of the rectangular region. Figure 5 As shown, Figure 5 The left side shows the constructed rectangular region R divided into several modules. Figure 5 The right side shows the orientations of several modules corresponding to the rectangular region R. The maximum response intensity value is selected as the texture orientation of the rectangular region R. The perpendicular direction of the texture orientation of the sub-region is the codeword scanning direction of the next sub-region.
[0059] S230. Starting from the initial sub-region, and taking the scan width of the previous sub-region as a reference, determine the scan width of the next sub-region.
[0060] Each barcode has a corresponding encoding rule, therefore the scanning width of each codeword has continuity and reference value. The scanning width of the next sub-region can be determined by using the scanning width of the previous sub-region as a reference. In this embodiment, "reference" can be the scanning width of the previous sub-region as the scanning width of the next sub-region, or it can be the scanning width adjusted based on the scanning width of the previous sub-region. The scanning width of the next region can be adaptively increased or decreased according to the actual scanning situation.
[0061] In some implementations, the scan width of the previous sub-region is determined so that the scan width of the next sub-region can be determined with reference to the scan width of the previous sub-region.
[0062] In some implementations, determining the scan width of the previous sub-region can be done by first scanning the sub-region multiple times with several parallel, spaced scan lines until no start or end symbol can be scanned; then determining the start and end points of each scan line that can scan the start or end symbol; and finally using the width between the midpoint of the line connecting all start points and the midpoint of the line connecting all end points as the scan width of the sub-region.
[0063] For example, refer to Figure 4 The system scans horizontally along the detected start symbol position, using multiple parallel scan lines spaced P pixels apart (e.g., P=2). When no start or end symbol is detected, all scan lines that could have detected either symbol are recorded. The midpoint of the line connecting the start points of all scan lines is designated as point A, and the midpoint of the line connecting the end points of all scan lines is designated as point B. The length of line segment AB is then used as the scan width of this sub-region. Using the width of line segment AB as a reference, the scan width of the next sub-region can be determined.
[0064] In some implementations, the scan width of the next sub-region is determined with reference to the scan width of the previous sub-region. This can be achieved by extending the scan line width of the previous sub-region by a certain number of pixels. For example, referencing... Figure 4 Using the end position B of the current scan line and the scan line length AB as a reference, extend the scan line along the direction determined by the previous sub-region by a few pixels at the beginning and end, denoted as points A′ and B′ respectively, as the initial scan line for the next codeword. Then, using scan line A′B′ as the starting scan line, continue scanning and detecting codewords that satisfy the encoding rules with a gap of P pixels between each subsequent scan line, until no codewords are detected. Finally, the width between the midpoint of the line connecting all starting points and the midpoint of the line connecting all ending points is taken as the scan width of this sub-region.
[0065] In some implementations, scanning ends if more than a predetermined number of codewords satisfying the encoding rules are detected in the currently scanned sub-region. To speed up detection, multiple scans on both sides can terminate early if more than a certain number C (e.g., C=3) of codewords satisfying the encoding rules are detected. To avoid errors, the number of codewords detected, C>=3, is generally used.
[0066] S240, Scan the codeword information of the next sub-region with the determined scanning direction and scanning width.
[0067] The codeword information of the next sub-region can be scanned based on the scanning direction determined in step S220 and the scanning width determined in step S230.
[0068] In some implementations, the codeword information from each scanned sub-region is combined sequentially according to encoding rules. If the verification passes, the combined codeword information is decoded. In this embodiment, the codeword information for each sub-region is recorded and statistically analyzed, with the codeword information for each sub-region based on the codeword that has been detected most frequently.
[0069] In some implementations, if decoding of the combined codeword information fails, the next starting sub-region is detected. This embodiment utilizes the inherent characteristics of barcodes, employing a "segmented bridging method" for dynamically adjusting the scanning of codeword segments. After determining the barcode start or end symbol, based on information about the area containing the currently scanned group of codewords, such as codeword length and barcode texture direction, the scanning direction and scanning width (scanning range) of the next group of codewords are determined. By continuously and dynamically adjusting the scanning position, the entire barcode area is scanned.
[0070] The distorted barcode decoding method provided in this embodiment continuously and dynamically adjusts the scanning position to scan the entire barcode area, flexibly adapting to various distorted barcode situations. Moreover, the calculation process is simple and the amount of computation is small, greatly improving the scanning experience in practical application scenarios.
[0071] Example 2
[0072] Figure 6 This is a schematic diagram of the structure of a decoding device for distorted barcodes according to an embodiment of the present invention. (Refer to...) Figure 6 The device 600 shown mainly includes:
[0073] The acquisition module 601 is used to scan the target barcode area and acquire the starting sub-region; wherein the starting sub-region is the sub-region where the start character or end character is located if the bar width ratio meets the specified requirements.
[0074] In some implementations, the target barcode area is scanned to obtain the starting sub-region, which includes the scanned target barcode area, and the bar and space width information of each scan line is obtained; the obtained bar and space width information is normalized to obtain the proportional relationship of each bar and space width; and according to the encoding rules, the sub-region whose bar and space width ratio satisfies the start character or end character is obtained.
[0075] In some implementations, the target barcode area is scanned at intervals of multiple rows to obtain the starting sub-region.
[0076] In some implementations, determining the scan width of the previous sub-region can be achieved by scanning the sub-region multiple times with several parallel, spaced scan lines until no start or end symbol is detected; determining the start and end points of each scan line that can detect the start or end symbol; and using the width between the midpoint of the line connecting all start points and the midpoint of the line connecting all end points as the scan width of the sub-region.
[0077] In some implementations, the target barcode region is clustered using a gradient detection algorithm before scanning the target barcode region to obtain the starting sub-region.
[0078] The first determining module 602 is used to determine the scanning direction of the next sub-region, starting from the initial sub-region and taking the direction perpendicular to the texture direction of the previous sub-region as a reference.
[0079] In some implementations, the texture direction of the previous sub-region is also determined.
[0080] The second determining module 603 is used to determine the scanning width of the next sub-region, starting from the starting sub-region and taking the scanning width of the previous sub-region as a reference.
[0081] In some implementations, the scanning width of the previous sub-region is also determined.
[0082] In some implementations, the scan line width of the next sub-region is obtained by extending the scan line width of the previous sub-region by several pixels.
[0083] The scanning module 604 is used to scan the codeword information of the next sub-region in the determined scanning direction and scanning width.
[0084] In some implementations, if more than a predetermined number of codewords satisfying the encoding rules are found in the currently scanned sub-region, the scanning ends.
[0085] In some implementations, such as Figure 7As shown, the device 600 may further include a decoding module 701, which is used to combine the codeword information of each scanned sub-region, and according to the encoding rules, combine the codeword information in sequence. If the verification passes, the combined codeword information is decoded.
[0086] In some implementations, if decoding of the combined codeword information fails, the next starting sub-region is detected.
[0087] For details of other operations performed by each module in this embodiment, please refer to the previous embodiment, which will not be elaborated here.
[0088] The distorted barcode decoding device provided in this embodiment continuously and dynamically adjusts the scanning position to scan the entire barcode area, flexibly adapting to various distorted barcode situations. Moreover, the calculation process is simple and the amount of computation is small, greatly improving the scanning experience in practical application scenarios.
[0089] The distorted barcode decoding device in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The distorted barcode decoding device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0090] like Figure 8 As shown, this application embodiment also provides an electronic device 800, including a processor 801, a memory 802, and a program or instructions stored in the memory 802 and executable on the processor 801. When the program or instructions are executed by the processor 801, they implement the various processes of the above-described distorted barcode decoding method embodiment and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0091] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described distorted barcode decoding method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0092] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0093] A computer-readable medium may contain a propagated data signal containing computer program code, for example, on baseband or as part of a carrier wave. This propagated signal may take various forms, including electromagnetic, optical, and so on, or suitable combinations thereof. A computer-readable medium can be any computer-readable medium other than a computer-readable storage medium, which can be connected to an instruction execution system, apparatus, or device to enable communication, propagation, or transmission of a program for use. The program code located on the computer-readable medium can be propagated through any suitable medium, including radio, cable, fiber optic cable, radio frequency signals, or similar media, or any combination of the above media.
[0094] For those skilled in the art, the above disclosure is merely illustrative and does not constitute a limitation of this application. Although not explicitly stated herein, those skilled in the art may make various modifications, improvements, and corrections to this application. Such modifications, improvements, and corrections are suggested in this application and therefore remain within the spirit and scope of the exemplary embodiments of this application.
[0095] Furthermore, this application uses specific terms to describe embodiments of the application. For example, "an embodiment," "one embodiment," and / or "some embodiments" refer to a particular feature, structure, or characteristic related to at least one embodiment of the application. Therefore, it should be emphasized and noted that "an embodiment," "one embodiment," or "an alternative embodiment" mentioned twice or more in different locations in this specification do not necessarily refer to the same embodiment. In addition, certain features, structures, or characteristics in one or more embodiments of the application can be appropriately combined.
[0096] Some aspects of this application can be executed entirely by hardware, entirely by software (including firmware, resident software, microcode, etc.), or by a combination of hardware and software. The aforementioned hardware or software may be referred to as a "data block," "module," "engine," "unit," "component," or "system." The processor may be one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DAPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, or combinations thereof. Furthermore, aspects of this application may manifest as computer products residing in one or more computer-readable media, including computer-readable program code. For example, computer-readable media may include, but are not limited to, magnetic storage devices (e.g., hard disks, floppy disks, magnetic tapes, etc.), optical discs (e.g., compressed CDs, digital multifunction DVDs, etc.), smart cards, and flash memory devices (e.g., cards, sticks, key drives, etc.).
[0097] Similarly, it should be noted that, in order to simplify the description of the present application and thus aid in the understanding of one or more embodiments of the invention, the foregoing description of the embodiments of the present application sometimes combines multiple features into a single embodiment, drawing, or description thereof. However, this disclosure method does not imply that the subject matter of the application requires more features than those mentioned in the claims. In fact, the embodiments contain fewer features than all the features of the single embodiments disclosed above.
[0098] In some embodiments, numbers describing the quantity of components and attributes are used. It should be understood that such numbers used in the description of embodiments are modified in some examples with the terms "approximately," "approximately," or "generally." Unless otherwise stated, "approximately," "approximately," or "generally" indicates that the numbers are allowed to vary by ±20%. Accordingly, in some embodiments, the numerical parameters used in the specification and claims are approximate values, which may be changed depending on the characteristics required by individual embodiments. In some embodiments, numerical parameters should take into account specified significant digits and employ a general method of digit reservation. Although the numerical ranges and parameters used to confirm their breadth of scope in some embodiments of this application are approximate values, in specific embodiments, such values are set as precisely as feasible.
[0099] Although this application has been described with reference to specific embodiments, those skilled in the art should recognize that the above embodiments are only used to illustrate this application, and various equivalent changes or substitutions can be made without departing from the spirit of this application. Therefore, any changes or modifications to the above embodiments within the essential spirit of this application will fall within the scope of the claims of this application.
Claims
1. A method for decoding distorted barcodes, characterized in that, include: Scan the target barcode area to obtain the starting sub-region; The starting sub-region is the sub-region containing the start or end symbol whose width-to-width ratio meets the specified requirement; Starting from the initial sub-region, the scanning direction of the next sub-region is determined with reference to the direction perpendicular to the texture direction of the previous sub-region; Starting from the initial sub-region, the scanning width of the next sub-region is determined with reference to the scanning width of the previous sub-region; The codeword information of the next sub-region is scanned according to the determined scanning direction and scanning width.
2. The decoding method for distorted barcodes as described in claim 1, characterized in that, Scan the target barcode area to obtain the starting sub-region, including: Scan the target barcode area to obtain the bar width information for each scanned line; The obtained space width information is normalized to obtain the proportional relationship of each space width; According to the encoding rules, obtain the sub-regions whose bar-to-space width ratio satisfies the start character or the end character.
3. The decoding method for distorted barcodes as described in claim 1, characterized in that, Scan the target barcode area to obtain the starting sub-region, including: The target barcode area is scanned at intervals to obtain the starting sub-region.
4. The decoding method for distorted barcodes as described in claim 1, characterized in that, The method further includes: determining the texture direction of the previous sub-region.
5. The decoding method for distorted barcodes as described in claim 4, characterized in that, Determining the texture direction of the previous sub-region includes: Select a rectangular area and divide the rectangular area into several modules of size M×N pixels; Using the Sobel operator as a template for discrete convolution, the gradient G of each pixel within each module is calculated in the horizontal and vertical directions. x (i,j) and G y (i,j); Calculate the direction θ of each module k The formula is as follows: The maximum response intensity value is selected as the texture direction of the rectangular region, where the maximum response intensity value represents the direction that appears most frequently.
6. The decoding method for distorted barcodes as described in claim 5, characterized in that, θ k The value range is -90 to 90, and according to θ k The size of the angle with the horizontal direction will be θ k Normalized to 0-90.
7. The decoding method for distorted barcodes as described in claim 1, characterized in that, The method further includes: determining the scan width of the previous sub-region.
8. The decoding method for the distorted barcode according to claim 7, characterized in that, Determining the scan width of the previous sub-region includes: A number of parallel, spaced scan lines are used to scan the sub-region multiple times until the start symbol or the end symbol can no longer be scanned. Determine the start and end points of each scan line that can be scanned to the start symbol or the end symbol; The width between the midpoint of the line connecting all the starting points and the midpoint of the line connecting all the ending points is taken as the scan width of the sub-region.
9. The decoding method for distorted barcodes as described in claim 1, characterized in that, Using the scan width of the previous sub-region as a reference, the scan width of the next sub-region is determined by including: The scan line width of the next sub-region is the scan line width obtained by extending the scan line width of the previous sub-region by a certain number of pixels.
10. The decoding method for distorted barcodes as described in claim 1, characterized in that, If more than a predetermined number of codewords satisfying the encoding rules are found in the currently scanned sub-region, the scanning ends.
11. The decoding method for distorted barcodes as described in claim 1, characterized in that, Before scanning the target barcode region and obtaining the starting sub-region, the method further includes: using a gradient detection algorithm to cluster the target barcode region.
12. The decoding method for distorted barcodes as described in claim 1, characterized in that, The method further includes: Based on the codeword information of each scanned sub-region, the codeword information is combined sequentially according to the encoding rules. If the verification passes, the combined codeword information is decoded.
13. The decoding method for distorted barcodes as described in claim 12, characterized in that, The method further includes: if decoding the combined codeword information fails, then continue to detect the next starting sub-region.
14. A decoding device for distorted barcodes, characterized in that, include: The acquisition module is used to scan the target barcode area and acquire the starting sub-region; wherein the starting sub-region is the sub-region where the start character or end character meets the specified bar-to-space width ratio. The first determining module is used to determine the scanning direction of the next sub-region, starting from the initial sub-region and taking the direction perpendicular to the texture direction of the previous sub-region as a reference. The second determining module is used to determine the scanning width of the next sub-region, starting from the initial sub-region and taking the scanning width of the previous sub-region as a reference. The scanning module is used to scan the codeword information of the next sub-region in a determined scanning direction and scanning width.
15. The decoding apparatus for a twisted barcode as described in claim 14, characterized in that, Also includes: The decoding module is used to combine the codeword information of each scanned sub-region, and according to the encoding rules, combine the codeword information in sequence. If the verification is successful, the combined codeword information is decoded.
16. An electronic device, characterized in that, include: A processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps of the method for decoding a distorted barcode as described in any one of claims 1-13.
17. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the method for decoding distorted barcodes as described in any one of claims 1-13.