QR code position detection pattern positioning method and positioning system
Through a combination of object detection algorithm and scanning method, the coordinates of the center point of the QR code position detection graph are detected and corrected, which solves the problem of positioning deviation or inability to position in the QR code image in the prior art in complex environments, and improves the positioning accuracy.
Patent Information
- Application Number
- CN202210534720.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-17
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2042-05-17
AI Technical Summary
The prior art is difficult to effectively locate the QR code position detection graphics in complex and changeable environments, especially when the image contains defects such as noise and blur, which can easily lead to positioning deviations or inability to position.
The object detection algorithm is used to coarsely locate the original QR code image, detect the position detection graphics and correct the graphics, and obtain its detection box information. Then, the center point coordinates of the position detection pattern are determined by scanning method, and perspective transformation is performed in combination with the center point coordinates of the correction pattern, and the QR code image is corrected as a standard image, and finally decoded.
The positioning accuracy of the QR code position detection graphics is improved, and the problem of positioning deviation or inability to position in the traditional scanning positioning method when there are defects such as noise and blur.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of two-dimensional code recognition, and in particular to a positioning method and a positioning system for a QR code position detection graphic. Background Art
[0002] With the rapid development of e-commerce in the country, huge express delivery orders have prompted the express delivery industry to begin to change. From fully manual management of express parcels, to semi-automatic management of parcels, and then to fully automated management of express parcels, this process benefits from the identification and tracking of express information. The carrier of express information mainly relies on barcodes and QR codes. Barcodes have limited storage information and are easily affected by the external environment to produce problems such as reflection and contamination, which can easily cause misidentification. QR codes can effectively solve the drawbacks of barcodes. Among them, QR (Quick Response) code is a matrix-type QR code invented by DENSO in 1994. It has the advantages of large information storage capacity, strong fault tolerance, can represent Chinese characters, and fast recognition speed. It can be used in various industrial automation production lines, so QR codes play an important role in the field of intelligent logistics.
[0003] Since express delivery labels are prone to damage and stains during transportation, and images are prone to reflection and distortion when captured on the conveyor belt, how to locate and detect graphics in a complex and changing environment is an important issue facing QR code recognition.
[0004] At present, the main method for locating the position detection pattern of the QR code is the scanning method, that is, scanning the entire QR code image in rows and columns. According to the characteristics of the position detection pattern of 1:1:3:1:1, calculations are performed in the horizontal and vertical directions respectively to obtain the center points of the three position detection patterns. If one of the position detection patterns has a problem (such as noise, blur, stain, etc.), then the positioning of the position detection pattern is likely to be deviated, or even impossible to locate, so that perspective transformation cannot be performed for decoding. Summary of the invention
[0005] The present application provides a positioning method and positioning system for a QR code position detection pattern, which can solve the problem that the positioning of the QR code image position detection pattern is biased or even the QR code position detection pattern cannot be positioned due to defects such as noise and blur in the QR code image.
[0006] On the one hand, an embodiment of the present application provides a method for locating a QR code position detection pattern, wherein the QR code original image includes: a position detection pattern and a correction pattern, and the method for locating the QR code position detection pattern includes:
[0007] Performing coarse positioning on the QR code original image to determine the QR code area;
[0008] Using a target detection algorithm to detect the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern;
[0009] According to the detection frame information of the position detection pattern and the detection frame information of the correction pattern, the coordinates of the center point of the position detection pattern and the coordinates of the center point of the correction pattern at the lower right corner in the QR code area are acquired;
[0010] Performing perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image into a QR code standard image;
[0011] Decoding the QR code standard image;
[0012] Wherein, the step of obtaining the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern at the lower right corner of the QR code original image according to the detection frame information of the position detection pattern and the detection frame information of the correction pattern comprises:
[0013] According to the detection frame information of the position detection pattern, the position detection pattern is scanned by a scanning method to obtain the coordinates of the center point of the position detection pattern;
[0014] According to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, the correction pattern at the lower right corner of the QR code original image is determined, and the coordinates of the center point of the correction pattern at the lower right corner are obtained.
[0015] Optionally, in the positioning method of the QR code position detection pattern, the step of roughly positioning the QR code original image to determine the QR code area includes:
[0016] Scaling the original QR code image to a preset size, and performing normalization processing on the scaled original QR code image;
[0017] The object detection algorithm is used to roughly locate the scaled QR code original image to determine the QR code area.
[0018] Optionally, in the positioning method of the QR code position detection graphic, the target detection algorithm used for coarse positioning of the scaled QR code original image uses a target detection model of YoloV5-Nano.
[0019] Optionally, in the positioning method of the QR code position detection pattern, the step of using a target detection algorithm to detect the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and the detection frame information of the correction pattern includes:
[0020] Scaling the QR code region image within the QR code region to a preset size, and performing normalization processing on the scaled QR code region image;
[0021] A target detection algorithm is used to detect the position detection pattern and the correction pattern of the QR code area image to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern, wherein the target detection model used is YoloV5-FP.
[0022] Optionally, in the positioning method of the QR code position detection pattern, the step of acquiring the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern in the lower right corner within the QR code area according to the detection frame information of the position detection pattern and the detection frame information of the correction pattern includes:
[0023] Preprocessing the QR code region image so that the pixel values of the QR code region image only include 0 and 255;
[0024] The number of detection frames of the position detection pattern is obtained according to the detection frame information of the position detection pattern; wherein, if the number of detection frames of the position detection pattern is greater than or equal to 3, the detection frames of the three position detection patterns with the highest scores are screened out as the position detection patterns, and according to the pixel values of the QR code area image, the three position detection patterns are scanned by a scanning method to obtain the center point coordinates of the position detection patterns; if the number of the position detection patterns is less than 3, according to the pixel values of the QR code area image, the QR code area image is scanned by a scanning method to obtain three position detection patterns, and the center point coordinates of the three position detection patterns are obtained;
[0025] The number of the correction figures is obtained according to the detection frame information of the correction figures; wherein, if the number of the correction figures is greater than or equal to 2, the center point coordinates of the correction figure at the lower right corner of the QR code area image are obtained according to the position detection figure at the lower left corner and the position detection figure at the upper right corner of the QR code area image; if the number of the correction figures is equal to 1, the correction figure is regarded as the correction figure at the lower right corner of the QR code area image; if the number of the correction figures is equal to 0, the center point coordinates of the correction figure at the lower right corner of the QR code area image are obtained according to the 3 position detection figures in the QR code area image.
[0026] Optionally, in the positioning method of the QR code position detection pattern, the step of preprocessing the QR code area image so that the pixel values of the QR code area image only contain 0 and 255 includes:
[0027] Performing histogram equalization to nonlinearly stretch the grayscale of the QR code area image;
[0028] Median filtering removes noise in the QR code area image;
[0029] The QR code region image is binarized using the Otsu method so that the pixel values of the QR code region image only include 0 and 255.
[0030] Optionally, in the positioning method of the QR code position detection pattern, if the number of detection frames of the position detection pattern is greater than or equal to 3, the step of selecting the detection frames of the three position detection patterns with the highest scores as the position detection patterns, and scanning the three position detection patterns using a scanning method according to the pixel values of the QR code area image to obtain the coordinates of the center point of the position detection patterns includes:
[0031] Filtering out the detection frames of the three position detection patterns with the highest scores as position detection patterns;
[0032] Scanning the position detection pattern line by line, wherein every five segments constitute a scan line, and the pixel values between the segments alternate between 0 and 255, to obtain a scan line that satisfies the 1:1:3:1:1 rule;
[0033] Record the position of the first scan line and the position of the last scan line that satisfy the 1:1:3:1:1 rule, wherein the first scan line, the last scan line, and the middle dark module of the position detection pattern intersect at four points, which are recorded as A, B, C, and D;
[0034] The intersection of the four points A, B, C, and D is set as the virtual center point, and it is verified whether the scan line in the vertical direction passing through the virtual center point satisfies the 1:1:3:1:1 rule; if it satisfies the 1:1:3:1:1 rule, the virtual center point is used as the center point of the position detection figure.
[0035] Optionally, in the positioning method of the QR code position detection pattern, if the number of the correction patterns is greater than or equal to 2, the step of obtaining the center point coordinates of the correction pattern in the lower right corner of the QR code area image according to the position detection pattern in the lower left corner and the position detection pattern in the upper right corner in the QR code area image includes:
[0036] Obtaining the center point coordinates of the position detection pattern at the lower left corner and the position detection pattern at the upper right corner in the QR code area image, as well as the center point coordinates of each of the correction patterns;
[0037] Calculating the straight-line distance between the center point coordinates of each of the correction patterns and the center point coordinates of the position detection pattern at the lower left corner and the position detection pattern at the upper right corner;
[0038] The correction figure corresponding to the largest straight-line distance is selected as the correction figure at the lower right corner of the QR code area image, and the center point coordinates of the correction figure at the lower right corner of the QR code area image are obtained.
[0039] Optionally, in the positioning method of the QR code position detection pattern, if the number of the correction patterns is equal to 0, then according to the three position detection patterns in the QR code area image, the calculation formula for obtaining the center point coordinates of the correction pattern in the lower right corner of the QR code area image is:
[0040] x4=x1+x3-x2;
[0041] y4=y1+y3-y2;
[0042] Wherein, (x4, y4) is recorded as the coordinate of the center point of the correction figure at the lower right corner of the QR code area image; x4 is the horizontal coordinate of the correction figure at the lower right corner; y4 is the vertical coordinate of the correction figure at the lower right corner;
[0043] x1 is the horizontal coordinate of the position detection figure of the lower left corner; y1 is the vertical coordinate of the position detection figure of the lower left corner;
[0044] x2 is the horizontal coordinate of the position detection figure of the upper left corner, and y2 is the vertical coordinate of the position detection figure of the upper left corner;
[0045] x3 is the horizontal coordinate of the position detection figure of the upper right corner; y3 is the vertical coordinate of the position detection figure of the upper right corner.
[0046] On the other hand, the embodiment of the present application further provides a positioning system for a QR code position detection pattern, wherein the QR code original image includes: a position detection pattern and a correction pattern, and the positioning system for the QR code position detection pattern includes:
[0047] a detection module, used for roughly positioning the QR code original image to determine the QR code area, and for detecting the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern;
[0048] an operation processing module, configured to scan the position detection pattern using a scanning method according to the detection frame information of the position detection pattern to obtain the coordinates of the center point of the position detection pattern, and to determine the correction pattern at the lower right corner of the original image of the QR code according to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, and to obtain the coordinates of the center point of the correction pattern at the lower right corner;
[0049] The operation processing module is also used to perform perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image into a QR code standard image; and is also used to decode the QR code standard image.
[0050] The technical solution of this application has at least the following advantages:
[0051] The embodiment of the present application provides a positioning method and positioning system for a QR code position detection pattern, wherein the positioning method comprises: coarsely positioning the QR code original image to determine the QR code area; using a target detection algorithm to detect the position detection pattern and the correction pattern in the QR code area to obtain the detection frame information of the position detection pattern and the detection frame information of the correction pattern; scanning the position detection pattern using a scanning method according to the detection frame information of the position detection pattern to obtain the center point coordinates of the position detection pattern; determining the correction pattern at the lower right corner of the QR code original image according to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, and obtaining the center point coordinates of the correction pattern at the lower right corner; performing perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image to a QR code standard image; and decoding the QR code standard image. This application uses a target detection algorithm to detect the position detection pattern of the QR code, and combines it with a scanning method to determine the coordinates of the center point of the position detection pattern. It solves the defects of the traditional scanning positioning method through deep learning technology, that is, it can solve the problem that the traditional scanning positioning method cannot effectively locate QR codes containing defects such as noise and blur, avoids the problem of deviation or even inability to locate the QR code image position detection pattern, and improves the accuracy of QR code position detection pattern positioning. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the specific implementation methods of the present application or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0053] Figure 1is a block diagram of a positioning method for a QR code position detection graphic according to an embodiment of the present invention;
[0054] Figure 2 is a flow chart of a method for locating a QR code position detection pattern according to an embodiment of the present invention;
[0055] Figure 3 is a schematic diagram of an original image of a QR code according to an embodiment of the present invention;
[0056] Figure 4 is a schematic diagram of a QR code region image obtained by roughly positioning the QR code original image according to an embodiment of the present invention;
[0057] Figure 5 is a schematic diagram of a QR code region image in which a position detection pattern has defects according to an embodiment of the present invention;
[0058] Figure 6 is a schematic diagram of the preprocessing result of the QR code area image in step S30.1 of an embodiment of the present invention;
[0059] Figure 7 It is a schematic diagram of the results of detecting the coordinates of the center point of a positioning position and correcting the coordinates of the center point of a positioning position according to an embodiment of the present invention;
[0060] Figure 8 is a schematic diagram of a QR code standard image after perspective transformation correction according to an embodiment of the present invention;
[0061] Fig. 9 It is a structural schematic diagram of a positioning system for a QR code position detection graphic according to an embodiment of the present invention. DETAILED DESCRIPTION
[0062] The following will be combined with the accompanying drawings to clearly and completely describe the technical solutions in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0063] In the description of the present application, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present application. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0064] In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, it can also be the internal connection of two components, it can be a wireless connection, or it can be a wired connection. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0065] In addition, the technical features involved in the different embodiments of the present application described below can be combined with each other as long as they do not conflict with each other.
[0066] The original image of the QR code generally includes positioning graphics such as a position detection graphic and a correction graphic.
[0067] This application embodiment provides a method for locating a QR code position detection pattern. Please refer to Figure 1 , Figure 1 : is a block diagram of a positioning method for a QR code position detection pattern according to an embodiment of the present invention, wherein the positioning method for a QR code position detection pattern comprises:
[0068] S10: performing coarse positioning on the QR code original image to determine the QR code area.
[0069] S20: Detecting the position detection pattern and the correction pattern in the QR code area using a target detection algorithm to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern.
[0070] S30: According to the detection frame information of the position detection pattern and the detection frame information of the correction pattern, obtain the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern at the lower right corner in the QR code area. Step S30 may specifically include: according to the detection frame information of the position detection pattern, scanning the position detection pattern using a scanning method to obtain the center point coordinates of the position detection pattern; according to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, determine the correction pattern at the lower right corner of the QR code original image, and obtain the center point coordinates of the correction pattern at the lower right corner.
[0071] S40: Performing perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image into a QR code standard image.
[0072] S50: Decoding the QR code standard image.
[0073] Please refer to Figure 2 , Figure 2 1 is a flow chart of a method for locating a QR code position detection pattern according to an embodiment of the present invention. Next, the method for locating a QR code position detection pattern is described in detail.
[0074] First, step S10: roughly locate the QR code original image to determine the QR code area. The specific steps may include:
[0075] Step S10.1: Scale the QR code original image to a preset size, and perform normalization on the scaled QR code original image. In this embodiment, the QR code original image may be scaled to a size of (320, 320). The specific normalization process satisfies the following method:
[0076]
[0077] Among them, mean_value = [0.485, 0.456, 0.406] is the mean of the three channels of the image, and std_value = [0.229, 0.224, 0.225] is the variance of the three channels of the image.
[0078] Step S10.2: Use a target detection algorithm to roughly locate the scaled QR code original image to determine the QR code area. In this embodiment, the target detection algorithm used to roughly locate the scaled QR code original image is YoloV5-Nano. Because the scale of the QR code original image is unstable, three detection heads with downsampling multiples of 8, 16, and 32 are required when detecting the QR code original image, corresponding to small, medium, and large scale QR code original images, respectively. The QR code original image used for detection in this embodiment can be referred to Figure 3 The original QR code image detected in the QR code area can be referenced Figure 4 .
[0079] Then, step S20: using a target detection algorithm to detect the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern, the specific steps may include:
[0080] Step S20.1: scaling the QR code region image within the QR code region to a preset size, and normalizing the scaled QR code region image;
[0081] Step S20.2: Use a target detection algorithm to detect the position detection graphic and the correction graphic of the QR code area image to obtain the detection frame information of the position detection graphic and the detection frame information of the correction graphic, wherein the target detection model used is YoloV5-FP. In this embodiment, because the scale of the detection target is relatively fixed, the three detection heads originally downsampled to 8, 16, and 32 are reduced to two detection heads downsampled to 8 and 16. Secondly, on the basis of the target detection model YoloV5-Nano, the number of channels of the backbone network is reduced to make the detection model faster and smaller in size. After many experiments, the inventor finally determined that the target detection model YoloV5-FP, which can achieve better positioning accuracy and ensure the real-time performance of the algorithm on a variety of hardware devices, is used as the target detection model of step S20.2. The number of channels of the p1, p2, p3, p4, and p5 layers are 16, 32, 64, 64, and 128, respectively. In order to verify the robustness of YoloV5-FP, such as Figure 5 As shown, this embodiment selects a QR code area image with defects in the position detection pattern, and the target detection model YoloV5-FP can accurately locate the position detection pattern in the QR code area.
[0082] Next, step S30: according to the detection frame information of the position detection pattern, the position detection pattern is scanned by a scanning method to obtain the coordinates of the center point of the position detection pattern; according to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, the correction pattern at the lower right corner of the original image of the QR code is determined, and the coordinates of the center point of the correction pattern at the lower right corner are obtained. Further, step S30 may specifically include:
[0083] Step S30.1: pre-processing the QR code region image so that the pixel values of the QR code region image only include 0 and 255. Specifically, step S30.1 may further include:
[0084] Step S30.11: performing histogram equalization to nonlinearly stretch the grayscale of the QR code region image;
[0085] Step S30.12: removing noise points in the QR code area image by median filtering;
[0086] Step S30.13: Binarize the QR code region image using the Otsu method so that the pixel values of the QR code region image only contain 0 and 255. For the preprocessing result of the QR code region image, please refer to Figure 6 .
[0087] Step S30.2: acquiring the number of detection frames of the position detection pattern according to the detection frame information of the position detection pattern;
[0088] Step S30.3: If the number of detection frames of the position detection graphics is greater than or equal to 3, the detection frames of the three position detection graphics with the highest scores are screened out as position detection graphics, and according to the pixel values of the QR code area image, the three position detection graphics are scanned by a scanning method to obtain the center point coordinates of the position detection graphics; if the number of the position detection graphics is less than 3, according to the pixel values of the QR code area image, a scanning method is used to perform a global scan of the QR code area image to obtain three position detection graphics, and the center point coordinates of the three position detection graphics are obtained.
[0089] Since the position of the detection frame may deviate from the actual position, the three position detection patterns are scanned by a scanning method according to the pixel value of the QR code area image to obtain the center point coordinates of the position detection patterns, so that the center point coordinates can be determined more accurately.
[0090] In this embodiment, if the number of detection frames of the position detection pattern is greater than or equal to 3, the step of selecting the detection frames of the three position detection patterns with the highest scores as the position detection patterns, and scanning the three position detection patterns using a scanning method according to the pixel values of the QR code area image to obtain the coordinates of the center point of the position detection pattern may further include:
[0091] The first step: selecting the detection frames of the three position detection patterns with the highest scores as the position detection patterns;
[0092] The second step: scanning the position detection pattern line by line, wherein every 5 segments form a scan line, and the pixel values between the segments alternate between 0 and 255, to obtain a scan line that satisfies the 1:1:3:1:1 rule;
[0093] Step 3: Record the position of the first scan line and the position of the last scan line that satisfy the 1:1:3:1:1 rule, wherein the first scan line, the last scan line and the middle dark module of the position detection pattern intersect at four points, which are recorded as A, B, C and D;
[0094] Step 4: Set the intersection of points A, B, C, and D as the virtual center point, and verify whether the vertical scan line passing through the virtual center point satisfies the 1:1:3:1:1 rule; if it satisfies the 1:1:3:1:1 rule, use the virtual center point as the center point of the position detection pattern.
[0095] It is worth noting that if a position detection pattern is damaged due to the quality problem of the QR code image, and the row and column scanning cannot obtain the center point of the position detection pattern, then the upper left corner coordinate (x 11 ,y 11 ) The coordinates of the lower right corner of the detection box corresponding to the position detection pattern (x 21 ,y 21 ) is calculated using the following formula:
[0096]
[0097] Among them, (x i ,y i ) is the coordinate of the center point of the position detection figure, where i≤3.
[0098] Step S30.4: obtaining the number of the correction figures according to the detection frame information of the correction figures;
[0099] Step S30.5: If the number of correction patterns is greater than or equal to 2, the center point coordinates of the correction pattern in the lower right corner of the QR code area image are obtained based on the position detection pattern in the lower left corner and the position detection pattern in the upper right corner of the QR code area image; if the number of correction patterns is equal to 1, the correction pattern is regarded as the correction pattern in the lower right corner of the QR code area image; if the number of correction patterns is equal to 0, the center point coordinates of the correction pattern in the lower right corner of the QR code area image are obtained based on the three position detection patterns in the QR code area image.
[0100] Preferably, in the positioning method of the QR code position detection pattern, if the number of the correction patterns is greater than or equal to 2, the step of obtaining the center point coordinates of the correction pattern in the lower right corner of the QR code area image according to the position detection pattern in the lower left corner and the position detection pattern in the upper right corner in the QR code area image may include:
[0101] Step 1: Obtain the center point coordinates of the position detection pattern at the lower left corner and the position detection pattern at the upper right corner in the QR code area image, as well as the center point coordinates of each correction pattern;
[0102] The second step: calculating the straight-line distance between the center point coordinates of each correction pattern and the center point coordinates of the position detection pattern at the lower left corner and the position detection pattern at the upper right corner;
[0103] The third step: selecting the correction figure corresponding to the largest straight-line distance as the correction figure at the lower right corner of the QR code area image, and obtaining the center point coordinates of the correction figure at the lower right corner of the QR code area image.
[0104] The above-mentioned first step to the third step can also be understood as: first determine the position detection patterns of the lower left corner and the upper right corner. Because in the triangle composed of the three position detection patterns, the line between the lower left corner and the upper right corner is the long side of the triangle, so the two position detection patterns with the largest straight-line distance (Euclidean distance) are the position detection patterns of the lower left corner and the upper right corner, and then calculate the coordinates of their center points, and judge the straight-line distance from the center point of the correction pattern detection frame to the center points of the lower left corner and the upper right corner position detection patterns. The correction pattern with the largest distance is considered to be the correction pattern of the lower right corner, thereby obtaining the center point coordinates of the correction pattern of the lower right corner of the QR code area image.
[0105] Further, if the number of the correction patterns is equal to 0, the calculation formula for obtaining the coordinates of the center point of the correction pattern in the lower right corner of the QR code area image according to the three position detection patterns in the QR code area image is:
[0106] x4=x1+x3-x2;
[0107] y4=y1+y3-y2;
[0108] Among them, (x4, y4) are recorded as the center point coordinates of the correction figure at the lower right corner of the QR code area image; x4 is the horizontal coordinate of the correction figure at the lower right corner; y4 is the vertical coordinate of the correction figure at the lower right corner; (x1, y1) are recorded as the center point coordinates of the position detection figure at the lower left corner of the QR code area image; (x2, y2) are recorded as the center point coordinates of the position detection figure at the upper left corner of the QR code area image, x2 is the horizontal coordinate of the position detection figure at the upper left corner, and y2 is the vertical coordinate of the position detection figure at the upper left corner; (x3, y3) are recorded as the center point coordinates of the position detection figure at the upper right corner of the QR code area image, x3 is the horizontal coordinate of the position detection figure at the upper right corner; y3 is the vertical coordinate of the position detection figure at the upper right corner. For the result diagram of the center point coordinates of the position detection figure and the center point coordinates of the correction figure in this embodiment, please refer to Figure 7 .
[0109] Further, step S40: according to the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern, a perspective transformation matrix is obtained to correct the QR code original image to a QR code standard image. Specifically, in step S30, the center point coordinates of the three position detection patterns and the center point coordinates of the correction pattern are obtained. In step S40, the perspective transformation is performed using these four points to correct the QR code area image to a QR code standard image. The perspective transformation matrix can be obtained by the following formula:
[0110]
[0111] Wherein, (x, y) is the coordinate of any one of the four points (the center points of the three position detection patterns and the center point of the correction pattern) before perspective transformation, (x', y') is the coordinate of the corresponding center point after perspective transformation, ω is the coefficient, and the 3×3 matrix is the perspective transformation matrix H. After obtaining the perspective transformation matrix H, the distorted image can be subjected to inverse perspective transformation. Please refer to Figure 8 , and finally the QR code standard image after perspective transformation correction is obtained.
[0112] Finally, step S50: decoding the QR code standard image. Specifically, in this embodiment, the open source QR code decoding library zxing can be used to decode the QR code standard image.
[0113] Based on the same inventive concept, the present application also provides a positioning system for QR code position detection graphics, please refer to Fig. 9 , Fig. 9 : is a schematic diagram of the structure of a positioning system for a QR code position detection pattern according to an embodiment of the present invention, wherein the positioning system for a QR code position detection pattern comprises:
[0114] A detection module 10, used for roughly positioning the QR code original image to determine the QR code area, and also for detecting the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern;
[0115] The operation processing module 20 is used to scan the position detection pattern using a scanning method according to the detection frame information of the position detection pattern to obtain the coordinates of the center point of the position detection pattern, and to determine the correction pattern at the lower right corner of the original image of the QR code according to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, and obtain the coordinates of the center point of the correction pattern at the lower right corner;
[0116] The operation processing module 20 is further used to perform perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image into a QR code standard image; and is further used to decode the QR code standard image.
[0117] In summary, the embodiment of the present application provides a positioning method and positioning system for a QR code position detection pattern, wherein the positioning method includes: roughly positioning the QR code original image to determine the QR code area; using a target detection algorithm to detect the position detection pattern and the correction pattern in the QR code area to obtain the detection frame information of the position detection pattern and the detection frame information of the correction pattern; scanning the position detection pattern according to the detection frame information of the position detection pattern using a scanning method to obtain the center point coordinates of the position detection pattern; determining the correction pattern at the lower right corner of the QR code original image according to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, and obtaining the center point coordinates of the correction pattern at the lower right corner; performing perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image to a QR code standard image; decoding the QR code standard image. Further, the positioning system includes: a detection module 10 and an operation processing module 20. This application uses a target detection algorithm to detect the position detection pattern of the QR code, and combines it with a scanning method to determine the coordinates of the center point of the position detection pattern. It solves the defects of the traditional scanning positioning method through deep learning technology, that is, it can solve the problem that the traditional scanning positioning method cannot effectively locate QR codes containing defects such as noise and blur, avoids the problem of deviation or even inability to locate the QR code image position detection pattern, and improves the accuracy of QR code position detection pattern positioning.
[0118] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection created by this application.
Claims
1. A method for locating a QR code position detection pattern, characterized in that: The QR code original image includes: a position detection pattern and a correction pattern, and the positioning method of the QR code position detection pattern includes: Performing coarse positioning on the QR code original image to determine the QR code area; Using a target detection algorithm to detect the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern; According to the detection frame information of the position detection pattern and the detection frame information of the correction pattern, the coordinates of the center point of the position detection pattern and the coordinates of the center point of the correction pattern at the lower right corner in the QR code area are acquired; Performing perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image into a QR code standard image; Decoding the QR code standard image; The step of using a target detection algorithm to detect the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern includes: Scaling the QR code region image within the QR code region to a preset size, and performing normalization processing on the scaled QR code region image; Using a target detection algorithm to detect the position detection pattern and the correction pattern of the QR code area image to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern, wherein the target detection model used is YoloV5-FP; The step of obtaining the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern at the lower right corner in the QR code area according to the detection frame information of the position detection pattern and the detection frame information of the correction pattern comprises: Preprocessing the QR code region image so that the pixel values of the QR code region image only include 0 and 255; The number of detection frames of the position detection pattern is obtained according to the detection frame information of the position detection pattern; wherein, if the number of detection frames of the position detection pattern is greater than or equal to 3, the detection frames of the three position detection patterns with the highest scores are screened out as the position detection patterns, and the three position detection patterns are scanned by a scanning method according to the pixel values of the QR code area image to obtain the center point coordinates of the position detection patterns; if the number of the position detection patterns is less than 3, the QR code area image is scanned by a scanning method according to the pixel values of the QR code area image to obtain three position detection patterns, and the center point coordinates of the three position detection patterns are obtained; The number of the correction figures is obtained according to the detection frame information of the correction figures; wherein, if the number of the correction figures is greater than or equal to 2, the center point coordinates of the correction figure at the lower right corner of the QR code area image are obtained according to the position detection figure at the lower left corner and the position detection figure at the upper right corner of the QR code area image; if the number of the correction figures is equal to 1, the correction figure is regarded as the correction figure at the lower right corner of the QR code area image; if the number of the correction figures is equal to 0, the center point coordinates of the correction figure at the lower right corner of the QR code area image are obtained according to the 3 position detection figures in the QR code area image.
2. The method for locating a QR code position detection pattern according to claim 1, characterized in that: The step of roughly locating the QR code original image to determine the QR code area comprises: Scaling the original QR code image to a preset size, and performing normalization processing on the scaled original QR code image; The object detection algorithm is used to roughly locate the scaled QR code original image to determine the QR code area.
3. The method for locating a QR code position detection pattern according to claim 2, characterized in that: The target detection algorithm used for coarse positioning of the scaled QR code original image uses the target detection model YoloV5-Nano.
4. The method for locating a QR code position detection pattern according to claim 1, characterized in that: The step of preprocessing the QR code region image so that the pixel values of the QR code region image only contain 0 and 255 comprises: Performing histogram equalization to nonlinearly stretch the grayscale of the QR code area image; Median filtering removes noise in the QR code area image; The QR code region image is binarized using the Otsu method so that the pixel values of the QR code region image only include 0 and 255.
5. The method for locating a QR code position detection pattern according to claim 1, characterized in that: If the number of detection frames of the position detection pattern is greater than or equal to 3, the step of selecting the detection frames of the three position detection patterns with the highest scores as the position detection patterns, and scanning the three position detection patterns using a scanning method according to the pixel values of the QR code area image to obtain the coordinates of the center points of the position detection patterns includes: Filtering out the detection frames of the three position detection patterns with the highest scores as position detection patterns; Scanning the position detection pattern line by line, wherein every five segments constitute a scan line, and the pixel values between the segments alternate between 0 and 255, to obtain a scan line that satisfies the 1:1:3:1:1 rule; Record the position of the first scan line and the position of the last scan line that satisfy the 1:1:3:1:1 rule; wherein the first scan line, the last scan line, and the middle dark module of the position detection pattern intersect at four points, which are recorded as A, B, C, and D; The intersection of the four points A, B, C, and D is set as the virtual center point, and it is verified whether the scan line in the vertical direction passing through the virtual center point satisfies the 1:1:3:1:1 rule; if it satisfies the 1:1:3:1:1 rule, the virtual center point is used as the center point of the position detection figure.
6. The method for locating a QR code position detection pattern according to claim 1, characterized in that: If the number of the correction patterns is greater than or equal to 2, the step of obtaining the center point coordinates of the correction pattern at the lower right corner of the QR code area image according to the position detection pattern at the lower left corner and the position detection pattern at the upper right corner of the QR code area image comprises: Obtaining the center point coordinates of the position detection pattern at the lower left corner and the position detection pattern at the upper right corner in the QR code area image, as well as the center point coordinates of each of the correction patterns; Calculating the straight-line distance between the center point coordinates of each of the correction patterns and the center point coordinates of the position detection pattern at the lower left corner and the position detection pattern at the upper right corner; The correction figure corresponding to the largest straight-line distance is selected as the correction figure at the lower right corner of the QR code area image, and the center point coordinates of the correction figure at the lower right corner of the QR code area image are obtained.
7. The method for locating a QR code position detection pattern according to claim 1, characterized in that: If the number of the correction patterns is equal to 0, the calculation formula for obtaining the coordinates of the center point of the correction pattern in the lower right corner of the QR code area image according to the three position detection patterns in the QR code area image is: x4=x1+x3-x2; y4=y1+y3-y2; Wherein, (x4, y4) is recorded as the coordinate of the center point of the correction figure at the lower right corner of the QR code area image; x4 is the horizontal coordinate of the correction figure at the lower right corner; y4 is the vertical coordinate of the correction figure at the lower right corner; x1 is the horizontal coordinate of the position detection figure of the lower left corner; y1 is the vertical coordinate of the position detection figure of the lower left corner; x2 is the horizontal coordinate of the position detection figure of the upper left corner, and y2 is the vertical coordinate of the position detection figure of the upper left corner; x3 is the horizontal coordinate of the position detection figure of the upper right corner; y3 is the vertical coordinate of the position detection figure of the upper right corner.
8. A QR code position detection pattern positioning system, used to implement the QR code position detection pattern positioning method according to any one of claims 1 to 7, characterized in that: The QR code original image includes: a position detection pattern and a correction pattern, and the positioning system of the QR code position detection pattern includes: a detection module, used for roughly positioning the QR code original image to determine the QR code area, and for detecting the position detection pattern and the correction pattern in the QR code area to obtain detection frame information of the position detection pattern and detection frame information of the correction pattern; an operation processing module, configured to scan the position detection pattern using a scanning method according to the detection frame information of the position detection pattern to obtain the coordinates of the center point of the position detection pattern, and to determine the correction pattern at the lower right corner of the original image of the QR code according to the detection frame information of the correction pattern and the detection frame information of the position detection pattern, and to obtain the coordinates of the center point of the correction pattern at the lower right corner; The operation processing module is also used to perform perspective transformation on the center point coordinates of the position detection pattern and the center point coordinates of the correction pattern to correct the QR code original image into a QR code standard image; and is also used to decode the QR code standard image.
Citation Information
Patent Citations
QR code image correction method and system
CN104517109A