Two-dimensional code positioning method, two-dimensional code positioning device and computer storage medium
By extracting and filtering candidate points using the QR code positioning method, generating positioning lines and performing grid score statistics, and combining this with caliper precision positioning, the positioning accuracy problem of Aztec codes in complex backgrounds was solved, achieving efficient QR code contour positioning.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG HUARAY TECH CO LTD
- Filing Date
- 2025-04-10
- Publication Date
- 2026-07-24
AI Technical Summary
Aztec codes have low positioning accuracy in complex backgrounds, especially in complex scenarios with high noise, and type identification errors occur frequently.
By acquiring the QR code positioning image, candidate points are extracted and second candidate points that meet the conditions are selected. A positioning line is generated, grid scores are calculated, positioning scores are determined, target candidate points above the threshold are obtained, the QR code position is determined based on the target candidate points, and the QR code type is determined by precise positioning with calipers and fitting a line.
It enables precise positioning of QR codes in complex industrial environments, improves the applicability of Aztec codes, enhances enterprise efficiency, and reduces computational complexity.
Smart Images

Figure CN120633688B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of QR code positioning technology, and in particular to a QR code positioning method, a QR code positioning device, and a computer storage medium. Background Technology
[0002] With the development of information technology and Industry 4.0 in my country, QR codes have been widely used in information transmission, marketing promotion, and payment functions, and their application scenarios are constantly expanding. For example, in industry, they can be used to identify products and track the production process, assembly management, and life cycle of products. Among them, Aztec codes (matrix QR codes) use less space than other codes, can store a large amount of information, and have strong error correction capabilities. Therefore, they are widely used in airline tickets and other travel documents, as well as vehicle registration documents. They can also be used for patient identification, drug identification, samples, and other items related to specific patients in hospitals. Due to the diversification and complexity of application scenarios, the positioning accuracy of Aztec codes in complex backgrounds is relatively low. Summary of the Invention
[0003] To address the aforementioned technical problems, this application proposes a QR code positioning method, a QR code positioning device, and a computer storage medium.
[0004] To address the aforementioned technical problems, this application proposes a QR code positioning method, which includes:
[0005] Obtain the location image of the QR code;
[0006] Extract several first candidate points from the binary image of the QR code positioning image;
[0007] The first candidate points are screened according to preset conditions to determine a number of second candidate points;
[0008] Based on the edge points and rotation angle of each second candidate point, a first positioning line is generated;
[0009] An interval sampling map is obtained based on the first positioning line;
[0010] The grid scores of the interval sampling map are calculated to determine the localization score of each second candidate point;
[0011] Obtain target candidate points whose positioning scores are higher than a preset threshold;
[0012] The location of the QR code is determined based on the target candidate points.
[0013] The step of determining the location of the QR code based on the target candidate point includes:
[0014] Candidate boxes are generated based on the target candidate points;
[0015] Select the point to be located on the candidate edge of the candidate box;
[0016] The point to be positioned is precisely positioned using calipers to determine the precise positioning point;
[0017] Based on the fitted straight line of the precise positioning point, the vertex of the first QR code is determined;
[0018] Determine the location of the QR code based on the first QR code vertex.
[0019] The method for positioning QR codes further includes, after determining the precise positioning point by caliper positioning of the point to be positioned, the step of positioning the point by caliper.
[0020] Based on the precise positioning points, a positioning line and an outward expansion line are fitted;
[0021] Obtain the projection points of the positioning line and the outward expansion line of the target candidate point;
[0022] Obtain the histogram of the projection line segment containing each projection point;
[0023] The QR code type is determined based on the changes in the histogram.
[0024] The step of extracting several first candidate points from the binary image of the QR code positioning image includes:
[0025] Obtain the binary image of the QR code positioning image;
[0026] A horizontal scan is performed on the binary image to determine a horizontal line segment that conforms to a preset horizontal black-and-white module ratio, and the center point of the horizontal line segment is obtained as a third candidate point.
[0027] Based on the third candidate point, the binary image is scanned vertically to obtain the vertical line segment corresponding to each third candidate point.
[0028] A third candidate point corresponding to a vertical line segment that conforms to the preset vertical black and white module ratio is determined and used as the first candidate point.
[0029] The step of filtering the plurality of first candidate points according to preset conditions to determine a plurality of second candidate points includes:
[0030] Obtain the horizontal black-and-white module boundary points on the horizontal line segment and the vertical black-and-white module boundary points on the vertical line segment for each first candidate point;
[0031] Based on the boundary points of the horizontal black and white modules, the horizontal rotation angle of the horizontal line segment is obtained;
[0032] Based on the boundary points of the vertical black and white module, obtain the vertical rotation angle of the vertical line segment;
[0033] Obtain the rotation angle difference between the horizontal rotation angle and the vertical rotation angle;
[0034] First candidate points whose absolute value of the rotation angle difference is less than or equal to a preset angle difference threshold are eliminated, and second candidate points are determined based on the remaining first candidate points.
[0035] The step of obtaining the lateral rotation angle of the lateral line segment based on the boundary points of the lateral black and white modules includes:
[0036] Obtain the eight neighboring points of each horizontal black and white module boundary point;
[0037] Based on the rotation angle of each point among the horizontal black and white module boundary points and the eight neighboring points;
[0038] Map the rotation angle of each point to a preset angle range, and obtain the cumulative sum of the angles and the cumulative sum of the weights for each index number in the preset angle range;
[0039] Obtain the target index number with the maximum cumulative weight sum;
[0040] The horizontal rotation angle of the horizontal line segment is determined based on the cumulative sum of the angles and the cumulative sum of the weights of the target index number.
[0041] The step of mapping the rotation angle of each point to a preset angle range and obtaining the cumulative sum of angles and cumulative sum of weights for each index number in the preset angle range includes:
[0042] Map the rotation angle of each point to a preset angle range, and determine the first index number and the second index number of the target angle range;
[0043] The first weight is determined based on the difference between the rotation angle and the first index number;
[0044] The second weight is determined based on the difference between the rotation angle and the second index number;
[0045] Using the first weight, determine the cumulative weight value of the first index sequence number;
[0046] Using the second weight, determine the cumulative weight value of the second index sequence number;
[0047] Based on the first weight and the rotation angle, determine the cumulative angle value of the first index number;
[0048] Based on the second weight and the rotation angle, determine the cumulative angle value of the second index number;
[0049] After traversing the rotation angles of all points, determine the cumulative sum of angles and the cumulative sum of weights for each index number within the preset angle range.
[0050] The step of obtaining the interval sampling map based on the first positioning line includes:
[0051] The second positioning line pointing inward and the third positioning line pointing outward are determined based on the first positioning line;
[0052] Interval sampling is performed in several module areas formed by the first positioning line, the second positioning line, the third positioning line, and their intersection points to obtain the interval sampling map.
[0053] The step of calculating the grid scores of the interval sampling map and determining the localization score of each second candidate point includes:
[0054] Transform the interval sampling map into a block sampling map;
[0055] The color sampling image is obtained by inverting the colors of the block sampling image;
[0056] Obtain the white module grid from the color sampling image;
[0057] The localization score of each white module grid is determined based on the grayscale difference between its neighboring module grids and the white module grid itself.
[0058] Calculate the localization scores of all white module grids to determine the localization score of the second candidate point.
[0059] The step of determining the positioning score of the white module grid based on the grayscale difference between the neighboring module grids and the white module grid includes:
[0060] When the grayscale difference between the white module grid and the neighboring module grid is greater than the contrast threshold, the positioning score of the white module grid is incremented by 1.
[0061] After traversing all neighboring module grids of the white module grid, determine the positioning score of the white module grid;
[0062] The contrast threshold is determined by the number of grids and the grayscale value of the white module grid, and the number of grids and the grayscale value of the black module grid.
[0063] To address the aforementioned technical problems, this application also proposes a QR code positioning device, which includes a memory and a processor coupled to the memory; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the QR code positioning method as described above.
[0064] To address the aforementioned technical problems, this application also proposes a computer storage medium for storing program data, which, when executed by a computer, is used to implement the aforementioned QR code positioning method.
[0065] Compared with existing technologies, the beneficial effects of this application are as follows: a QR code positioning device acquires a QR code positioning image; extracts several first candidate points from the binary image of the QR code positioning image; filters the several first candidate points according to preset conditions to determine several second candidate points; generates a first positioning line based on the edge points and rotation angle of each second candidate point; acquires an interval sampling map based on the first positioning line; calculates the grid score of the interval sampling map to determine the positioning score of each second candidate point; acquires target candidate points whose positioning scores are higher than a preset threshold; and determines the position of the QR code based on the target candidate points. Through the above QR code positioning method, computational complexity is low, solving the QR code positioning problem in complex industrial environments and achieving accurate QR code contour positioning. Attached Figure Description
[0066] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0067] in:
[0068] Figure 1 This is a flowchart illustrating an embodiment of the QR code positioning method provided in this application;
[0069] Figure 2 This is a schematic diagram of the overall process of the QR code positioning method provided in this application;
[0070] Figure 3 yes Figure 1 The diagram shows the detailed process flow of step S12 in the QR code positioning method.
[0071] Figure 4 This is a schematic diagram of the angular interval classification provided in this application;
[0072] Figure 5 This is an enlarged view of the "bull's eye" locator provided in this application;
[0073] Figure 6 This is a sampling result diagram provided in this application;
[0074] Figure 7 This is a schematic diagram of the "bull's eye" locator provided in this application divided into 49 equal parts;
[0075] Figure 8 This is a schematic diagram showing the color reversal of the "bull's eye" locator provided in this application;
[0076] Figure 9 yes Figure 1 The diagram shows the detailed process flow of step S18 in the QR code positioning method.
[0077] Figure 10 This is a flowchart illustrating another embodiment of the QR code positioning method provided in this application;
[0078] Figure 11 This is a schematic diagram of an embodiment of the QR code positioning device provided in this application;
[0079] Figure 12 This is a schematic diagram of the structure of an embodiment of the computer storage medium provided in this application. Detailed Implementation
[0080] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0081] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0082] The QR codes used in this application include, but are not limited to, Aztec codes. The following explanation uses Aztec codes as an example, but is not limited to them. Aztec codes feature a "bull's eye" pattern at the center, used for positioning the QR code. Data is encoded in concentric square rings around this central pattern. The central pattern is typically 9×9 or 13×13 pixels, and the surrounding data layers gradually expand, forming different versions such as 15×15, 19×19, and 23×23.
[0083] Aztec codes have two different types of structures: compact and full-range. The bullseye pattern locator in the middle is similar to, but not exactly the same as, the locator in a QR (Quick Response Code).
[0084] With the development of machine vision and code reading algorithms, this application proposes an Aztec code localization method and designs an Aztec code fine localization method adapted to complex backgrounds, thereby improving the Aztec code localization accuracy.
[0085] This application's QR code positioning method overcomes the problems of low positioning accuracy and incorrect Aztec code type identification in existing technologies, especially the positioning challenges in complex scenarios such as high noise. By utilizing the "bull's eye" locator feature of Aztec codes, a positioning method adapted to high-noise environments is proposed. A method for automatically determining the Aztec code type is designed: first, the vertex coordinates of the compact "bull's eye" locator are calculated; then, calipers are used to determine if it is a full-range type. If so, the vertex coordinates are updated. Using this method, the positioning accuracy problem of Aztec codes in complex scenarios is effectively solved, thereby improving the applicability of Aztec codes and enhancing enterprise efficiency.
[0086] Please continue reading for details. Figure 1 and Figure 2 , Figure 1 This is a flowchart illustrating an embodiment of the QR code positioning method provided in this application. Figure 2 This is a schematic diagram of the overall process of the QR code positioning method provided in this application.
[0087] The QR code positioning method of this application is applied to a QR code positioning device, which can be a server, a terminal device, or a system in which the server and the terminal device cooperate with each other. Accordingly, the various parts of the QR code positioning device, such as each unit, subunit, module, and submodule, can all be set in the server, all in the terminal device, or separately in the server and the terminal device.
[0088] Furthermore, the aforementioned server can be either hardware or software. When the server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the server is software, it can be implemented as multiple software programs or software modules, such as software or software modules used to provide distributed server functionality, or as a single software program or software module; no specific limitations are made here.
[0089] The main characteristic of Aztec code locators is a single "bull's eye" locator module, with a black-white module ratio of 1:1:1:1:1:1:1.
[0090] The main process of finding the "bull's eye" locator is as follows: perform binarization on the entire image, scan the image pixel by pixel in the horizontal and vertical directions, determine the center position of the locator based on the line segment ratio characteristics, and then calculate the positions of the four vertices of the locator.
[0091] like Figure 1 As shown, the specific steps are as follows:
[0092] Step S11: Obtain the QR code positioning image.
[0093] Step S12: Extract several first candidate points from the binary image of the QR code positioning image.
[0094] In this embodiment, the QR code positioning device performs adaptive threshold segmentation on the QR code positioning image to obtain a binary image, fills the image hole area, scans the entire image to obtain the candidate point positions, and extracts several first candidate points.
[0095] Please refer to the following for details on the process of the QR code positioning device extracting the first candidate point. Figure 4 , Figure 3 yes Figure 1 The diagram shows the detailed process of step S12 in the QR code positioning method.
[0096] like Figure 3 As shown, the specific steps are as follows:
[0097] Step S121: Obtain the binary image of the QR code positioning image.
[0098] In this embodiment, the QR code positioning device performs mean filtering on the QR code positioning image to reduce noise interference. Then, the QR code positioning device uses adaptive threshold segmentation on the QR code positioning image to generate a binary image.
[0099] Specifically, adaptive thresholding is a general image processing algorithm, and its implementation principle can be expressed as follows:
[0100]
[0101] in,
[0102] Specifically, for each pixel srcPixel(x, y), the mean pixel value AvePixel(x, y) within its N*M neighborhood is calculated. Based on the relationship between srcPixel(x, y) and AvePixel(x, y), the resulting pixel value dstPixel(x, y) at that location is output. By processing each pixel in turn, a binary image result can be obtained.
[0103] Furthermore, in cases of high noise or damaged locators, the resulting binary image is not ideal. Hole filling uses the floodfill algorithm to fill the white holes in the black modules of the entire image, ultimately resulting in a complete black module.
[0104] The principle of floodFill is to iterate through the binary image to find all white closed contours, and then perform the following judgment on each closed contour:
[0105]
[0106] HoleArea represents the hole area, and HoleAreaThre is the preset hole area threshold.
[0107] Step S122: Perform a horizontal scan on the binary image to determine a horizontal line segment that conforms to the preset horizontal black-and-white module ratio, and obtain the center point of the horizontal line segment as the third candidate point.
[0108] In this embodiment, on the binary image after hole filling, the entire image is scanned line by line to find all seven adjacent black and white modules with a ratio of 1:1:1:1:1:1:1. The coordinates of the center point of each line segment are recorded as {lPt1,lPt2,...,lPtn}. The aforementioned center points are the third candidate points.
[0109] Step S123: Based on the third candidate point, perform a vertical scan on the binary image to obtain the vertical line segment corresponding to each third candidate point.
[0110] In this embodiment, starting from the midpoint of the line segment obtained by the horizontal scan in step S122, upward and downward scans are performed respectively. Taking the upward scan as an example, the coordinates of the change points from white to black, black to white, and white to black are recorded as {Pt3, Pt2, Pt1}. Similarly, the coordinates of the black and white change points obtained by the downward scan are marked as {Pt4, Pt5, Pt6}. Based on the positions of each black and white point, the proportion of the black and white modules of the vertical scan line segment is calculated. The calculation formula is as follows:
[0111] {Pt6y -Pt5 y :Pt5 y -Pt4 y :Pt4 y -Pt3 y :Pt3 y -Pt2 y :Pt2 y -Pt1 y}
[0112] The QR code positioning device eliminates candidate points corresponding to vertical line segments that do not meet the ratio of 1:1:3:1:1.
[0113] Step S124: Determine the third candidate point corresponding to the vertical line segment that conforms to the preset vertical black and white module ratio, and use it as the first candidate point.
[0114] Step S13: Filter the first candidate points according to preset conditions to determine a number of second candidate points.
[0115] In this embodiment of the application, the QR code positioning device filters out candidate points that meet the angle requirements, that is, it traverses the candidate box composed of each candidate point and filters out candidate points that meet the angle requirements.
[0116] Specifically, the QR code positioning device acquires eight neighboring points of the caliper point in the X direction. Taking point p1 in the horizontal caliper points as an example, eight neighboring points are taken with p1 as the center. Similarly, eight neighboring points of each point are taken to form all 54 points (6*9) for calculating the angle in the X direction.
[0117] The QR code positioning device calculates the X-direction angle. Sobel's formula for calculating the X-direction edge amplitude is:
[0118]
[0119] The formula for calculating the edge angle is:
[0120]
[0121] The rotation angle of 54 pixels in the X direction is calculated using this method.
[0122] Then, the QR code positioning device follows the procedure as follows: Figure 4 The 22 angular intervals shown are classified, with an interval of 8°.
[0123] If an edge point has an angle nAngle = 20°, then it belongs to the interval 16-24, and is assigned to the first weighted value of 16°. The second weight assigned to 24° is V2 = 1 - V1.
[0124] The QR code positioning device recalculates the angle and weight sum under the corresponding index number based on the current weight:
[0125]
[0126] The QR code positioning device uses special processing for the final brightness angle. Within the range of nAngle (0-8 degrees), the weight is expressed as follows:
[0127]
[0128] Within the range of nAngle (176–180 degrees), the weights are expressed as follows:
[0129]
[0130] After obtaining the weights of the 54 points, they are sorted, and the index number with the largest cumulative weight value is selected:
[0131]
[0132] The final formula for calculating the angle of the candidate point is:
[0133]
[0134] Similarly, the QR code positioning device acquires 54 points in the Y direction and calculates the rotation angle in the Y direction as nResultAngle. Y .
[0135] In summary, the QR code positioning device eliminates candidate points that do not meet the requirements based on the X-axis and Y-axis rotation angles of the candidate points. The judgment rules are as follows:
[0136] |nResultAngle X -nResultAngle Y ≤30
[0137] Specifically, if the absolute value of the difference between the rotation angle in the X direction and the rotation angle in the Y direction calculated by the QR code positioning device is less than 30, then the current candidate point is eliminated; otherwise, the current candidate point is retained.
[0138] Step S14: Generate the first positioning line based on the edge points and rotation angle of each second candidate point.
[0139] In this embodiment of the application, the QR code positioning device filters out candidate points that meet the score threshold of the "bull's eye" locator: that is, on the remaining candidate points, the four edge lines of the candidate box formed by the candidate points are adjusted, the score value of the candidate box enclosed by the four lines is calculated, and candidate points that meet the requirements are filtered again.
[0140] Specifically, the QR code positioning device calculates the precise position of the calipers on the QR code positioning image, maps the pyramid diagram onto the QR code positioning image, and then uses the calipers to calculate the precise edge point positions, as shown in the following figure. Figure 5 The enlarged view of the "bull's eye" locator shown.
[0141] The QR code positioning device uses calipers to calculate the precise edge point positions as follows: During the mapping process, points p2 and p5 may not fall exactly on the boundary of the black and white module. Therefore, calipers are used to adjust points p2 and p5 to the boundary of the black and white module.
[0142] Step S15: Obtain an interval sampling map based on the first positioning line.
[0143] In this embodiment, the QR code positioning device calculates the vertex position of the "bull's eye" locator. Figure 5 The calculated precise edge point positions and the rotation angle nResultAngle calculated in step S13 x nResultAngle Y The equations of the four lines are calculated as follows: Figure 5 As shown, the four straight lines A are then shifted inward and outward by one module to form new straight lines, such as the green line B and the blue line C. The four blue lines C are then intersected in pairs, and the positions of the four vertices are calculated to form a rectangle.
[0144] The QR code positioning device acquires the "bull's eye" positioning symbol interval sampling map to obtain the black and white module boundary map. Then, it calculates the intersection points of the lines, obtaining 36 intersection points in the X direction {pEdgePtX1, pEdgePtX2, ..., pEdgePtXn} and 36 intersection points in the Y direction {pEdgePtY1, pEdgePtY2, ..., pEdgePtYn}. Then, it samples at intervals between different modules; the interval sampling result is shown in the image below. Figure 6 As shown.
[0145] Step S16: Calculate the grid score of the interval sampling map and determine the positioning score of each second candidate point.
[0146] In this embodiment of the application, the QR code positioning device calculates the score of the interval sampling image. Specifically, it divides the 14*14 size interval sampling image into 2*2 blocks, transforming it into a 7*7 size image, as shown below. Figure 7 As shown, then Figure 6 The colors of the 49-part sampled image are inverted as follows: Figure 8 As shown, different blocks are marked with different colors according to the following rules:
[0147]
[0148] The QR code positioning device counts the pixel values and black and white marks of 49 modules, and calculates the sum of gray values nSumLightPixel of 16 white modules and the sum of gray values nSumDarkPixel of 33 black modules to obtain the light / dark contrast threshold:
[0149]
[0150] right Figure 8 For each of the 16 white modules, calculate its own grid score. For example, taking white module number 8 as an example, count whether the grayscale difference between all black modules in its 8-neighborhood and the current white module is greater than nContrastThre.
[0151]
[0152] Using the same method, the grid scores of the remaining white modules are calculated. Assuming all modules meet the requirements, the total score is 88.
[0153] Step S17: Obtain the target candidate points whose positioning scores are higher than the preset threshold.
[0154] In this embodiment, the QR code positioning device eliminates candidate points that do not meet the score requirements. Assuming the score threshold is nMinJudgeScore, if nSumScore <= nMinJudgeScore, then the current candidate point is eliminated. The target candidate point is the candidate point with the largest nSumScore among the remaining candidate points.
[0155] Step S18: Determine the position of the QR code based on the target candidate point.
[0156] In this embodiment, the QR code positioning device calculates the vertex coordinates of the "bull's eye" locator. Using calipers, three precise caliper points are calculated on each straight line. These caliper points are then used to fit the lines using the least squares method, and the pairwise intersections of the four lines are calculated as the vertex positions of the "bull's eye" locator.
[0157] For details on the process of the QR code positioning device extracting the vertex position of the "bull's eye" locator, please refer to the following article. Figure 9 , Figure 9 yes Figure 1 The diagram shows the detailed process of step S18 in the QR code positioning method.
[0158] like Figure 9 As shown, the specific steps are as follows:
[0159] Step S181: Generate candidate boxes based on the target candidate points.
[0160] In this embodiment of the application, the QR code positioning device generates candidate boxes based on the positioning points p1 to p6 corresponding to the target candidate points.
[0161] Step S182: Select the point to be located on the candidate edge of the candidate box.
[0162] In this embodiment, the QR code positioning device selects three points {Pt1, Pt2, Pt3} on each side of the candidate frame for caliper-based precise positioning. After precise positioning, a straight line, Line1, is fitted using the least squares method. The function of caliper-based precise positioning is to move the three selected points to the boundary of the black and white module in the image, serving as precise positioning points.
[0163] Step S183: Perform caliper precision positioning on the point to be positioned to determine the precision positioning point.
[0164] Step S184: Based on the fitted straight line of the precise positioning point, determine the vertex of the first QR code.
[0165] In this embodiment, similarly, caliper precision positioning is performed on the other three sides, and then straight lines are fitted. The four fitted straight lines intersect each other in pairs, and the coordinates of the four vertices are {verPt1,verPt2,verPt3,verPt4}.
[0166] Step S185: Determine the QR code positioning position according to the first QR code vertex.
[0167] In this embodiment of the application, the QR code positioning device determines the QR code positioning position in the QR code positioning image based on the four QR code vertices.
[0168] In this application, a QR code positioning device acquires a QR code positioning image; extracts several first candidate points from the binary image of the QR code positioning image; filters the several first candidate points according to preset conditions to determine several second candidate points; generates a first positioning line based on the edge points and rotation angle of each second candidate point; acquires an interval sampling map based on the first positioning line; calculates the grid score of the interval sampling map to determine the positioning score of each second candidate point; acquires target candidate points whose positioning scores are higher than a preset threshold; and determines the position of the QR code based on the target candidate points. This QR code positioning method has low computational complexity, solves the QR code positioning problem in complex industrial environments, and achieves accurate QR code contour positioning.
[0169] Furthermore, in Figure 1Based on the QR code positioning method shown, the QR code positioning device can also perform code type determination, update vertex coordinates, and fit the four edges of the entire code area. Based on the calculated vertex positions, the midpoint of each pair of vertex positions is taken, and the area is expanded outwards by two module sizes. It is then determined whether a white-black-white process has occurred. If all four points meet the requirements, the code type is full-range, thus updating the vertex position of the "bull's eye" locator. According to the rules for storing Aztec code mode messages, the code version is parsed, thereby calculating the coordinates of the four vertices of the entire code area, and then fitting the four edges of the Aztec code.
[0170] Please continue reading for details. Figure 10 , Figure 10 This is a flowchart illustrating another embodiment of the QR code positioning method provided in this application.
[0171] like Figure 10 As shown, the specific steps are as follows:
[0172] Step S21: Fit the positioning line and the outward expansion line based on the precise positioning point.
[0173] Step S22: Obtain the projection points of the positioning line and the outward expansion line of the target candidate point.
[0174] In this embodiment, the QR code positioning device calculates and fits four straight lines to the full-range Aztec code according to the previous steps. Then, it expands each straight line outward by one module, such as the green straight line D, and expands each straight line outward by two modules, such as the red straight line E. Finally, it projects the center point centerPt onto the four green straight lines D to obtain four projection points {proPt1, proPt2, proPt3, proPt4}.
[0175] Step S23: Obtain the histogram of the projection line segment where each projection point is located.
[0176] In this embodiment of the application, the QR code positioning device calculates the histogram of caliper data points. Taking point proPt3 as an example, a data segment is extracted with point proPt3 as the center, with 2 modules above and below, and 0.5 modules to the left and right, and a histogram is generated from this data segment.
[0177] Step S24: Determine the QR code type based on the changes in the histogram.
[0178] In this embodiment, the QR code positioning device determines the Aztec code type. The histogram is traversed from right to left to check if it has undergone three transformation processes: white->black, black->white, and white->black. Similarly, the histograms of the other three projection points are also calculated to check if they have undergone these three transformation processes. If all four points meet the requirements, then the Aztec code type is full-range; otherwise, it is compact.
[0179] If step S24 above determines that the QR code type is a full-range Aztec code, then the vertex coordinates of the "bull's eye" locator can be calculated and updated directly according to step S18 above.
[0180] Finally, the QR code positioning device fits the four edges of the entire Aztec code area. Based on the coordinates of the four vertices of the "bull's eye" locator and the rules for storing Aztec code mode messages, the Aztec code version number information is parsed, thereby calculating the coordinates of the four vertices of the entire code area, and then fitting the four edges of the code.
[0181] The QR code positioning method proposed in this application is an Aztec code "bull's eye" locator positioning method adapted to complex backgrounds, realizing Aztec contour positioning in complex scenarios such as high background noise and damaged "bull's eye" locators.
[0182] This application proposes an Aztec code "bull's eye" locator method for QR code positioning. It calculates candidate points using the features of the locator, and then filters out candidate points that do not meet the requirements by filtering the angle of the candidate box and the score value of the locator. Based on the calculation of the compact type candidate box, it determines whether it is a full-range type. It has low computational complexity and solves the Aztec code positioning problem in complex industrial environments.
[0183] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0184] To implement the above-mentioned QR code positioning method, this application also proposes a QR code positioning device, please refer to the details below. Figure 11 , Figure 11 This is a schematic diagram of an embodiment of the QR code positioning device provided in this application.
[0185] The QR code positioning device 400 in this embodiment includes a processor 41, a memory 42, an input / output device 43, and a bus 44.
[0186] The processor 41, memory 42, and input / output device 43 are respectively connected to the bus 44. The memory 42 stores program data, and the processor 41 is used to execute the program data to implement the QR code positioning method described in the above embodiment.
[0187] In this embodiment, processor 41 can also be referred to as a CPU (Central Processing Unit). Processor 41 may be an integrated circuit chip with signal processing capabilities. Processor 41 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor, or processor 41 can be any conventional processor.
[0188] This application also provides a computer storage medium; please refer to the following: Figure 12 , Figure 12 This is a schematic diagram of a computer storage medium according to an embodiment of the present application. The computer storage medium 600 stores a computer program 61, which, when executed by a processor, is used to implement the QR code positioning method of the above embodiment.
[0189] When the embodiments of this application are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0190] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A QR code positioning method, characterized in that, The QR code positioning method includes: Obtain the location image of the QR code; Extract several first candidate points from the binary image of the QR code positioning image; The first candidate points are screened according to preset conditions to determine a number of second candidate points; Based on the edge points and rotation angle of each second candidate point, a first positioning line is generated; An interval sampling map is obtained based on the first positioning line; The grid scores of the interval sampling map are calculated to determine the localization score of each second candidate point; Obtain target candidate points whose positioning scores are higher than a preset threshold; The location of the QR code is determined based on the target candidate points; The step of filtering the plurality of first candidate points according to preset conditions to determine a plurality of second candidate points includes: Obtain the horizontal black-and-white module boundary points on the horizontal line segment and the vertical black-and-white module boundary points on the vertical line segment for each first candidate point; Based on the boundary points of the horizontal black and white modules, the horizontal rotation angle of the horizontal line segment is obtained; Based on the boundary points of the vertical black and white module, obtain the vertical rotation angle of the vertical line segment; Obtain the rotation angle difference between the horizontal rotation angle and the vertical rotation angle; First candidate points whose absolute value of the rotation angle difference is less than or equal to a preset angle difference threshold are eliminated, and second candidate points are determined based on the remaining first candidate points; The step of obtaining the lateral rotation angle of the lateral line segment based on the lateral black and white module boundary points includes: Obtain the eight neighboring points of each horizontal black and white module boundary point; Based on the rotation angle of each point among the horizontal black and white module boundary points and the eight neighboring points; Map the rotation angle of each point to a preset angle range, and obtain the cumulative sum of the angles and the cumulative sum of the weights for each index number in the preset angle range; Obtain the target index number with the maximum cumulative weight sum; The horizontal rotation angle of the horizontal line segment is determined based on the cumulative sum of the angles and the cumulative sum of the weights of the target index number.
2. The QR code positioning method according to claim 1, characterized in that, Determining the location of the QR code based on the target candidate points includes: Candidate boxes are generated based on the target candidate points; Select the point to be located on the candidate edge of the candidate box; The point to be positioned is precisely positioned using calipers to determine the precise positioning point; Based on the fitted straight line of the precise positioning point, the vertex of the first QR code is determined; Determine the location of the QR code based on the first QR code vertex.
3. The QR code positioning method according to claim 2, characterized in that, After performing precise caliper positioning on the point to be positioned to determine the precise positioning point, the QR code positioning method further includes: Based on the precise positioning points, a positioning line and an outward expansion line are fitted; Obtain the projection points of the positioning line and the outward expansion line of the target candidate point; Obtain the histogram of the projection line segment containing each projection point; The QR code type is determined based on the changes in the histogram.
4. The QR code positioning method according to claim 1, characterized in that, The step of extracting several first candidate points from the binary image of the QR code positioning image includes: Obtain the binary image of the QR code positioning image; A horizontal scan is performed on the binary image to determine a horizontal line segment that conforms to a preset horizontal black-and-white module ratio, and the center point of the horizontal line segment is obtained as a third candidate point. Based on the third candidate point, the binary image is scanned vertically to obtain the vertical line segment corresponding to each third candidate point. A third candidate point corresponding to a vertical line segment that conforms to the preset vertical black and white module ratio is determined and used as the first candidate point.
5. The QR code positioning method according to claim 1, characterized in that, The step of mapping the rotation angle of each point to a preset angle range and obtaining the cumulative sum of angles and cumulative sum of weights for each index number in the preset angle range includes: Map the rotation angle of each point to a preset angle range, and determine the first index number and the second index number of the target angle range; The first weight is determined based on the difference between the rotation angle and the first index number; The second weight is determined based on the difference between the rotation angle and the second index number; Using the first weight, determine the cumulative weight value of the first index sequence number; Using the second weight, determine the cumulative weight value of the second index sequence number; Based on the first weight and the rotation angle, determine the cumulative angle value of the first index number; Based on the second weight and the rotation angle, determine the cumulative angle value of the second index number; After traversing the rotation angles of all points, determine the cumulative sum of angles and the cumulative sum of weights for each index number within the preset angle range.
6. The QR code positioning method according to claim 1, characterized in that, The step of obtaining the interval sampling map based on the first positioning line includes: The second positioning line pointing inward and the third positioning line pointing outward are determined based on the first positioning line; Interval sampling is performed in several module areas formed by the first positioning line, the second positioning line, the third positioning line, and their intersection points to obtain the interval sampling map.
7. The QR code positioning method according to claim 6, characterized in that, The step of calculating the grid scores of the interval sampling map and determining the localization score of each second candidate point includes: Transform the interval sampling map into a block sampling map; The color sampling image is obtained by inverting the colors of the block sampling image; Obtain the white module grid from the color sampling image; The localization score of each white module grid is determined based on the grayscale difference between its neighboring module grids and the white module grid itself. Calculate the localization scores of all white module grids to determine the localization score of the second candidate point.
8. The QR code positioning method according to claim 7, characterized in that, The determination of the localization score of the white module grid based on the grayscale difference between the neighboring module grids and the white module grid includes: When the grayscale difference between the white module grid and the neighboring module grid is greater than the contrast threshold, the positioning score of the white module grid is incremented by 1. After traversing all neighboring module grids of the white module grid, determine the positioning score of the white module grid; The contrast threshold is determined by the number of grids and the grayscale value of the white module grid, and the number of grids and the grayscale value of the black module grid.
9. A QR code positioning device, characterized in that, The QR code positioning device includes a memory and a processor coupled to the memory; The memory is used to store program data, and the processor is used to execute the program data to implement the QR code positioning method as described in any one of claims 1 to 8.
10. A computer storage medium, characterized in that, The computer storage medium is used to store program data, which, when executed by the computer, is used to implement the QR code positioning method as described in any one of claims 1 to 8.