CN109934036B - Method and system for recognizing and reading QR (quick response) code through single-position detection graph - Google Patents

Method and system for recognizing and reading QR (quick response) code through single-position detection graph Download PDF

Info

Publication number
CN109934036B
CN109934036B CN201910223412.4A CN201910223412A CN109934036B CN 109934036 B CN109934036 B CN 109934036B CN 201910223412 A CN201910223412 A CN 201910223412A CN 109934036 B CN109934036 B CN 109934036B
Authority
CN
China
Prior art keywords
position detection
correction
code
calculating
graph
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910223412.4A
Other languages
Chinese (zh)
Other versions
CN109934036A (en
Inventor
刘武
宋少龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fuzhou Symbol Information Technology Co ltd
Original Assignee
Fuzhou Symbol Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fuzhou Symbol Information Technology Co ltd filed Critical Fuzhou Symbol Information Technology Co ltd
Priority to CN201910223412.4A priority Critical patent/CN109934036B/en
Publication of CN109934036A publication Critical patent/CN109934036A/en
Application granted granted Critical
Publication of CN109934036B publication Critical patent/CN109934036B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Image Analysis (AREA)

Abstract

The invention discloses a method and a system for identifying and reading a QR code through a single position detection graph, which solve the problem that when two position detection graphs in one QR code are stained, only one position detection graph can be identified. And calculating the version of the QR code according to the current recognizable position detection graph and the correction graph, and decoding by applying different masks and error correction levels by using the calculated version. The invention does not use a complex method with large calculation amount to reconstruct the position detection graph for decoding, but uses the relationship between one position detection graph and the correction graph which can be obtained to carry out version calculation for combined decoding. The defect that decoding can be performed only by at least two position detection graphs in the prior art is overcome, and the anti-pollution capacity of QR code identification is improved.

Description

Method and system for recognizing and reading QR (quick response) code through single-position detection graph
Technical Field
The invention relates to the technical field of stained two-dimensional code identification, in particular to a method and a system for identifying and reading a QR code through a single-position detection graph.
Background
Barcodes (barcodes for short) can be divided into one-dimensional barcodes and two-dimensional barcodes, and QR codes are the most widely used two-dimensional barcodes. Compared with other two-dimensional bar codes, the QR code has the advantages of high recognition speed, high data density and small occupied space. The QR code has an error correction function of 4 levels, and can be correctly read even if damaged. The QR code is strong in bending resistance, and can be quickly identified even if the QR code is attached to a bent article. The method is suitable for the requirements of printing with limited printing area and long and thin space. In addition, 35 numbers, 9 Chinese characters or 21 English letters can be placed in the miniature QR code in a space of 1 cm, and the requirement for collecting the ID number by the small circuit board is met.
Due to environmental influences, the two-dimensional barcode image may be contaminated. Due to the characteristics of the QR code, the QR code has certain anti-pollution capability, and under a certain pollution degree, the information carried by the QR code can be recovered and identified. What needs to be searched for the identification and reading of a QR code is a position detection graph, also called a bull eye, the position detection graph is respectively positioned at the upper left corner, the lower left corner and the upper right corner of the QR code, each detection graph can be regarded as being composed of three overlapped concentric squares which are respectively 7 × 7 dark color modules, 5 × 5 light color modules and 3 × 3 dark color modules. The positions and the directions of the symbols in the field of view can be definitely determined by determining the positions of the three position detection patterns, so that the version information and the format information decoding of the current QR code are obtained. However, if the detection pattern is broken, the QR code cannot be positioned by a conventional method, and the subsequent decoding operation cannot be performed.
Disclosure of Invention
Therefore, the technical problem to be solved by the invention is that in the prior art, bar code reading equipment cannot accurately read a QR code with more than one contaminated position detection pattern.
In order to solve the technical problems, the invention adopts the following technical scheme:
technical scheme one
A method of identifying a QR code by a single position detection pattern, comprising the steps of:
and S1, acquiring a frame of image containing the QR code and transferring the image to a processing unit for preprocessing, wherein the preprocessing comprises acquiring image contrast and a main QR code area, and establishing a rectangular coordinate system, wherein the rectangular coordinate system takes the central point of the current image as an origin, the horizontal direction is the X-axis direction, and the vertical direction is the Y-axis direction.
S2, scanning the image to search the position detection pattern, calculating the number of the position detection patterns which can be obtained, if the number of the searched position detection patterns is more than 1, ending the current process, and positioning and decoding the QR code; if the number of searched position detection patterns is 1, the process proceeds to step S3.
S3, calculating the current QR code unit module size m according to the position detection graph, namely
m is the pixel width of the side length of the position detection pattern/7.
And S4, according to the four vertex coordinates of the position detection graph, connecting two adjacent points to determine four straight lines, dividing the four straight lines into two groups, wherein the straight lines in the same group are parallel, and the straight lines in different groups are perpendicular to each other.
And S5, finding the correction graphs on the four straight lines, counting the number of the correction graphs in two mutually perpendicular directions and recording the coordinates of the center points of all the correction graphs.
S6, judging the position of the position detection graph according to the number of the correction graphs, and when the number of the correction graphs in two directions is different, considering the position detection graph as a side position detection graph and entering the step S7; when the number of correction patterns in both directions is the same, the position detection pattern is regarded as the center position detection pattern, and the process proceeds to step S8.
S7: calculating the distances between the centers of all the correction patterns and the center of the position detection pattern, sorting according to the magnitude of the distances, taking the center of the correction pattern with the largest distance as a reference point 1, calculating the distances from the reference point 1 to the four corners of the position detection pattern to obtain a minimum distance L, and calculating according to the unit module size m to obtain the number cnt of modules contained in the distance L, namely the number cnt of the modules contained in the distance L
cnt=L/m
Proceed to S9.
S8: calculating the distances between the centers of all the correction graphs and the center of the position detection graph, sorting according to the magnitude of the distance values, selecting the center of the correction graph with the largest distance as a reference point 1, and calculating the distances from the reference point 1 to the four corners of the position detection graph to obtain a minimum distance L; selecting the center of the correction graph with the closest distance as a reference point 2, calculating the distances from the reference point 2 to the four corners of the position detection graph to obtain a minimum distance T, and calculating the number cnt of the modules contained in the L + T distance according to the unit module size m, namely the number cnt of the modules contained in the L + T distance
cnt=(L+T)/m
Proceed to S9.
And S9, calculating version information according to the cnt, and selecting a corresponding mask and error correction level combination for decoding.
In the step S2, the approximate area where the position detection pattern is located is preliminarily determined by searching the ratio relationship of black, white, and black modules line by line with the ratio of 1:1:3:1:1, the center black block of a group of modules having this ratio is continuously searched in the direction perpendicular to the scanning line, and if the same ratio of black and white modules of 1:1:3:1:1 exists, the current center black block is determined to be the center black block of the position detection pattern.
In the step S5, the approximate area where the correction pattern is located is preliminarily determined by searching the four straight lines for the proportional relationship of black, white, and black modules in the ratio of 1:1:1:1:1, the search is continued in the direction perpendicular to the straight lines for the central black block of the group of modules in which the ratio exists, and if the same ratio of black and white modules in the ratio of 1:1:1:1:1 exists, the current central black block is determined to be the central black block of the correction pattern.
In step S5, if the corrected pattern cannot be confirmed on the four straight lines, the search is continued by moving the correction pattern by a distance of 1 to 2 unit blocks in a direction perpendicular to the current straight line.
In step S9, the formula for calculating the version information is:
version ═ cnt +14-21)/4+ 1.
The second technical scheme is as follows:
a system for recognizing a QR code through a single position detection pattern, comprising one or more processors and a memory, the memory storing a program and configured to perform the following steps by the one or more processors:
and S1, acquiring a frame of image containing the QR code and transferring the image to a processing unit for preprocessing, wherein the preprocessing comprises acquiring image contrast and a main QR code area, and establishing a rectangular coordinate system, wherein the rectangular coordinate system takes the central point of the current image as an origin, the horizontal direction is the X-axis direction, and the vertical direction is the Y-axis direction.
S2, scanning the image to search the position detection pattern, calculating the number of the position detection patterns which can be obtained, if the number of the searched position detection patterns is more than 1, ending the current process, and positioning and decoding the QR code; if the number of searched position detection patterns is 1, the process proceeds to step S3.
S3, calculating the current QR code unit module size m according to the position detection graph, namely
m is the pixel width of the side length of the position detection pattern/7.
And S4, according to the four vertex coordinates of the position detection graph, connecting two adjacent points to determine four straight lines, dividing the four straight lines into two groups, wherein the straight lines in the same group are parallel, and the straight lines in different groups are perpendicular to each other.
And S5, finding the correction graphs on the four straight lines, counting the number of the correction graphs in two mutually perpendicular directions and recording the coordinates of the center points of all the correction graphs.
S6, judging the position of the position detection graph according to the number of the correction graphs, and when the number of the correction graphs in two directions is different, considering the position detection graph as a side position detection graph and entering the step S7; when the number of correction patterns in both directions is the same, the position detection pattern is regarded as the center position detection pattern, and the process proceeds to step S8.
S7: calculating the distances between the centers of all the correction patterns and the center of the position detection pattern, sorting according to the magnitude of the distances, taking the center of the correction pattern with the largest distance as a reference point 1, calculating the distances from the reference point 1 to the four corners of the position detection pattern to obtain a minimum distance L, and calculating according to the unit module size m to obtain the number cnt of modules contained in the distance L, namely the number cnt of the modules contained in the distance L
cnt=L/m
Proceed to S9.
S8: calculating the distances between the centers of all the correction graphs and the center of the position detection graph, sorting according to the magnitude of the distance values, selecting the center of the correction graph with the largest distance as a reference point 1, and calculating the distances from the reference point 1 to the four corners of the position detection graph to obtain a minimum distance L; selecting the center of the correction graph with the closest distance as a reference point 2, calculating the distances from the reference point 2 to the four corners of the position detection graph to obtain a minimum distance T, and calculating the number cnt of the modules contained in the L + T distance according to the unit module size m, namely the number cnt of the modules contained in the L + T distance
cnt=(L+T)/m
Proceed to S9.
And S9, calculating version information according to the cnt, and selecting a corresponding mask and error correction level combination for decoding.
In the step S2, the approximate area where the position detection pattern is located is preliminarily determined by searching the ratio relationship of black, white, and black modules line by line with the ratio of 1:1:3:1:1, the center black block of a group of modules having this ratio is continuously searched in the direction perpendicular to the scanning line, and if the same ratio of black and white modules of 1:1:3:1:1 exists, the current center black block is determined to be the center black block of the position detection pattern.
In the step S5, the approximate area where the correction pattern is located is preliminarily determined by searching the four straight lines for the proportional relationship of black, white, and black modules in the ratio of 1:1:1:1:1, the search is continued in the direction perpendicular to the straight lines for the central black block of the group of modules in which the ratio exists, and if the same ratio of black and white modules in the ratio of 1:1:1:1:1 exists, the current central black block is determined to be the central black block of the correction pattern.
In step S5, if the corrected pattern cannot be confirmed on the four straight lines, the search is continued by moving the correction pattern by a distance of 1 to 2 unit blocks in a direction perpendicular to the current straight line.
In step S9, the formula for calculating the version information is:
version ═ cnt +14-21)/4+ 1.
Compared with the prior art, the technical scheme of the invention has the following advantages.
1. According to the method and the system for recognizing and reading the QR code through the single position detection graph, the version of the QR code is calculated according to the recognizable unique position detection graph and the number and position relation of the correction graphs, so that the anti-pollution capacity of the QR code recognition is improved.
2. The method and the system for identifying and reading the QR code through the single position detection graph quickly identify the position detection graph and the correction graph according to the ratio of the black and white code blocks, and reduce the running time.
3. The method and the system for recognizing and reading the QR code through the single-position detection graph improve the accuracy of searching by carrying out the extended search on the correction graph in a certain range.
Drawings
In order that the present disclosure may be more readily and clearly understood, the following detailed description of the present disclosure is provided in connection with specific embodiments thereof and the accompanying drawings, in which,
FIG. 1 is a schematic diagram of the main structure of a QR code;
FIG. 2 is a schematic diagram of a position detection pattern in a QR code;
FIG. 3 is a flow chart of a method of reading a QR code with a single position detection pattern in accordance with the present invention;
FIG. 4 is a schematic diagram of an embodiment of a method for recognizing a QR code through a single-position detection pattern according to the present invention;
FIG. 5 is a schematic diagram of an embodiment of a method for recognizing a QR code by a single-position detection pattern according to the present invention;
fig. 6 is a schematic diagram illustrating an embodiment of a method for recognizing a QR code by a single position detection pattern according to the present invention.
Detailed Description
Example 1
The main structure of a QR code is shown in fig. 1:
functional graphics: regions that do not participate in encoding data;
blank area: the color of an area which is specified in the standard QR code (version 1-40) and has the width of 4 units at the periphery and the width of 2 units at the periphery of the miniature QR code is equivalent to the white point in the QR code, wherein patterns or marks cannot be arranged so as to ensure that the QR code is clear and recognizable;
position detection pattern: the square mark is also called a bull eye, is positioned at the upper left corner, the upper right corner and the lower left corner of the QR code, is used for assisting scanning software to position the QR code and transform a coordinate system, and the position detection graph can enable the QR code to be scanned at any angle, which cannot be achieved by a one-dimensional bar code.
A separator: a single bit wide white point band is placed between each position detection pattern and the code region for distinguishing.
Positioning a pattern: a single bit wide band of alternating black and white dots, starting and ending in black, for indicating the mark density and determining the coordinate system.
And (3) correcting the pattern: only QR codes of version 2 and above have corrected patterns. The calibration pattern is used to further calibrate the coordinate system. The number of correction patterns depends on the version.
Coding region: a region of encoded data.
Format information: the fault tolerance level and data mask are stored, along with an additional own BCH fault tolerance code.
Version information: version information is stored, and symbols of the QR code have 40 specifications of matrixes from 21x21 (version 1) to 177x177 (version 40), and each version symbol is added with 4 modules on each side compared with the previous version.
Data and error correction code words: the coding mode, the actually coded data and the RS error-tolerant code of the data are stored.
The identification and reading of a QR code is that position detection patterns need to be found firstly, each detection pattern can be regarded as being composed of three overlapped concentric squares, which are 7 × 7 dark color modules, 5 × 5 light color modules and 3 × 3 dark color modules respectively, and the identification and reading of the QR code is mainly as shown in fig. 2:
the position and the direction of the symbol in the visual field can be definitely determined through the position detection graph; the positioning of the QR is usually realized by identifying three position detection patterns, but if the detection patterns are damaged, the QR code cannot be positioned by using a conventional method.
As shown in fig. 3, which is a preferred flowchart of the present invention, a method for recognizing a QR code by a single position detection pattern includes the steps of:
and S1, acquiring a frame of image containing the QR code and transferring the image to a processing unit for preprocessing, wherein the preprocessing comprises acquiring image contrast and a main QR code area, and establishing a rectangular coordinate system, wherein the rectangular coordinate system takes the central point of the current image as an origin, the horizontal direction is the X-axis direction, and the vertical direction is the Y-axis direction.
The method commonly used in the field of establishing the rectangular coordinate system is that a shot image is a rectangular pixel image aaxbbb, aaa and bbb are respectively the number of long and long pixels, generally, an image center point is taken as an origin, the horizontal and vertical directions are taken as XY axes, and a coordinate unit is a pixel. In this embodiment, the QR code is shot by acquiring an image through a lens, and the CMOS or CCD image sensor is disposed behind the lens. The processing unit includes a CPU processor and a decoding unit.
The preprocessing mainly comprises the steps of obtaining the contrast of an image and obtaining a main area of a QR code to be searched; the rectangular coordinate system is established logically, and the origin and the orientation of the coordinate system are set, so that subsequent calculation is facilitated. Further, the preprocessing also comprises denoising processing and binarization processing of the graph.
S2, scanning the image to search the position detection pattern, calculating the number of the position detection patterns which can be obtained, if the number of the searched position detection patterns is more than 1, ending the current process, and positioning and decoding the QR code; if the number of searched position detection patterns is 1, the process proceeds to step S3.
In the prior art, positioning and decoding of a QR code can be realized under the condition that only two position detection patterns can be identified, for example, a decoding method and a decoding system for the QR code position detection pattern breakage in chinese patent CN 105138943B. The invention mainly solves the problem that the extreme fouling condition of the detection pattern can be identified only by one position.
S3, calculating the current QR code unit module size m according to the position detection graph, namely
m is the pixel width of the side length of the position detection pattern/7.
As shown in fig. 2, the side length of the maximum peripheral square in the position detection graph is 7 unit module sizes, the theoretical unit module size can be obtained by calculation, and data such as the side length and the center point coordinates can be obtained when the position detection graph is searched.
And S4, according to the four vertex coordinates of the position detection graph, connecting two adjacent points to determine four straight lines, dividing the four straight lines into two groups, wherein the straight lines in the same group are parallel, and the straight lines in different groups are perpendicular to each other.
As shown in fig. 4, four corners of the position detection pattern are respectively marked as ABCD, and four straight lines, i.e., four extended straight lines of the position detection pattern, are respectively marked as Line1, Line2, Line3, and Line 4.
And S5, finding the correction graphs on the four straight lines, counting the number of the correction graphs in two mutually perpendicular directions and recording the coordinates of the center points of all the correction graphs.
As shown in fig. 4, the corrected patterns 1, 2, 3 and the respective center points PT1, PT2, PT3 are recognized based on four straight lines.
S6, judging the position of the position detection graph according to the number of the correction graphs, and when the number of the correction graphs in two directions is different, considering the position detection graph as a side position detection graph and entering the step S7; when the number of correction patterns in both directions is the same, the position detection pattern is regarded as the center position detection pattern, and the process proceeds to step S8.
As shown in fig. 4, the number of the correction patterns in the horizontal direction is 2, the number of the correction patterns in the vertical direction is 1, and the two correction patterns are different, so that the position detection pattern is a side position detection pattern.
As shown in fig. 5, if the number of the correction patterns in the horizontal direction is 1 and the number of the correction pattern pages in the vertical direction is 1, and the numbers of the correction patterns are the same, the position detection pattern is the center position detection pattern.
S7: calculating the distances between the centers of all the correction patterns and the center of the position detection pattern, sorting according to the magnitude of the distances, taking the center of the correction pattern with the largest distance as a reference point 1, calculating the distances from the reference point 1 to the four corners of the position detection pattern to obtain a minimum distance L, and calculating according to the unit module size m to obtain the number cnt of modules contained in the distance L, namely the number cnt of the modules contained in the distance L
cnt=L/m
Proceed to S9.
As shown in FIG. 4, if the farthest calibration pattern is calibration pattern 2, the center point PT2 of calibration pattern 2 is set as reference point 1, and the distances from PT2 to the four corners of the position detection pattern, i.e., the four corners of ABCD, are calculated, wherein the minimum distance L is the distance from PT2 to corner B.
S8: calculating the distances between the centers of all the correction graphs and the center of the position detection graph, sorting according to the magnitude of the distance values, selecting the center of the correction graph with the largest distance as a reference point 1, and calculating the distances from the reference point 1 to the four corners of the position detection graph to obtain a minimum distance L; selecting the center of the correction graph with the closest distance as a reference point 2, calculating the distances from the reference point 2 to the four corners of the position detection graph to obtain a minimum distance T, and calculating the number cnt of the modules contained in the L + T distance according to the unit module size m, namely the number cnt of the modules contained in the L + T distance
cnt=(L+T)/m
Proceed to S9.
As shown in fig. 5, when the QR code version is small, the distances between the correction pattern 1 and the correction pattern 2 and the position detection pattern are the same, the distance between the PT1 at the center point of the correction pattern 1 is set as the reference point 1, and the distances between the PT1 and the four corners of the position detection pattern, that is, the four corners of ABCD are calculated, and the minimum distance L is the distance between the PT1 and the corner C. The distance from PT2 to the four corners of the position detection pattern, i.e., the four corners of ABCD, is calculated with the center point PT2 of the correction pattern 2 set as reference point 2, and the minimum distance T is known as the distance from PT2 to corner C. Since the distances are the same, the center point of the correction pattern 1 can likewise be used as the reference point 2.
As shown in fig. 6, when the QR code version is large, the distances between the calibration pattern and the position detection pattern are different, and the calibration pattern 1 is farthest from the QR code version, the center point PT1 of the calibration pattern 1 is set as the reference point 1, and the distances from PT1 to the four corners of the position detection pattern, that is, the four corners of ABCD are calculated, and the minimum distance L is the distance from PT1 to corner C. In the figure, the correction pattern 2 is closest, the distance from the PT2 to the four corners of the position detection pattern, i.e., the four corners of ABCD, is calculated by setting the center point PT2 of the correction pattern 2 as the reference point 2, and the minimum distance T is the distance from the PT2 to the corner C. Because the QR code is square, four sides are equal in length, and the correction patterns 3 and 4 can be used as the calculation reference points.
The number of modules in each distance is calculated to mainly determine the number of modules contained in the side length of the QR code, and then version information is obtained.
In fig. 4, the L distance is the distance between two position detection patterns on a single side, and the number of modules included in the side length of the two position detection patterns is 14, so that the number of modules included in the side length of the QR code can be obtained.
In fig. 5 and 6, according to the mirror distribution rule of the calibration pattern in the QR code, the sum of L and T is the distance between the two position detection patterns on a single side.
And S9, calculating version information according to the cnt, and selecting a corresponding mask and error correction level combination for decoding.
Each version of the QR code has 4 modules added to each edge of the symbol of the previous version, the number of the side length modules of the version 1 is 21, the version of the current QR code can be reversely deduced according to the following formula,
version ═ cnt +14-21)/4+ 1.
Because the parameters used in the calculation are theoretical calculation values, the obtained version number is also a theoretical version number, if the combination of the mask of the current version and the error correction level cannot be decoded, the decoding operation can be performed by using the version number of plus or minus 1 unit, and the algorithm is internally provided with the combination of the mask of the corresponding version and the error correction level and a decoding method thereof.
In the step S2, the approximate area where the position detection pattern is located is preliminarily determined by searching the ratio relationship of black, white, and black modules line by line with the ratio of 1:1:3:1:1, the center black block of a group of modules having this ratio is continuously searched in the direction perpendicular to the scanning line, and if the same ratio of black and white modules of 1:1:3:1:1 exists, the current center black block is determined to be the center black block of the position detection pattern.
In the step S5, the approximate area where the correction pattern is located is preliminarily determined by searching the four straight lines for the proportional relationship of black, white, and black modules in the ratio of 1:1:1:1:1, the search is continued in the direction perpendicular to the straight lines for the central black block of the group of modules in which the ratio exists, and if the same ratio of black and white modules in the ratio of 1:1:1:1:1 exists, the current central black block is determined to be the central black block of the correction pattern.
In step S5, if the corrected pattern cannot be confirmed on the four straight lines, the search is continued by moving the correction pattern by a distance of 1 to 2 unit blocks in a direction perpendicular to the current straight line.
In step S9, the formula for calculating the version information is:
version ═ cnt +14-21)/4+ 1.
According to the method and the system for recognizing and reading the QR code through the single position detection graph, the version of the QR code is calculated according to the recognizable unique position detection graph and the number and position relation of the correction graphs, so that the anti-pollution capacity of the QR code recognition is improved. The position detection pattern and the correction pattern are quickly identified by the ratio of black and white code blocks, so that the running time is reduced. The accuracy of search is improved by carrying out the extended search of the correction graph within a certain range.
Example 2
A system for recognizing a QR code through a single position detection pattern, comprising one or more processors and a memory, the memory storing a program and configured to perform the following steps by the one or more processors:
and S1, acquiring a frame of image containing the QR code and transferring the image to a processing unit for preprocessing, wherein the preprocessing comprises acquiring image contrast and a main QR code area, and establishing a rectangular coordinate system, wherein the rectangular coordinate system takes the central point of the current image as an origin, the horizontal direction is the X-axis direction, and the vertical direction is the Y-axis direction.
S2, scanning the image to search the position detection pattern, calculating the number of the position detection patterns which can be obtained, if the number of the searched position detection patterns is more than 1, ending the current process, and positioning and decoding the QR code; if the number of searched position detection patterns is 1, the process proceeds to step S3.
S3, calculating the current QR code unit module size m according to the position detection graph, namely
m is the pixel width of the side length of the position detection pattern/7.
And S4, according to the four vertex coordinates of the position detection graph, connecting two adjacent points to determine four straight lines, dividing the four straight lines into two groups, wherein the straight lines in the same group are parallel, and the straight lines in different groups are perpendicular to each other.
And S5, finding the correction graphs on the four straight lines, counting the number of the correction graphs in two mutually perpendicular directions and recording the coordinates of the center points of all the correction graphs.
S6, judging the position of the position detection graph according to the number of the correction graphs, and when the number of the correction graphs in two directions is different, considering the position detection graph as a side position detection graph and entering the step S7; when the number of correction patterns in both directions is the same, the position detection pattern is regarded as the center position detection pattern, and the process proceeds to step S8.
S7: calculating the distances between the centers of all the correction patterns and the center of the position detection pattern, sorting according to the magnitude of the distances, taking the center of the correction pattern with the largest distance as a reference point 1, calculating the distances from the reference point 1 to the four corners of the position detection pattern to obtain a minimum distance L, and calculating according to the unit module size m to obtain the number cnt of modules contained in the distance L, namely the number cnt of the modules contained in the distance L
cnt=L/m
Proceed to S9.
S8: calculating the distances between the centers of all the correction graphs and the center of the position detection graph, sorting according to the magnitude of the distance values, selecting the center of the correction graph with the largest distance as a reference point 1, and calculating the distances from the reference point 1 to the four corners of the position detection graph to obtain a minimum distance L; selecting the center of the correction graph with the closest distance as a reference point 2, calculating the distances from the reference point 2 to the four corners of the position detection graph to obtain a minimum distance T, and calculating the number cnt of the modules contained in the L + T distance according to the unit module size m, namely the number cnt of the modules contained in the L + T distance
cnt=(L+T)/m
Proceed to S9.
And S9, calculating version information according to the cnt, and selecting a corresponding mask and error correction level combination for decoding.
In the step S2, the approximate area where the position detection pattern is located is preliminarily determined by searching the ratio relationship of black, white, and black modules line by line with the ratio of 1:1:3:1:1, the center black block of a group of modules having this ratio is continuously searched in the direction perpendicular to the scanning line, and if the same ratio of black and white modules of 1:1:3:1:1 exists, the current center black block is determined to be the center black block of the position detection pattern.
In the step S5, the approximate area where the correction pattern is located is preliminarily determined by searching the four straight lines for the proportional relationship of black, white, and black modules in the ratio of 1:1:1:1:1, the search is continued in the direction perpendicular to the straight lines for the central black block of the group of modules in which the ratio exists, and if the same ratio of black and white modules in the ratio of 1:1:1:1:1 exists, the current central black block is determined to be the central black block of the correction pattern.
In step S5, if the corrected pattern cannot be confirmed on the four straight lines, the search is continued by moving the correction pattern by a distance of 1 to 2 unit blocks in a direction perpendicular to the current straight line.
In step S9, the formula for calculating the version information is:
version ═ cnt +14-21)/4+ 1.
According to the method and the system for recognizing and reading the QR code through the single position detection graph, the version of the QR code is calculated according to the recognizable unique position detection graph and the number and position relation of the correction graphs, so that the anti-pollution capacity of the QR code recognition is improved. The position detection pattern and the correction pattern are quickly identified by the ratio of black and white code blocks, so that the running time is reduced. The accuracy of search is improved by carrying out the extended search of the correction graph within a certain range.
Example 3
As shown in fig. 4, the position detection patterns on the upper right and upper left of the QR code have been contaminated.
One frame of image containing the QR code as shown in FIG. 4 is acquired and transferred to a processing unit for preprocessing.
The image is scanned for position detection patterns, and the number of position detection patterns that can be obtained is calculated. And searching the proportional relation of black, white, black, white and black modules in a ratio of 1:1:3:1:1 line by line through the scanning lines. The scanning line is at first in the horizontal direction, and from right above the image, the scanning is continued by shifting down one pixel at the end of each scanning. The position of a black and white pixel point on a current scanning horizontal line is calculated in each scanning, when the scanning line scans the tail end of an image, the proportional relation of black, white, black, white and black modules in proportion of 1:1:3:1:1 appears, and at the moment, the position detection graph in the current area can be determined. And searching the central black block along the direction vertical to the scanning line at the moment, wherein the same black-white module proportion of 1:1:3:1:1 exists, and determining the current central black block as the central black block of the position detection graph.
Calculating the current QR code unit module size m according to the position detection graph, namely
m is the pixel width of the side length of the position detection pattern/7.
In this embodiment, by preprocessing the established coordinate system and the scan data of the scan line, the pixel width of the position detection graph side length can be calculated to be 14, and then the current QR code unit module size m is 2.
And according to the coordinates of the four vertexes of the position detection graph, determining four straight lines by connecting two adjacent points, dividing the four straight lines into two groups, wherein the straight lines in the same group are parallel to each other, and the straight lines in different groups are perpendicular to each other.
The four vertex coordinates are obtained during the scan line scan, as shown in fig. 4, which are four corners of ABCD, and two by two lines form line1, line2, line3, and line 4.
And trying to find the correction graphs on the four straight lines, counting the number of the correction graphs in two mutually perpendicular directions and recording the coordinates of the center points of all the correction graphs. And searching the proportional relation of black, white, black, white and black modules in a ratio of 1:1:1:1:1 line by line through the scanning lines. The scanning line is at first in the horizontal direction, and from right above the image, the scanning is continued by shifting down one pixel at the end of each scanning. The position of a black and white pixel point on a current scanning horizontal line is calculated in each scanning, when the scanning line scans the tail end of an image, the proportional relation of black, white, black, white and black modules in proportion of 1:1:1:1:1 occurs, and at the moment, the position detection graph in the current area can be determined. And searching the central black block along the direction vertical to the scanning line at the moment, wherein the same black-white module proportion of 1:1:3:1:1 exists, and determining the current central black block as the central black block of the position detection graph. A total of 3 calibration patterns were obtained, with the center points PT1, PT2, and PT 3.
Since the number of the vertical direction correction patterns is 1 and the number of the horizontal direction correction patterns is 2, the position detection pattern is considered to be a side position detection pattern.
Calculating the distances between the centers of all the correction graphs and the center of the position detection graph, sorting according to the magnitude of the distance values, selecting the center of the correction graph with the largest distance as a reference point 1, and calculating the distances from the reference point 1 to the four corners of the position detection graph to obtain a minimum distance L; in this embodiment, the distance from PT3 to the center point of the position detection pattern is the largest, then PT3 is the reference point, and the minimum distance is the distance from PT3 to point B, which is 60.
Selecting the center of the correction graph with the closest distance as a reference point 2, PT2 as a reference point 2, calculating the distances from the reference point 2 to the four corners of the position detection graph to obtain a minimum distance 24, and calculating the number cnt of the modules contained in the L + T distance according to the unit module size m, namely the number cnt of the modules contained in the L + T distance
cnt=(L+T)/m=(60+24)/2=42
The version information is calculated from the cnt,
version (cnt +14-21)/4+1 (42+14-21)/4+1 (10). A mask with a version number of 10 is selected for decoding in combination with the error correction level.
According to the method and the system for recognizing and reading the QR code through the single position detection graph, the version of the QR code is calculated according to the recognizable unique position detection graph and the number and position relation of the correction graphs, so that the anti-pollution capacity of the QR code recognition is improved. The position detection pattern and the correction pattern are quickly identified by the ratio of black and white code blocks, so that the running time is reduced. The accuracy of search is improved by carrying out the extended search of the correction graph within a certain range.
It should be understood that the above examples are only for clarity of illustration and are not intended to limit the embodiments. Other variations and modifications will be apparent to persons skilled in the art in light of the above description. And are neither required nor exhaustive of all embodiments. And obvious variations or modifications therefrom are within the scope of the invention.

Claims (10)

1. A method for recognizing and reading a QR code through a single position detection graph is characterized by comprising the following steps:
s1, acquiring a frame of image containing a QR code and transferring the image to a processing unit for preprocessing, wherein the preprocessing comprises acquiring image contrast and a main QR code area and establishing a rectangular coordinate system, the rectangular coordinate system takes the central point of the current image as an origin, the horizontal direction is the X-axis direction, and the vertical direction is the Y-axis direction;
s2, scanning the image to search the position detection pattern, calculating the number of the position detection patterns which can be obtained, if the number of the searched position detection patterns is more than 1, ending the current process, and positioning and decoding the QR code; if the number of the searched position detection patterns is 1, the step is switched to step S3;
s3, calculating the current QR code unit module size m according to the position detection graph, namely
m is the pixel width of the side length of the position detection graph/7;
s4, according to the four vertex coordinates of the position detection graph, four straight lines are determined through the connection of two adjacent points, the four straight lines are divided into two groups, the straight lines in the same group are parallel, and the straight lines in different groups are perpendicular to each other;
s5, finding the correction graphs on the four straight lines, counting the number of the correction graphs in two mutually perpendicular directions and recording the coordinates of the central points of all the correction graphs;
s6, judging the position of the position detection graph according to the number of the correction graphs, and when the number of the correction graphs in two directions is different, considering the position detection graph as a side position detection graph and entering the step S7; when the number of the corrected patterns in the two directions is the same, the position detection pattern is regarded as a center position detection pattern, and the process proceeds to step S8;
s7: calculating the distances between the centers of all the correction patterns and the center of the position detection pattern, sorting according to the magnitude of the distances, taking the center of the correction pattern with the largest distance as a reference point 1, calculating the distances from the reference point 1 to the four corners of the position detection pattern to obtain a minimum distance L, and calculating according to the unit module size m to obtain the number cnt of modules contained in the distance L, namely the number cnt of the modules contained in the distance L
cnt=L/m
Proceeding to S9;
s8: calculating the distances between the centers of all the correction graphs and the center of the position detection graph, sorting according to the magnitude of the distance values, selecting the center of the correction graph with the largest distance as a reference point 1, and calculating the distances from the reference point 1 to the four corners of the position detection graph to obtain a minimum distance L; selecting the center of the correction graph with the closest distance as a reference point 2, calculating the distances from the reference point 2 to the four corners of the position detection graph to obtain a minimum distance T, and calculating the number cnt of the modules contained in the L + T distance according to the unit module size m, namely the number cnt of the modules contained in the L + T distance
cnt=(L+T)/m
Proceeding to S9;
and S9, calculating version information according to the cnt, and selecting a corresponding mask and error correction level combination for decoding.
2. The method for identifying and reading the QR code according to the single position detection pattern of claim 1, wherein in the step S2, the scanning lines are used to search line by line for the proportional relationship of black, white, black, white and black modules in the ratio of 1:1:3:1:1 to preliminarily confirm the approximate area where the position detection pattern is located, the search is continued to be performed on the central black block of a group of modules with the ratio along the direction perpendicular to the scanning lines, and if the same ratio of black and white modules in the ratio of 1:1:3:1:1 is present, the current central black block is determined to be the central black block of the position detection pattern.
3. The method for identifying and reading a QR code according to a single position detection pattern as claimed in claim 2, wherein in step S5, the approximate region where the correction pattern is located is preliminarily determined by searching the four straight lines for the ratio of black, white, black, white and black modules in the ratio of 1:1:1:1:1, the search is continued in the direction perpendicular to the straight lines for the central black block of the group of modules having the ratio, and if the same ratio of black and white modules in the ratio of 1:1:1:1:1 is present, the current central black block is determined to be the central black block of the correction pattern.
4. The method as claimed in claim 3, wherein if the corrected pattern is not confirmed on the four straight lines, the step S5 is performed by moving the current straight line in a direction perpendicular to the current straight line by a distance of 1 to 2 unit modules.
5. The method for recognizing and reading a QR code according to claim 4, wherein in step S9, the formula for calculating the version information is:
version ═ cnt +14-21)/4+ 1.
6. A system for recognizing a QR code through a single position detection pattern, comprising one or more processors and a memory, said memory storing a program and configured to be executed by said one or more processors to perform the steps of:
s1, acquiring a frame of image containing a QR code and transferring the image to a processing unit for preprocessing, wherein the preprocessing comprises acquiring image contrast and a main QR code area and establishing a rectangular coordinate system, wherein the rectangular coordinate system takes the central point of the current image as an origin, the horizontal direction is the X-axis direction, and the vertical direction is the Y-axis direction;
s2, scanning the image to search the position detection pattern, calculating the number of the position detection patterns which can be obtained, if the number of the searched position detection patterns is more than 1, ending the current process, and positioning and decoding the QR code; if the number of the searched position detection patterns is 1, the step is switched to step S3;
s3, calculating the current QR code unit module size m according to the position detection graph, namely
m is the pixel width of the side length of the position detection graph/7;
s4, according to the four vertex coordinates of the position detection graph, four straight lines are determined through the connection of two adjacent points, the four straight lines are divided into two groups, the straight lines in the same group are parallel, and the straight lines in different groups are perpendicular to each other;
s5, finding the correction graphs on the four straight lines, counting the number of the correction graphs in two mutually perpendicular directions and recording the coordinates of the central points of all the correction graphs;
s6, judging the position of the position detection graph according to the number of the correction graphs, and when the number of the correction graphs in two directions is different, considering the position detection graph as a side position detection graph and entering the step S7; when the number of the corrected patterns in the two directions is the same, the position detection pattern is regarded as a center position detection pattern, and the process proceeds to step S8;
s7: calculating the distances between the centers of all the correction patterns and the center of the position detection pattern, sorting according to the magnitude of the distances, taking the center of the correction pattern with the largest distance as a reference point 1, calculating the distances from the reference point 1 to the four corners of the position detection pattern to obtain a minimum distance L, and calculating according to the unit module size m to obtain the number cnt of modules contained in the distance L, namely the number cnt of the modules contained in the distance L
cnt=L/m
Proceeding to S9;
s8: calculating the distances between the centers of all the correction graphs and the center of the position detection graph, sorting according to the magnitude of the distance values, selecting the center of the correction graph with the largest distance as a reference point 1, and calculating the distances from the reference point 1 to the four corners of the position detection graph to obtain a minimum distance L; selecting the center of the correction graph with the closest distance as a reference point 2, calculating the distances from the reference point 2 to the four corners of the position detection graph to obtain a minimum distance T, and calculating the number cnt of the modules contained in the L + T distance according to the unit module size m, namely the number cnt of the modules contained in the L + T distance
cnt=(L+T)/m
Proceeding to S9;
and S9, calculating version information according to the cnt, and selecting a corresponding mask and error correction level combination for decoding.
7. The system for identifying and reading the QR code according to the single position detection pattern of claim 6, wherein in the step S2, the scanning lines are used to search line by line for the proportional relationship of black, white, black, white and black modules in the ratio of 1:1:3:1:1 to preliminarily confirm the approximate area where the position detection pattern is located, the search is continued to be performed on the central black block of the group of modules with the ratio along the direction perpendicular to the scanning lines, and if the same ratio of black and white modules in the ratio of 1:1:3:1:1 is present, the current central black block is determined to be the central black block of the position detection pattern.
8. The system for identifying and reading a QR code according to a single position detection pattern as claimed in claim 7, wherein in step S5, the approximate region where the correction pattern is located is preliminarily determined by searching the four straight lines for the ratio of black, white, black, white and black modules in the ratio of 1:1:1:1:1, the search is continuously performed in the direction perpendicular to the straight lines on the center black block of the group of modules having the ratio, and if the same ratio of black and white modules in the ratio of 1:1:1:1:1 is present, the current center black block is determined to be the center black block of the correction pattern.
9. The system for recognizing a QR code according to claim 8, wherein in step S5, if the calibration pattern cannot be confirmed on the four straight lines, the search is continued by moving a distance of 1 to 2 unit modules in a direction perpendicular to the current straight line.
10. The system for recognizing and reading a QR code according to claim 9, wherein in step S9, the formula for calculating the version information is:
version ═ cnt +14-21)/4+ 1.
CN201910223412.4A 2019-03-22 2019-03-22 Method and system for recognizing and reading QR (quick response) code through single-position detection graph Active CN109934036B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910223412.4A CN109934036B (en) 2019-03-22 2019-03-22 Method and system for recognizing and reading QR (quick response) code through single-position detection graph

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910223412.4A CN109934036B (en) 2019-03-22 2019-03-22 Method and system for recognizing and reading QR (quick response) code through single-position detection graph

Publications (2)

Publication Number Publication Date
CN109934036A CN109934036A (en) 2019-06-25
CN109934036B true CN109934036B (en) 2022-01-04

Family

ID=66988065

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910223412.4A Active CN109934036B (en) 2019-03-22 2019-03-22 Method and system for recognizing and reading QR (quick response) code through single-position detection graph

Country Status (1)

Country Link
CN (1) CN109934036B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110490021B (en) * 2019-08-21 2023-02-24 网易(杭州)网络有限公司 Two-dimensional code positioning method, medium, device and computing equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101882207A (en) * 2010-06-01 2010-11-10 福建新大陆电脑股份有限公司 Bar code decoding chip of Data Matrix codes and decoding method thereof
CN101908128A (en) * 2010-06-01 2010-12-08 福建新大陆电脑股份有限公司 Aztec Code bar code decoding chip and decoding method thereof
CN105138943A (en) * 2015-09-02 2015-12-09 福建联迪商用设备有限公司 Method and system for decoding QR code with damaged position detection graph
CN106127276A (en) * 2016-06-27 2016-11-16 福建联迪商用设备有限公司 A kind of quantization is stained the method and system of QRCode
CN107748855A (en) * 2017-08-29 2018-03-02 广东顺德中山大学卡内基梅隆大学国际联合研究院 A kind of detection method of Quick Response Code view finding figure

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101882207A (en) * 2010-06-01 2010-11-10 福建新大陆电脑股份有限公司 Bar code decoding chip of Data Matrix codes and decoding method thereof
CN101908128A (en) * 2010-06-01 2010-12-08 福建新大陆电脑股份有限公司 Aztec Code bar code decoding chip and decoding method thereof
CN105138943A (en) * 2015-09-02 2015-12-09 福建联迪商用设备有限公司 Method and system for decoding QR code with damaged position detection graph
CN106127276A (en) * 2016-06-27 2016-11-16 福建联迪商用设备有限公司 A kind of quantization is stained the method and system of QRCode
CN107748855A (en) * 2017-08-29 2018-03-02 广东顺德中山大学卡内基梅隆大学国际联合研究院 A kind of detection method of Quick Response Code view finding figure

Also Published As

Publication number Publication date
CN109934036A (en) 2019-06-25

Similar Documents

Publication Publication Date Title
EP3309704B1 (en) Two-dimensional code partitioning and decoding method and system
CN107633192B (en) Bar code segmentation and reading method based on machine vision under complex background
CN110047109B (en) Camera calibration plate based on self-identification mark and identification detection method thereof
EP2393037B1 (en) Data matrix decoding chip and decoding method thereof
KR100828539B1 (en) Detection method of two dimensional code, detection device thereof, and storage medium having detection program storaged therein
EP2393035B1 (en) QR barcode decoding chip and decoding method thereof
CN108073966B (en) Conversion method of two-dimensional code and hole array code
US9286501B2 (en) Method and device for identifying a two-dimensional barcode
CN111783495B (en) Bar code identification method and device, electronic equipment and storage medium
CN107247985B (en) Coding, positioning and identifying method of two-dimensional code
WO2015174191A1 (en) Two-dimensional code, and two-dimensional-code analysis system
CN108763996B (en) Plane positioning coordinate and direction angle measuring method based on two-dimensional code
EP3561729B1 (en) Method for detecting and recognising long-range high-density visual markers
CN112699704B (en) Method, device, equipment and storage device for detecting bar code
CN111275049B (en) Method and device for acquiring text image skeleton feature descriptors
CN109934036B (en) Method and system for recognizing and reading QR (quick response) code through single-position detection graph
WO2022021687A1 (en) Method for positioning quick response code area, and electronic device and storage medium
CN113420580A (en) Method and device for positioning auxiliary locator for two-dimensional code, two-dimensional code scanning equipment and storage medium
CN110543798B (en) Two-dimensional code identification method and device
CN112488099A (en) Digital detection extraction element on electric power liquid crystal instrument based on video
CN116469090A (en) Method and device for detecting code spraying pattern, electronic equipment and storage medium
CN109635613B (en) Two-dimensional code generation method, system and device for sphere surface
CN110263597B (en) Quick and accurate QR (quick response) code correction method and system
CN110097065B (en) Freeman chain code-based line detection method and terminal
CN112800798A (en) Positioning method of Aztec code

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant