Two-dimensional code decoding method, device and equipment and readable storage medium

By obtaining the virtual and real edge information of the DM code, calculating the number of modules and combining error correction technology, the problem of low decoding accuracy of DM code in printing and industrial environments is solved, and high robustness and high accuracy decoding is achieved.

CN120337957AActive Publication Date: 2025-07-18SUNLUX IOT TECHNOLOGY (GUANGDONG) INC
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510367237.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-26
Publication Date
2025-07-18
Estimated Expiration
2045-03-26

AI Technical Summary

Technical Problem

The existing DM code decoding methods are not high in the decoding accuracy and low in printing or industrial environments due to the loss of the number of virtual edge modules.

Method used

By obtaining the virtual and real edges of the image to be decoded, the number of first modules and second modules is calculated, and error correction is performed using the Reed-Solomon error correction mechanism to ensure the robustness and accuracy of the decoding.

Benefits of technology

It improves the decoding tolerance and accuracy of DM codes in printing and industrial environments, and reduces the production management risks caused by decoding errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120337957A_ABST
    Figure CN120337957A_ABST
Patent Text Reader

Abstract

The invention discloses a two-dimensional code decoding method, apparatus and device, and a readable storage medium. The method comprises the steps of obtaining a to-be-decoded image, performing global binarization and barcode positioning on the to-be-decoded image, obtaining a virtual edge of the to-be-decoded image, obtaining a first module number of the to-be-decoded image based on the virtual edge, and decoding the to-be-decoded image based on the first module number; if decoding fails, obtaining a first real edge and a second real edge of the to-be-decoded image based on bar code positioning, and obtaining a real edge length and a module length based on the first real edge and the second real edge; and obtaining a second module number based on the real edge length and the module length, and decoding the to-be-decoded image based on the second module number. According to the method, after virtual edge positioning decoding fails, the second module number is calculated according to the length of the real edge, and decoding is carried out again, so that even if part loss or module number calculation errors are caused by printing or industrial environment factors, secondary decoding can be carried out through the real edge, and the decoding robustness and the error-tolerant rate are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of two-dimensional code decoding, and particularly to a two-dimensional code decoding method, device, equipment and readable storage medium. Background Art

[0002] The DM code (Data Matrix Code) is a two-dimensional code widely used in the industrial and printing fields. Its main features are high data density, strong damage resistance and small occupied space. The DM code has wide applications in fields such as industrial manufacturing, logistics management, electronic component identification, and medical device tracking. For example, it is used for component identification and automated management to improve production efficiency and quality traceability; it is used for product packaging and label identification to facilitate inventory management and product anti-counterfeiting; or it is used for identifying and tracking tiny electronic components to improve the efficiency of supply chain management. Although the DM code decoding technology has been relatively mature, due to the influence of the printing or industrial environment, the virtual edges of the DM code may be partially lost, resulting in incorrect calculation of the number of modules, thereby affecting the decoding accuracy.

[0003] Existing DM code decoding methods obtain the number of modules by locating the virtual edges of the DM code, and perform error correction on the DM through the Reed-Solomon error correction mechanism to complete the DM code decoding. However, in industrial and printing applications, when the number of virtual edge modules is lost, error correction decoding cannot be performed through the Reed-Solomon error correction mechanism, resulting in low decoding accuracy and low fault tolerance rate. Summary of the Invention

[0004] The present invention provides a two-dimensional code decoding method, device, equipment and readable storage medium to improve the decoding fault tolerance rate and accuracy of the DM code.

[0005] To solve the above technical problems, an embodiment of the present invention provides a two-dimensional code decoding method, including:

[0006] Obtain an image to be decoded, perform global binarization and barcode positioning on the image to be decoded, obtain the virtual edges of the image to be decoded, obtain the first number of modules of the image to be decoded based on the virtual edges, and decode the image to be decoded based on the first number of modules;

[0007] If the decoding fails, obtain the first real edge and the second real edge of the image to be decoded based on barcode positioning, and obtain the real edge length and module length based on the first real edge and the second real edge; obtain the second number of modules based on the real edge length and the module length, and decode the image to be decoded based on the second number of modules.

[0008] After the virtual edge positioning decoding fails, the present invention utilizes barcode positioning to obtain the first real edge and the second real edge, obtains the real edge length and the module length based on them, calculates the second module number, and decodes again. This enables secondary decoding through the real edge even if part is lost or the module number is calculated incorrectly due to printing or industrial environment factors, improving the robustness and error tolerance of decoding, thereby reducing the production management risks brought about by decoding errors.

[0009] Further, obtaining the first real edge and the second real edge of the image to be decoded based on real edge barcode positioning, and obtaining the real edge length and the module length based on the first real edge and the second real edge, includes:

[0010] Obtaining the binary image of the image to be decoded, performing barcode positioning based on the binary image, and obtaining the first real edge and the second real edge;

[0011] Determining the target real edge based on the first real edge and the second real edge, and determining the real edge length based on the target real edge;

[0012] Determining two corner points of the real edge and the virtual edge based on the first real edge and the second real edge, and obtaining the module length based on the two corner points.

[0013] The present invention accurately locates the real edge and its intersection points. This method can more accurately measure the actual side length and the module length, providing a basis for the accurate calculation of the subsequent module number, thereby enhancing the accuracy of the decoded data and avoiding decoding failures caused by incomplete edge information.

[0014] Further, determining the target real edge based on the first real edge and the second real edge, and determining the real edge length based on the target real edge, includes:

[0015] Comparing the lengths of the first real edge and the second real edge, and taking the longer side as the target real edge;

[0016] Determining the real edge length based on the target real edge.

[0017] The present invention compares the lengths of the two real edges and selects the longer side as the target, which can reduce the error caused by local damage or loss. The longer side usually has more complete edge information. Therefore, using this side helps to more accurately determine the module size, improving the overall decoding accuracy and stability.

[0018] Further, determining two corner points of the real edge and the virtual edge based on the first real edge and the second real edge, and obtaining the module length based on the two corner points, includes:

[0019] Determine the real-edge intersection point based on the first real edge and the second real edge, and determine the two corner points of the real edge and the virtual edge based on the real-edge intersection point and the real-edge length;

[0020] Search along a preset direction starting from the corner point. When the first module of any color is obtained, stop the search and record the search end point;

[0021] Obtain the module length based on the starting point and the search end point.

[0022] The present invention determines the boundary position between the real edge and the virtual edge, and estimates the module length by searching for the first color-inverted module, ensuring more accurate calculation of the module size and improving the accuracy of QR code decoding.

[0023] Further, obtaining the second module number based on the real-edge length and the module length, and decoding the image to be decoded based on the second module number includes:

[0024] Obtain the second module number based on the real-edge length and the module length;

[0025] Obtain black-and-white dot information based on the second module number, and convert the black-and-white dot information into binary information;

[0026] Perform data reverse operation and error correction operation on the binary information to obtain the decoding result.

[0027] The present invention decodes through the second module number measured from the real edge, which can make up for the calculation error of the module number caused by the lack of virtual edge information. At the same time, combined with the error correction technology, data reverse recovery and error correction are performed, further improving the accuracy and robustness of decoding, and providing an effective guarantee for high-reliability decoding in industrial and printing environments.

[0028] Further, after obtaining the decoding result, it further includes:

[0029] If the decoding result is decoding failure, subtract a preset first value from the second module number to obtain the third module number;

[0030] Decode the image to be decoded based on the third module number.

[0031] The present invention attempts to recover the correct data by dynamically correcting the module number. This flexible adjustment mechanism effectively improves the fault tolerance of the system in cases where edge information is severely missing or there is a lot of noise, and reduces the decoding failure rate caused by inaccurate module number estimation.

[0032] Further, the step of obtaining the image to be decoded, performing global binarization and barcode localization on the image to be decoded, obtaining the virtual edge of the image to be decoded, obtaining the first number of modules of the image to be decoded based on the virtual edge, and decoding the image to be decoded based on the first number of modules includes:

[0033] Perform global binarization on the image to be decoded to obtain a binarized image;

[0034] Perform barcode localization based on the binarized image to obtain the virtual edge of the image to be decoded;

[0035] Obtain the number of black and white module intervals of the virtual edge, and obtain the first number of modules based on the number of black and white module intervals;

[0036] Decode the image to be decoded based on the first module.

[0037] In the case of good image quality and complete virtual edge information, the present invention locates and identifies the number of modules of the image to be decoded based on the virtual edge, so as to achieve high-speed and efficient decoding according to the number of modules.

[0038] In a second aspect, the present invention provides a two-dimensional code decoding device, including: a virtual edge decoding module and a real edge decoding module;

[0039] The virtual edge decoding module is configured to obtain an image to be decoded, perform global binarization and barcode localization on the image to be decoded, obtain the virtual edge of the image to be decoded, obtain the first number of modules of the image to be decoded based on the virtual edge, and decode the image to be decoded based on the first number of modules;

[0040] The real edge decoding module is configured to, if the decoding fails, obtain the first real edge and the second real edge of the image to be decoded based on barcode localization, and obtain the real edge length and the module length based on the first real edge and the second real edge; obtain the second number of modules based on the real edge length and the module length, and decode the image to be decoded based on the second number of modules.

[0041] In a third aspect, the present invention further provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the method for decoding a two-dimensional code described above is implemented.

[0042] In a fourth aspect, the present invention further provides a computer-readable storage medium. The computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the method for decoding a two-dimensional code described above. Description of the Drawings

[0043] Figure 1Schematic flowchart of a QR code decoding method provided by an embodiment of the present invention;

[0044] Figure 2 Another schematic flowchart of a QR code decoding method provided by an embodiment of the present invention;

[0045] Figure 3 Schematic structural diagram of a QR code decoding device provided by an embodiment of the present invention. Detailed implementation manners

[0046] The following further describes in detail the specific implementation manners of the present invention in conjunction with the accompanying drawings and embodiments. The following embodiments are used to illustrate the present invention, but are not used to limit the scope of the present invention.

[0047] The terms "first" and "second" etc. in the specification, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products or devices.

[0048] Referring to "embodiment" herein means that a specific feature, structure or characteristic described in conjunction with the embodiment may be included in at least one embodiment of the present application. The phrase appears in various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0049] Embodiment 1

[0050] See Figure 1 , Figure 1 Schematic flowchart of a QR code decoding method provided by an embodiment of the present invention. An embodiment of the present invention provides a QR code decoding method, including steps 101 to 102, specifically as follows:

[0051] Step 101: Obtain an image to be decoded, perform global binarization and barcode positioning on the image to be decoded, obtain the virtual edge of the image to be decoded, obtain the first module number of the image to be decoded based on the virtual edge, and decode the image to be decoded based on the first module number;

[0052] In this embodiment, obtaining the image to be decoded, performing global binarization and barcode localization on the image to be decoded, obtaining the virtual edge of the image to be decoded, obtaining the first number of modules of the image to be decoded based on the virtual edge, and decoding the image to be decoded based on the first number of modules includes:

[0053] Performing global binarization on the image to be decoded to obtain a binarized image;

[0054] Performing barcode localization based on the binarized image to obtain the virtual edge of the image to be decoded;

[0055] Obtaining the number of black and white module intervals of the virtual edge, and obtaining the first number of modules based on the number of black and white module intervals;

[0056] Decoding the image to be decoded based on the first module.

[0057] In this embodiment, performing global binarization processing on the image to be decoded to generate a binarized image. The binarization processing classifies the image pixels into two categories (generally black and white) to facilitate subsequent barcode localization and module boundary recognition.

[0058] In this embodiment, based on the generated binarized image, using a barcode localization algorithm to analyze the image to determine the position of the barcode in the image. During the barcode localization process, using the characteristic information of the DM code to obtain the virtual edge of the DM code in the image, that is, judging the boundary of the barcode through the continuous black and white regions in the image, so as to eliminate interference information in the image and accurately extract the edge region of the QR code, laying a foundation for the calculation of the number of modules.

[0059] In this embodiment, on the obtained virtual edge, determining the number of modules by counting the number of intervals between black and white modules. Specifically, using the characteristic that black and white colors alternate on the virtual edge, by calculating the number of intervals, the first number of modules is obtained. For example, if the black and white interval is 10, the first number of modules is 10.

[0060] In this embodiment, by using the relatively stable black and white module interval information inside the virtual edge, when the image quality is high and the virtual edge information is intact, the number of modules of the DM code can be obtained more accurately, providing a basis for subsequent decoding work.

[0061] In this embodiment, according to the first number of modules, sampling the image to be decoded, that is, performing equidistant sampling at the module intervals in the image, and reading the black and white dot information at the corresponding positions. Converting the sampled black and white dot information into binary data (generally, it is agreed that black corresponds to 0 and white corresponds to 1). Performing a data reverse operation on the converted binary data, and at the same time combining a pre-set error correction rule (such as the Reed-Solomon error correction mechanism) to perform error correction, and finally obtaining the correct decoded data.

[0062] In this embodiment, by taking points at intervals of 10 * 10 with the first module number, the black and white dot information is read, and the black is assigned a value of 0, and the white is assigned a value of 1.

[0063] In this embodiment, when the virtual edge information is complete and without loss, the DM code data can be decoded quickly and accurately.

[0064] Step 102: If the decoding fails, obtain the first real edge and the second real edge of the image to be decoded based on barcode positioning, and obtain the real edge length and the module length based on the first real edge and the second real edge; obtain the second module number based on the real edge length and the module length, and decode the image to be decoded based on the second module number.

[0065] In this embodiment, the obtaining of the first real edge and the second real edge of the image to be decoded based on real edge barcode positioning, and the obtaining of the real edge length and the module length based on the first real edge and the second real edge include:

[0066] Obtain the binary image of the image to be decoded, perform barcode positioning based on the binary image, and obtain the first real edge and the second real edge;

[0067] Determine the target real edge based on the first real edge and the second real edge, and determine the real edge length based on the target real edge;

[0068] Determine two corner points of the real edge and the virtual edge based on the first real edge and the second real edge, and obtain the module length based on the two corner points.

[0069] In this embodiment, obtain the binary image of the image to be decoded, and then use the barcode positioning algorithm to process the binary image, extract the edge information within the DM code area, and then respectively locate the first real edge and the second real edge in the image.

[0070] In this embodiment, the contrast of the black and white edges in the image is improved by binarization, ensuring that the real edge information can be accurately extracted during the barcode positioning process.

[0071] In this embodiment, the determining of the target real edge based on the first real edge and the second real edge, and the determining of the real edge length based on the target real edge include:

[0072] Compare the lengths of the first real edge and the second real edge, and take the longer side as the target real edge;

[0073] Determine the real edge length based on the target real edge.

[0074] In this embodiment, based on the obtained first real edge and second real edge, by comparing their lengths, the relatively complete and longer side is determined as the target real edge. Using the target real edge, by extracting the pixel data of its continuous edge, the actual length of this edge, i.e., the real edge length, is measured.

[0075] In this embodiment, by comparing the lengths of the two real edges and selecting the longer side as the target, the error caused by local damage or missing can be reduced. The longer side usually has more complete edge information. Therefore, using this side helps to more accurately determine the module size and improve the overall decoding accuracy and stability.

[0076] In this embodiment, determining the two corner points of the real edge and the virtual edge based on the first real edge and the second real edge, and obtaining the module length based on the two corner points includes:

[0077] Determining the intersection point of the real edges based on the first real edge and the second real edge, and determining the two corner points of the real edge and the virtual edge based on the intersection point of the real edges and the real edge length;

[0078] Searching along a preset direction starting from the corner point, and stopping the search when the first module of any color is obtained, and recording the search end point;

[0079] Obtaining the module length based on the starting point and the search end point.

[0080] In this embodiment, using the obtained first real edge and second real edge, the junction of the real edge and the virtual edge, i.e., the positions of the two corner points, is further determined. Specifically, when implementing, first calculate the intersection point of the two real edges, and then determine the two corner points where the virtual edge intersects the real edge based on this. Then, starting from one of the corner points, search along the preset search direction (generally along the extending direction of the real edge) until the boundary of the first module with a color (black or white) change is found, and record the search end point. The distance between the starting point and the end point is used as the average length of a single module, i.e., the module length.

[0081] In this embodiment, by determining the intersection point of the real edge and the virtual edge and the corresponding corner points, the key information in the edge area of the DM code can be accurately captured, and the color change is used to accurately calculate the size of a single module.

[0082] In this embodiment, obtaining the second module number based on the real edge length and the module length, and decoding the image to be decoded based on the second module number includes:

[0083] Obtaining the second module number based on the real edge length and the module length;

[0084] Obtain black-and-white dot information based on the number of the second module, and convert the black-and-white dot information into binary information;

[0085] Perform data reverse operation and error correction operation on the binary information to obtain a decoding result.

[0086] In this embodiment, decoding by using the number of the second module obtained through real edge measurement can make up for the module number calculation error caused by the lack of virtual edge information. At the same time, combined with error correction technology, data reverse recovery and error correction are performed on the data, further improving the accuracy and robustness of decoding, and providing an effective guarantee for highly reliable decoding in industrial and printing environments.

[0087] In this embodiment, according to the obtained number of the second module, equidistant sampling is performed in the image along the horizontal and vertical directions of the DM code, and the black-and-white state information at the center position of each module is read. After sampling, the black-and-white states are respectively converted into binary information (usually it is agreed that black corresponds to "0" and white corresponds to "1"). In this process, a corresponding binary matrix is formed according to the determined number of modules to ensure the integrity and structure of the data.

[0088] In this embodiment, by using the number of modules re-determined based on real edges for data sampling, the accuracy of sampling points is improved, and the information loss or mis-sampling phenomenon caused by incorrect module division is reduced.

[0089] In this embodiment, for the data information converted into binary, first perform a data reverse operation (for example, reverse, decrypt or restore the original arrangement of the data according to a predetermined algorithm) to restore it to the original coding state. Subsequently, a preset error correction algorithm (such as Reed-Solomon error correction technology) is used to perform error detection and correction on the data, correct the errors introduced by image noise, sampling error or virtual edge loss, and finally extract the correct decoding result.

[0090] In this embodiment, the data reverse operation ensures that the binary sequence after module sampling can be correctly interpreted, and the error correction mechanism improves the reliability of data recovery.

[0091] In this embodiment, after obtaining the decoding result, it further includes:

[0092] If the decoding result is a decoding failure, subtract a preset first value from the number of the second module to obtain a number of the third module;

[0093] Decode the image to be decoded based on the number of the third module.

[0094] The present invention attempts to recover correct data by dynamically modifying the number of modules. This flexible adjustment mechanism effectively improves the fault tolerance of the system in cases where there is severe lack of edge information or a large amount of noise, and reduces the decoding failure rate caused by inaccurate estimation of the number of modules.

[0095] In this embodiment, after data sampling, data reversal, and error correction processing are performed using the second number of modules, a decoding result is obtained. If this decoding result meets the preset validity criteria, it is directly output; otherwise, decoding fails.

[0096] In this embodiment, if the initial decoding result is a failure, then subtract a preset first value from the second number of modules previously calculated based on the actual edge length and module length to obtain an adjusted number of modules, that is, the third number of modules.

[0097] In this embodiment, this value can be preset or dynamically adjusted according to the actual application scenario.

[0098] In this embodiment, the first value is 2.

[0099] In this embodiment, by reducing the number of modules, the oversampling problem caused by local virtual edge loss, image distortion, or excessive module interval estimation is compensated, so as to hopefully more accurately locate the actual boundary of the module.

[0100] In this embodiment, use the third number of modules as a new sampling basis to perform a sampling operation on the image to be decoded again, thereby reconstructing the black and white dot information matrix. Perform data reversal and error correction processing on the sampled binary data to obtain a new decoding result. If the decoding is successful this time, the correct data is output; if the decoding still fails, module number adjustment can be continued according to the preset strategy or decoding failure can be marked.

[0101] Please refer to Figure 2 , Figure 2 which is another flowchart of a two-dimensional code decoding method provided by an embodiment of the present invention.

[0102] In this embodiment, after the input decoded image, global binarization is performed, and then barcode localization is carried out. The number of black and white intervals of the black dotted line is used to determine the number of the first modules. For example, if the number of black and white intervals is 10, the number of modules is 10. Then, points are taken at intervals of 10 * 10 modules, and the black and white point information is read. Black is assigned a value of 0, and white is assigned a value of 1. Then the information is converted into binary form, and then the data is operated in reverse, and Reed - Solomon error correction is performed. Finally, decoding is carried out again. If the decoding is successful, a decoding success message is output. If the decoding fails, real - edge localization is performed, the lengths of the two real edges are calculated, and the lengths of the two real edges are compared. The longer real - edge length is taken as the total length of the side length. And based on the intersection of the real edge and the virtual edge, searches are carried out along two directions of the virtual edge to find the first black or white (opposite color) module. Then the average length of each module is estimated. Then, combined with the real - edge length, the real - edge length is divided by the average module length to estimate the number of the second modules. Then, the black and white point information is read through the number of modules, and then the information is converted into binary form, and then the data is operated in reverse, and Reed - Solomon error correction is performed. Finally, decoding is carried out again. If the decoding is successful, a decoding success message is output. If the decoding fails, the number of the second modules is decreased by 2, and the black and white point information is continuously read through the number of modules, and then the information is converted into binary form, and then the data is operated in reverse, and Reed - Solomon error correction is performed. Finally, decoding is carried out again. If the decoding is successful, a decoding success message is output. If the decoding fails, a decoding failure flag is output.

[0103] Please refer to Figure 3 , Figure 3 FIG. is a schematic structural diagram of a two - dimensional code decoding device provided by an embodiment of the present invention, including: a virtual - edge decoding module 301 and a real - edge decoding module 302;

[0104] The virtual - edge decoding module 301 is configured to obtain an image to be decoded, perform global binarization and barcode localization on the image to be decoded, obtain the virtual edge of the image to be decoded, obtain the number of the first modules of the image to be decoded based on the virtual edge, and decode the image to be decoded based on the number of the first modules;

[0105] The real - edge decoding module 302 is configured to, if the decoding fails, obtain the first real edge and the second real edge of the image to be decoded based on barcode localization, and obtain the real - edge length and the module length based on the first real edge and the second real edge; obtain the number of the second modules based on the real - edge length and the module length, and decode the image to be decoded based on the number of the second modules.

[0106] In an embodiment of the present invention, a terminal device is further provided, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the above - mentioned two - dimensional code decoding method is implemented.

[0107] In an embodiment of the present invention, a computer-readable storage medium is further provided. The computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the above-mentioned two-dimensional code decoding method.

[0108] Exemplarily, the computer program may be divided into one or more modules. One or more modules are stored in the memory and executed by the processor to complete the present invention. One or more modules may be a series of computer program instruction segments capable of performing specific functions, and these instruction segments are used to describe the execution process of the computer program in the terminal device.

[0109] The terminal device may be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The terminal device may include, but is not limited to, a processor, a memory, and a display. Those skilled in the art can understand that the above components are only examples of the terminal device and do not constitute a limitation on the terminal device. It may include more or fewer components than those described, or combine some components, or different components. For example, the terminal device may further include input / output devices, network access devices, a bus, etc.

[0110] The so-called processor may be a central processing unit (CPU), or 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. The processor is the control center of the terminal device and connects various parts of the entire terminal device through various interfaces and lines.

[0111] The memory can be used to store computer programs and / or modules. By running or executing the computer programs and / or modules stored in the memory, and invoking the data stored in the memory, the processor can implement various functions of the terminal device. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store the operating system, application programs required for at least one function (such as the sound playback function, text conversion function, etc.); the data storage area can store the data created according to the use of the mobile phone (such as audio data, text message data, etc.). In addition, the memory can include high-speed random access memory, and can also include non-volatile memory, such as hard disks, memory, plug-in hard disks, smart media cards (SMC), secure digital (SD) cards, flash cards, at least one magnetic disk storage device, flash memory device, or other volatile solid-state storage devices.

[0112] Among them, when the module for decoding the two-dimensional code is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above-mentioned embodiment methods of the present invention, it can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various 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 include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc. Those of ordinary skill in the art can understand and implement it without creative efforts.

[0113] The above specific embodiments have further elaborated on the purpose, technical solutions, and beneficial effects of the present invention. It should be understood that the above are only specific embodiments of the present invention and are not used to limit the protection scope of the present invention. It is particularly pointed out that for those skilled in the art, any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for decoding a two-dimensional code, characterized in that, Including: Obtain the image to be decoded, perform global binarization and barcode localization on the image to be decoded, obtain the virtual edge of the image to be decoded, obtain the first module number of the image to be decoded based on the virtual edge, and decode the image to be decoded based on the first module number; If the decoding fails, obtain the first real edge and the second real edge of the image to be decoded based on barcode localization, and obtain the real edge length and the module length based on the first real edge and the second real edge; obtain the second module number based on the real edge length and the module length, and decode the image to be decoded based on the second module number.

2. The method for decoding a two-dimensional code according to claim 1, wherein The obtaining the first real edge and the second real edge of the image to be decoded based on real edge barcode localization, and obtaining the real edge length and the module length based on the first real edge and the second real edge includes: Obtain the binarized image of the image to be decoded, perform barcode localization based on the binarized image, and obtain the first real edge and the second real edge; Determine the target real edge based on the first real edge and the second real edge, and determine the real edge length based on the target real edge; Determine two corner points of the real edge and the virtual edge based on the first real edge and the second real edge, and obtain the module length based on the two corner points.

3. The method for decoding a two-dimensional code according to claim 2, wherein The determining the target real edge based on the first real edge and the second real edge, and determining the real edge length based on the target real edge includes: Compare the lengths of the first real edge and the second real edge, and take the longer side as the target real edge; Determine the real edge length based on the target real edge.

4. The method for decoding a two-dimensional code according to claim 2, wherein The determining two corner points of the real edge and the virtual edge based on the first real edge and the second real edge, and obtaining the module length based on the two corner points includes: Determine the real edge intersection point based on the first real edge and the second real edge, and determine two corner points of the real edge and the virtual edge based on the real edge intersection point and the real edge length; Search along a preset direction starting from the corner point, stop searching when obtaining the first module of any color, and record the search end point; Obtain the module length based on the starting point and the search end point.

5. A method for decoding a two-dimensional code according to any one of claims 1 to 4, characterized in that, The obtaining the second module number based on the real edge length and the module length, and decoding the image to be decoded based on the second module number includes: Obtain the second module number based on the real edge length and the module length; Obtain the black and white dot information based on the second module number, and convert the black and white dot information into binary information; Perform data reverse operation and error correction operation on the binary information to obtain the decoding result.

6. The method for decoding a two-dimensional code according to claim 5, wherein, After obtaining the decoding result, it further includes: If the decoding result is decoding failure, subtract a preset first value from the second module number to obtain the third module number; Decode the image to be decoded based on the third module number.

7. A method for decoding a two-dimensional code according to claim 1, characterized in that, The obtaining the image to be decoded, performing global binarization and barcode localization on the image to be decoded, obtaining the virtual edge of the image to be decoded, obtaining the first module number of the image to be decoded based on the virtual edge, and decoding the image to be decoded based on the first module number includes: Perform global binarization on the image to be decoded to obtain the binarized image; Perform barcode localization based on the binarized image to obtain the virtual edges of the image to be decoded; Obtain the number of black and white module intervals of the virtual edges, and obtain the first number of modules based on the number of black and white module intervals; Decode the image to be decoded based on the first module.

8. A two-dimensional code decoding device, characterized in that, Comprising: A virtual edge decoding module and a real edge decoding module; The virtual edge decoding module is configured to obtain an image to be decoded, perform global binarization and barcode localization on the image to be decoded, obtain the virtual edges of the image to be decoded, obtain the first number of modules of the image to be decoded based on the virtual edges, and decode the image to be decoded based on the first number of modules; The real edge decoding module is configured to, if the decoding fails, obtain the first real edge and the second real edge of the image to be decoded based on barcode localization, and obtain the real edge length and the module length based on the first real edge and the second real edge; obtain the second number of modules based on the real edge length and the module length, and decode the image to be decoded based on the second number of modules.

9. A terminal device, characterized in that, Comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements a two-dimensional code decoding method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that, A computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute a two-dimensional code decoding method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and device for acquiring DM code area

    CN112069851A

  • Dot-matrix DM two-dimensional code specification determination method and related device

    CN112598100A

  • DM code decoding method, electronic equipment, storage medium and program product

    CN115879488A

  • Two-dimensional code module boundary determination method and device

    CN118228753A

  • Low-quality DM code rapid identification method based on L-type virtual edge positioning

    CN118798232A