Two-dimensional code recognition method, storage medium and computer

By using adaptive threshold segmentation and affine transformation to convert low-quality QR codes into standard QR codes, the problem of low recognition accuracy of low-quality QR codes is solved, and higher recognition and decoding accuracy and robustness are achieved.

CN114692661BActive Publication Date: 2025-11-04DSTEK CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011581643.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-28
Publication Date
2025-11-04
Estimated Expiration
2040-12-28

AI Technical Summary

Technical Problem

Low-quality QR codes suffer from reduced recognition and decoding accuracy due to factors such as uneven printing, wear, obstruction, and poor lighting conditions.

Method used

The QR code image is converted into a binary image by adaptive threshold segmentation, the four vertices are located, the affine transformation matrix is ​​calculated, the image is converted into a regular rectangle, the two-dimensional grid is divided using the gray-level gradient change law, and the standard QR code is redrawn for reading and decoding.

Benefits of technology

It improves the accuracy of recognizing and decoding low-quality QR codes and enhances the robustness of recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114692661B_ABST
    Figure CN114692661B_ABST
Patent Text Reader

Abstract

The application provides a two-dimensional code recognition method, a storage medium and a computer. The method comprises the following steps: converting a detection image comprising a two-dimensional code into a binary image through adaptive threshold segmentation; locating four vertices of the two-dimensional code in the binary image according to features of various two-dimensional codes; calculating an affine transformation matrix based on the four vertices of the two-dimensional code to convert the two-dimensional code in the detection image and the binary image of the two-dimensional code into a right rectangle; dividing the two-dimensional code of the right rectangle to form a two-dimensional grid according to a gray gradient variation rule; obtaining information of each sampling grid being "0" or "1" based on a gray mean value of each sampling grid in the two-dimensional grid; redrawing a standard two-dimensional code composed of black and white data blocks according to the information of each sampling grid in the two-dimensional grid; and performing code reading and decoding on the standard two-dimensional code. Thus, the code recognition and decoding accuracy of low-quality two-dimensional codes can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image processing, and in particular to a low-quality image two-dimensional code recognition method, a storage medium and a computer. BACKGROUND

[0002] Two-dimensional codes have prevailed in daily life and industrial production due to their large storage capacity, high accuracy and good real-time performance, and therefore, the research on two-dimensional code recognition technology is extremely important in terms of market demand and research significance.

[0003] However, in the application environment of two-dimensional codes, interference factors such as uneven printing, wear, obstruction and poor lighting conditions often occur, resulting in low imaging quality of two-dimensional codes, and thus reducing the decoding accuracy. Therefore, it is of practical significance to research a recognition method for low-quality two-dimensional codes.

[0004] Therefore, it is necessary to propose an improved scheme to overcome the above problems. SUMMARY

[0005] The present application relates to the technical field of image processing, and in particular to a low-quality image two-dimensional code recognition method, a storage medium and a computer.

[0006] To achieve the purpose of the application, according to one aspect of the present application, the present application provides a two-dimensional code recognition method, which comprises: converting a detection image including a two-dimensional code into a binary image by adaptive threshold segmentation, so as to separate the two-dimensional code in the detection image from the background of the detection image; locating four vertices of the two-dimensional code in the binary image according to the features of various two-dimensional codes; calculating an affine transformation matrix based on the four vertices of the located two-dimensional code, and converting the binary image of the two-dimensional code into a rectangle based on the affine transformation matrix; dividing a two-dimensional grid by using the gray gradient change rule of the two-dimensional code of the rectangle, the two-dimensional grid comprising a plurality of sampling grids separated by interval; obtaining information of each sampling grid as "0" or "1" based on the average gray value of each sampling grid in the two-dimensional grid of the two-dimensional code, and redrawing a standard two-dimensional code composed of black and white data blocks according to the information of each sampling grid in the two-dimensional grid; and reading and decoding the standard two-dimensional code.

[0007] According to another aspect of the present application, the present application provides a storage medium storing program instructions, which execute the above-mentioned two-dimensional code recognition method.

[0008] According to still another aspect of the present application, the present application provides a computer comprising a processor and a memory, the memory storing program instructions, and the processor executing the program instructions to perform the above-mentioned two-dimensional code recognition method.

[0009] Compared with the prior art, the application improves the code recognition and decoding accuracy of low-quality two-dimensional codes by converting two-dimensional code images into standard two-dimensional codes. BRIEF DESCRIPTION OF DRAWINGS

[0010] Figure 1 A flowchart of the two-dimensional code recognition method in an embodiment of the application is shown.

[0011] Figure 2 An example of the two-dimensional code recognition method in the application is shown. DETAILED DESCRIPTION

[0012] To further explain the technical means and effects adopted by the application to achieve the predetermined purposes, the specific embodiments, structures, features and effects of the application are described in detail below in combination with the drawings and preferred embodiments.

[0013] The application provides a two-dimensional code recognition method by converting two-dimensional code images into standard two-dimensional codes, thereby improving the code recognition and decoding accuracy of low-quality two-dimensional codes.

[0014] Figure 1 A flowchart of the two-dimensional code recognition method 100 in an embodiment of the application is shown. As shown in the figure, the two-dimensional code recognition method 100 includes the following steps. Figure 1

[0015] Step 110, the top point positions of the two-dimensional code in the detection image are located, and the detection image including the two-dimensional code is converted into a binary image by adaptive threshold segmentation, so as to separate the two-dimensional code in the detection image from the background of the detection image.

[0016] In an embodiment, a local adaptive image threshold processing method based on the integral algorithm can be used to convert the detection image including the two-dimensional code into a binary image, which has good effect and fast speed. Figure 2 (a) in the figure is a detection image, in which the two-dimensional code is mainly displayed, Figure 2 (b) in the figure is a binary image of the detection image.

[0017] Step 120, the four top points of the two-dimensional code are located in the binary image according to the features of various two-dimensional codes.

[0018] ​In one embodiment, three vertices A, B, and C of the two-dimensional code are located in the binary image according to various two-dimensional code features. Specifically, if the two-dimensional code is a DM (Data Matrix) two-dimensional code, two straight lines of the "L" side for positioning the DM two-dimensional code are obtained by Hough transform straight line fitting, and three vertices A, B, and C are obtained based on the endpoints and intersection points of the two lines; if the two-dimensional code is a QR two-dimensional code, three "square" contours for positioning the QR (Quick Response) two-dimensional code are obtained through contour extraction and level screening, so as to obtain three vertices A, B, and C of the QR two-dimensional code. As Figure 2 shown, the two-dimensional code is a DM two-dimensional code, so the figure (c) is obtained after fitting the L side.

[0019] Due to factors such as variable viewing angles and lens distortion, the fourth vertex D cannot be directly obtained through the pairwise parallel rule of the parallelogram. Therefore, the two vertices A and C on the diagonal are connected to obtain the first straight line I1, the first straight line I1 is translated in the opposite direction of another vertex B to obtain several intersection points with the edge of the two-dimensional code, and these intersection points are linearly fitted, and the second straight line l2 farthest from the vertex C and the third straight line l3 farthest from the vertex A are selected. The intersection point of the second straight line l2 and the third straight line l3 is the fourth vertex D of the two-dimensional code. As Figure 2 shown in (d) of

[0020] Step 130, calculate an affine transformation matrix based on the four vertices of the located two-dimensional code, and convert the binary image of the two-dimensional code into a regular rectangle based on the affine transformation matrix. Specifically, the width and height of the minimum bounding rectangle of the located two-dimensional code are used as the target width and height after affine transformation to calculate the affine transformation matrix. As Figure 2 shown in (e) of

[0021] Step 140, use the gray gradient change rule of the regular rectangle two-dimensional code to divide and form a two-dimensional grid, and the two-dimensional grid includes multiple sampling grids separated by intervals.

[0022] In one embodiment, according to the rule of the "0""1" jump of the two-dimensional code, by calculating the sum of the gray deviation values of the two-dimensional code on the horizontal and vertical coordinate axes respectively, that is, the sum of the gray differences between this column (row) and the previous column (row), which is equivalent to converting the two-dimensional code into two one-dimensional waveforms, and then performing filtering and normalization operations. The low change value area is determined as the sampling area (that is, the black or white information area), and the high change value area is determined as the interval area (that is, the area where the black and white change violently). The area that is the sampling area on both the horizontal and vertical coordinate axes becomes the sampling grid in the two-dimensional grid, and the area where one of the horizontal and vertical coordinate axes is the interval area becomes the interval area in the two-dimensional grid. As Figure 2(f) in the figure is a two-dimensional grid formed by dividing, wherein the black line is an isolation region, and the white grid in the middle is a sampling grid.

[0023] In step 150, based on the average gray value of each sampling grid in the two-dimensional grid in the binary image of the two-dimensional code, the information of each sampling grid is "0" or "1", and a standard two-dimensional code composed of black and white data blocks is redrawn according to the information of each sampling grid in the two-dimensional grid. Figure 2 (g) in the figure is a redrawn standard two-dimensional code.

[0024] In step 160, the standard two-dimensional code is read and decoded.

[0025] Specifically, the size and version type of the processed standard two-dimensional code are read first to determine the error correction mode, then the data information of the two-dimensional code is read one by one in a "snake" mode, and finally the decoding is performed to obtain the information content stored in the two-dimensional code.

[0026] The beneficial effects of the present application are: for the two-dimensional code image with low shooting quality, the traditional image algorithm can be used for preprocessing to obtain a standard two-dimensional matrix image composed of black and white data blocks for code reading and decoding, thereby improving the ability of two-dimensional code recognition and enhancing the robustness of recognition.

[0027] According to another aspect of the present application, the present application provides a storage medium storing program instructions, wherein the program instructions are executed to perform the two-dimensional code recognition method described above. For the sake of simplicity, the specific content of the two-dimensional code recognition method is not repeated here.

[0028] According to another aspect of the present application, the present application provides a computer comprising a processor and a memory, wherein the memory stores program instructions, and the processor executes the program instructions to perform the two-dimensional code recognition method described above. For the sake of simplicity, the specific content of the two-dimensional code recognition method is not repeated here.

[0029] In this document, the term "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, in addition to the listed elements, other elements that are not explicitly listed can also be included.

[0030] In this document, the terms "front", "back", "upper", "lower", and the like are defined with reference to the position of the parts in the drawing and the position of the parts relative to each other, only for the purpose of expressing the technical scheme clearly and conveniently. It should be understood that the use of the terms should not limit the scope of the application claimed.

[0031] Those skilled in the art will appreciate that embodiments of the application can be devised for a method, a system, or a computer program product. Accordingly, the present application can be embodied in the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, and the like) embodying computer readable program code.

[0032] The present application is described in reference to the flowchart illustrations and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams.

[0033] These computer program instructions can also be stored in a computer- readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams.

[0034] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams.

[0035] While preferred embodiments of the application have been described, additional variations and modifications can be made to these embodiments by those skilled in the art once they learn of the basic inventive concepts. Therefore, the appended claims are intended to cover all such variations and modifications as fall within the scope of the application.

Claims

1. A two-dimensional code recognition method characterized by, It includes: Converting a detection image including a QR code into a binary image through adaptive threshold segmentation to segment the QR code in the detection image from the background of the detection image; Locating four vertices of the QR code in the binary image according to various QR code features; Calculating an affine transformation matrix based on the four located vertices of the QR code, and converting the binary image of the QR code into a regular rectangle based on the affine transformation matrix; Dividing and forming a two-dimensional grid by using the gray-scale gradient change rule of the regular rectangle QR code, where the two-dimensional grid includes multiple sampling grids separated by intervals; Obtaining that the information of each sampling grid in the two-dimensional grid is "0" or "1" based on the gray-scale mean value of each sampling grid in the binary image of the QR code, and redrawing a standard QR code composed of black and white data blocks according to the information of each sampling grid in the two-dimensional grid; and Reading and decoding the standard QR code, The locating of the four vertices of the QR code in the binary image according to various QR code features includes: Locating three vertices A, B, and C of the QR code in the binary image according to various QR code features; Connecting the two vertices A and C on the diagonal to obtain a first straight line I1, translating the first straight line I1 in the opposite direction of the other vertex B to obtain several intersection points with the edge of the QR code, performing linear fitting on these intersection points, and screening out a second straight line l2 farthest from vertex C and a third straight line l3 farthest from vertex A. The intersection point of the second straight line l2 and the third straight line l3 is the fourth vertex D of the QR code, The locating of the three vertices A, B, and C of the QR code in the binary image according to various QR code features includes: If the QR code is a DM QR code, obtaining two straight lines of the "L" side for positioning of the DM QR code through Hough transform linear fitting, and obtaining three vertices A, B, and C based on the endpoints and intersection points of the two straight lines; If the QR code is a QR QR code, obtaining three "return" character contours for positioning of the QR QR code through contour extraction and level screening, so as to obtain three vertices A, B, and C of the QR QR code, The dividing and forming a two-dimensional grid by using the gray-scale gradient change rule of the regular rectangle QR code includes: By calculating the sum of the gray-scale deviation values of the binary image of the regular rectangle QR code on the horizontal and vertical coordinate axes respectively, and then performing filtering and normalization operations, determining the low-change value area as the sampling area, the high-change value area as the interval area, the area where both the horizontal and vertical coordinate axes are sampling areas becomes the sampling grid in the two-dimensional grid, and the area where one of the horizontal and vertical coordinate axes is the interval area becomes the interval area in the two-dimensional grid.

2. The two-dimensional code recognition method according to claim 1, wherein Converting a detection image including a QR code into a binary image by using a local adaptive image threshold processing method based on an integral algorithm.

3. The method of claim 1, wherein the two-dimensional code is a QR code. Calculating an affine transformation matrix by using the width and height of the minimum bounding rectangle of the located QR code as the target width and height after affine transformation.

4. A storage medium, characterized by It stores program instructions, and the program instructions are run to execute the QR code recognition method according to any one of claims 1-3.

5. A computer, characterized in that The application relates to a two-dimensional code recognition device, which comprises a processor and a memory, wherein the memory stores program instructions, and the processor runs the program instructions to execute the two-dimensional code recognition method as claimed in any one of claims 1-3.

Citation Information

Patent Citations

  • DM two-dimensional code identification method and device based on image processing

    CN107545207A