Two-dimensional code positioning method, electronic device, and storage medium
By filtering target candidate points and fitting inner edge lines in QR code images, the problem of inaccurate QR code positioning in complex scenarios is solved, achieving higher accuracy and reliability in QR code positioning.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG HUARAY TECH CO LTD
- Filing Date
- 2025-09-28
- Publication Date
- 2026-07-24
Smart Images

Figure CN121544852B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of task scheduling technology, and in particular to a QR code positioning method, electronic device and storage medium. Background Technology
[0002] In QR code recognition technology, the accuracy of QR code location positioning affects the efficiency and reliability of the entire recognition process. However, in real-world applications, QR code images are often diverse, with issues such as surrounding text interference, being in a zero-silence zone, or background interference, which weaken or destroy the edge features of the locator.
[0003] Current positioning methods directly locate and identify QR codes. However, due to interference around the QR code and the mixing of QR code edges with background edges, it is difficult to accurately detect the effective edges of the locator, which ultimately affects the accuracy of the QR code's location information. Therefore, there is a problem of low accuracy in QR code positioning. Summary of the Invention
[0004] The main technical problem addressed by this application is to provide a QR code positioning method, electronic device, and storage medium that can improve the accuracy of QR code positioning in complex scenarios.
[0005] The first aspect of this application provides a QR code positioning method, which includes: acquiring a QR code image, the QR code image containing a locator of the QR code; determining a number of target candidate points from the QR code image that meet preset filtering conditions; using the number of target candidate points to determine a positioning frame of the locator; selecting a number of first positioning points on each side of the positioning frame, and acquiring the inner edge points corresponding to each first positioning point to obtain a number of second positioning points; fitting the second positioning points to obtain inner edge lines, and shifting the inner edge lines outward to obtain positioning edge lines; and using the positioning edge lines to determine the position information of the QR code.
[0006] A second aspect of this application provides an electronic device including a memory and a processor coupled to each other, the memory storing program data and the processor executing the program data to implement any step of the QR code positioning method described above.
[0007] A third aspect of this application provides a computer-readable storage medium storing program data executable by a processor, the program data being used to implement any step of the QR code positioning method described above.
[0008] The above scheme acquires a QR code image containing its locator. First, it identifies several candidate points from the QR code image that meet preset filtering criteria. Using these candidate points, it determines the locator's bounding box. This candidate point filtering and initial locator box positioning improves the accuracy of locator recognition and reduces interference from irrelevant information. Then, it selects several first locator points on each side of the locator box and obtains the corresponding inner edge points for each first locator point, resulting in several second locator points. It fits these second locator points to obtain inner edge lines, which are then moved outwards to obtain positioning edge lines. These positioning edge lines are used to determine the QR code's position information. Through fine fitting and outward movement of the inner edge, a more accurate positioning edge is obtained, improving the accuracy of QR code position determination. This method can adapt to complex situations such as interference around the QR code, zero-silence zones, and background interference, enhancing the robustness and reliability of the QR code positioning method.
[0009] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this application. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in this application, the accompanying drawings required in the description of the embodiments will be briefly introduced below. Obviously, the 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. Among them: Figure 1 This is a flowchart illustrating an embodiment of the QR code positioning method of this application; Figure 2 This application Figure 1 A flowchart illustrating an embodiment of step S12; Figure 3 This is an example schematic diagram of an embodiment of the first number of pixels in this application; Figure 4 This is an example schematic diagram of an embodiment of the second neighborhood of the initial candidate point in this application; Figure 5 This is an example schematic diagram of an embodiment of the preset direction of this application; Figure 6 This is an example schematic diagram of an embodiment of the search array of this application; Figure 7 This is an example schematic diagram of an embodiment of the edge point of this application; Figure 8 This is a schematic diagram illustrating an example of the 8-neighborhood of edge point X0 in this application; Figure 9 This is an example schematic diagram of an embodiment of all neighboring points in this application; Figure 10This is an example schematic diagram of an embodiment of calculating edge amplitude in this application; Figure 11 This application Figure 1 A flowchart illustrating an embodiment of step S13; Figure 12 This application samples Figure 1 Example schematic diagram of the embodiment; Figure 13 This is an example schematic diagram of an embodiment of the grid block of this application; Figure 14 This application Figure 1 A schematic diagram illustrating an embodiment of step S14; Figure 15 This is a schematic diagram of the structure of an embodiment of the QR code positioning device of this application; Figure 16 This is a schematic diagram of the structure of an embodiment of the electronic device of this application; Figure 17 This is a schematic diagram of the structure of an embodiment of the computer-readable storage medium of this application. Detailed Implementation
[0011] 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.
[0012] The terms "first" and "second" in this application are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such processes, methods, products, or apparatus.
[0013] In this application, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0014] In this document, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, "many" in this document means two or more. Moreover, the term "at least one" in this document means any combination of at least two of any one or more of a plurality of objects. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0015] This application provides the following embodiments, and each embodiment is described in detail below.
[0016] Please see Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the QR code positioning method of this application. The method may include the following steps: S11: Obtain the QR code image, which contains the QR code's locator.
[0017] A QR code (Quick Response Code) is a two-dimensional graphic that uses alternating black and white patterns to record data information. A QR code consists of two parts: a functional graphic and an encoding area. The functional graphic may include locators, which are composed of three nested black and white squares. These locators are positioned in a predetermined ratio and located at the top left, top right, and bottom left corners of the QR code, defining its size and position. For example, they allow scanning devices to quickly identify the QR code's boundaries, orientation, and dimensions. The encoding area records specific data, error correction information, and version information. In some applications, the QR code also includes a white border around the three locators to prevent confusion between the QR code / locators and surrounding data modules.
[0018] It is possible to obtain a QR code image, which may contain the QR code to be located, that is, the QR code image contains the QR code's locator.
[0019] Optionally, the pattern of the two-dimensional code does not meet the preset distribution conditions, the pattern of the two-dimensional code does not meet the conditions of a standard two-dimensional code, etc. For example, not meeting the preset distribution conditions may include any of the following: not consisting of 3 nested large black-and-white squares, the black-and-white modules of the positioning mark do not meet the preset ratio, there are other characters or patterns interfering around the two-dimensional code (or the positioning mark), etc. Exemplarily, the two-dimensional code may be a zero quiet zone, or there are complex scenarios such as interference by text or other characters around the two-dimensional code, or there is background interference in the two-dimensional code.
[0020] Optionally, taking the case where the black-and-white modules of the positioning mark do not meet the preset ratio as an example, the positioning mark of the two-dimensional code meeting the preset ratio may include that the ratio of the black-and-white modules of the positioning mark has the characteristic of 1:1:3:1:1.
[0021] Exemplarily, the pattern of the two-dimensional code with a quiet zone meets the preset distribution conditions, which can represent the two-dimensional code image in normal circumstances. Specifically, the ratio of the black-and-white modules of the positioning mark (such as the "return" - shaped positioning mark) of the two-dimensional code has the characteristic of 1:1:3:1:1. Therefore, the positioning mark provides a good characteristic basis for the positioning of the two-dimensional code. The pattern of the two-dimensional code with a zero quiet zone does not meet the preset distribution conditions, and the two-dimensional code with a zero quiet zone does not have the above-mentioned ratio distribution characteristic. In this case, the periphery of the positioning mark is interfered, overlaps with the surrounding black, and the ratio of the black-and-white modules of the positioning mark only has the characteristic of 1:3:1. Therefore, if the two-dimensional code with a zero quiet zone is positioned by the normal method, it will lead to inaccurate positioning.
[0022] S12: Determine a number of target candidate points that meet the preset screening conditions from the two-dimensional code image.
[0023] Target candidate points can be obtained from the two-dimensional code image by scanning the entire image of the two-dimensional code to determine a number of target candidate points that meet the preset screening conditions. Optionally, the LBP (Local Binary Patterns) algorithm can be used to obtain candidate points, and then the candidate points that meet the requirements are screened using the angles of each candidate point, etc.
[0024] In some embodiments, refer to Figure 2 , the steps of S12 in the above embodiments can be further expanded. Determine a number of target candidate points that meet the preset screening conditions from the two-dimensional code image. This embodiment may include the following steps: S121: Use the preset neighborhood of each pixel point in the two-dimensional code image to screen each pixel point to obtain the first candidate points.
[0025] Optionally, before this step, the two-dimensional code image can be converted into a grayscale image, and the grayscale image can be subjected to a smoothing filtering process to obtain the processed two-dimensional code image to reduce noise interference.
[0026] Then, each pixel can be used as the current pixel, and its preset neighborhood can be used to filter the current pixels to determine whether it should be a first candidate point. In this way, the preset neighborhood of each pixel in the QR code image can be used to filter each pixel and obtain several first candidate points.
[0027] In some implementations, each pixel can be filtered multiple times using its different preset neighborhood to obtain a first candidate point. The range of the preset neighborhood differs with each filtering step; the range of the preset neighborhood in later filtering steps is larger than that in earlier steps. This allows for further filtering within a larger range, improving the accuracy of the selected candidate points. For example, the LBP algorithm can be used to filter candidate points in a QR code image, and then an expanded neighborhood LBP algorithm can be used to further filter each candidate point to obtain the first candidate point.
[0028] Optionally, the first neighborhood of each pixel is used to filter pixels that meet the first neighborhood condition to obtain initial candidate points. The first neighborhood condition includes: the first number corresponding to the pixel is greater than or equal to a first threshold, where the first number is the total number of pixels in the first neighborhood whose grayscale value is greater than that of the pixel.
[0029] For each pixel as the current pixel, the grayscale value of the current pixel is compared with the grayscale value of the surrounding pixels in the first neighborhood (the grayscale value can also refer to the pixel value) to determine the label value corresponding to the current pixel. If the grayscale value of the surrounding pixels is greater than the grayscale value of the current pixel, the label value is the first value (e.g., 1); otherwise, the label value is the second value (e.g., 0). The total number of labels with the first value (e.g., 1) is counted to obtain the first quantity corresponding to the current pixel.
[0030] For example, taking an 8-neighborhood as the first neighborhood, each pixel can be used as the current pixel to obtain its 8-neighborhood, with the center of the neighborhood as the current pixel. The LBP algorithm defines a 3x3 area, using the center pixel as a threshold. The grayscale values of the eight adjacent pixels are compared with the center pixel value. If the surrounding pixels have a higher grayscale value than the center pixel, the position of the surrounding pixels is marked as 1; otherwise, it is marked as 0. This allows us to obtain the label value of each pixel in its first neighborhood. The label value of each pixel can be obtained using the following formula: .
[0031] Here, p(x,y) represents the neighborhood center, i.e., the current pixel, and SrcA(x,y) represents the surrounding pixels in the first neighborhood. Based on the relationship between the surrounding pixels SrcA(x,y) and the current pixel p(x,y), the label value dstA(x,y) of the surrounding pixel is output, which is the result pixel value. By processing each surrounding pixel in turn, the label values of the surrounding pixels in the 8-neighborhood of the current pixel can be obtained.
[0032] For example, please refer to Figure 3 The first number of this pixel is 5. That is, for the neighborhood center (this pixel), there are 5 surrounding pixels in the 8-neighborhood with gray values greater than the gray value of the neighborhood center. In this way, the first number of each pixel in the whole image is obtained, which can also be called the LBP value.
[0033] Then, pixels that meet the first neighborhood condition are selected, that is, pixels whose LBP value is greater than or equal to the first threshold nVoteThre are selected to obtain initial candidate points. That is, when the LBP value of a pixel is greater than or equal to nVoteThre, the pixel is saved as an initial candidate point. The first threshold nVoteThre is a threshold set for whether to save the initial candidate point, and this application does not restrict it.
[0034] Optionally, to achieve better filtering results, LBP filtering is performed by expanding the neighborhood. Using the second neighborhood of each initial candidate point, initial candidate points that meet the second neighborhood conditions are selected to obtain the first candidate points. The range of the second neighborhood is larger than the range of the first neighborhood. The second neighborhood conditions include: the second number corresponding to the initial candidate point is greater than a second threshold, where the second number is the number of grayscale differences within the second neighborhood that are greater than a preset difference; the grayscale difference is the difference between a first statistical grayscale value and a second statistical grayscale value; the first statistical grayscale value is the difference between the sum of grayscale values within the first neighborhood and the maximum grayscale value; and the second statistical grayscale value is the difference between the sum of grayscale values of the pixels in the corresponding neighborhood within the second neighborhood and the minimum grayscale value.
[0035] The second neighborhood of a pixel can include pixels that are at a preset interval from the surrounding pixels in the first neighborhood. For example, for the pixel directly above the current pixel in the 8-neighborhood, a pixel at a 1-pixel interval directly above it can be taken as the pixel directly above the current pixel in the second neighborhood.
[0036] For example, please refer to Figure 4 Black pixels represent the current initial candidate points, green pixels represent the pixels in the first neighborhood (e.g., the 8-neighborhood) of the initial candidate points, orange pixels represent the pixels in the second neighborhood, and blue pixels represent the 8-neighborhood of the orange pixels.
[0037] For each initial candidate point, which is then used as the current initial candidate point, and for the center pixel (the black pixel, i.e., the current initial candidate point), the first statistical gray value of its first neighborhood can be obtained by using the difference between the sum of the gray values in the first neighborhood and the maximum gray value. For example, to obtain the minimum average gray value of the initial candidate points, the following formula can be used: .
[0038] Wherein, minAvg represents the minimum average gray value of the initial candidate point, SumPixel represents the sum of gray values in its first neighborhood (including the initial candidate point), and MaxPixel represents the maximum gray value in its first neighborhood (including the initial candidate point). The minimum average gray value is obtained by taking the difference between the sum of gray values and the maximum gray value. >>3 can represent a right shift of the difference by 3 bits, and so on below. The gray values in various embodiments of this application can also be represented as pixel values, and so on below.
[0039] For the second neighboring pixels (orange pixels) of the initial candidate point, obtain the maximum average gray value of its corresponding 8 neighboring pixels (blue pixels). That is, use the difference between the sum of the gray values in its 8 neighboring pixels (including orange pixels) and the minimum gray value to obtain the maximum average gray value of the second neighboring pixels. This can be expressed by the following formula: .
[0040] Where maxAvg represents the maximum average gray value of the pixels in the second neighborhood, SumPixel represents the sum of gray values in its 8 neighborhoods (including the orange center point), and MinPixel represents the minimum gray value in its 8 neighborhoods (including the orange center point). In this way, the maximum average gray value of each pixel in the second neighborhood can be obtained. That is, for 8 orange pixels, 8 maximum average gray values can be obtained in eight directions: left, right, up, down, lu (upper left), ru (upper right), ld (lower left), and rd (lower right), which can represent the second statistical gray value of the initial candidate points.
[0041] Obtain the difference between the second statistical gray value and the first statistical gray value to get the gray value difference. That is, obtain the difference between the eight maximum average gray values maxAvg and the eight minimum average gray values minAvg, and obtain the eight gray value differences dif[0]~dif[7], which can be expressed by the following formula: .
[0042] Then, determine whether the grayscale difference values dif[0] to dif[7] are greater than the preset difference value nGradThr2. If they are greater than the preset difference value nGradThr2, mark them as 1; otherwise, mark them as 0. Count the number of times they are marked as 1, that is, count the number of times the grayscale difference values dif[0] to dif[7] are greater than the preset difference value nGradThr2, and obtain the second number nSumVote corresponding to the initial candidate points. This process can be expressed by the following formula: .
[0043] Finally, if the second number nSumVote corresponding to the initial candidate point is greater than the second threshold nVoteThre2, then the initial candidate point is retained; otherwise, it is discarded, thus obtaining several first candidate points. Through the above two filtering processes (LBP processing), several first candidate points can be obtained, and all subsequent filtering steps can be based on this batch of first candidate points.
[0044] In some embodiments, after the above steps, coordinate mapping can be performed on each first candidate point to obtain a pyramid image corresponding to the QR code image. The purpose of coordinate mapping is to map the position of the first candidate point on the small pyramid image to the large pyramid image, and to ensure that the coordinates fall as close as possible to the center of the central black module. The coordinates of the small image can be enlarged proportionally, for example, to enlarge the pyramid by one layer, the coordinates can be enlarged by 2 times, etc., and the first candidate points in the pyramid image can be enlarged layer by layer.
[0045] Optionally, the first candidate point can be magnified by a preset factor to obtain the magnified position. For example, if the coordinates of each first candidate point are magnified by a factor of 2, then the first candidate point can be multiplied by 2 to obtain the magnified position. The magnified position of the first candidate point can be represented as follows: .
[0046] Where (curX, curY) represent the coordinates of the first candidate point, and (scaleX, scaleY) represent the magnified position of the first candidate point.
[0047] Then, in the third neighborhood of the magnified position (scaleX, scaleY), for example, the third neighborhood is an 8-neighborhood, the coordinates of the smallest gray value are selected as the position of the first candidate point after magnification.
[0048] For example, the coordinates of the first candidate points can be mapped layer by layer. For example, from layer m to layer m2: Layer[m], Layer[m-1], Layer[m-2], the coordinates of several first candidate points in layer[m] can be mapped to layer[m-1] to obtain the coordinates of several first candidate points in layer[m-1]. Then the coordinates of several first candidate points in layer[m-1] can be mapped to layer[m-2] to obtain the coordinates of several first candidate points in layer[m-2]. And so on. In the process of mapping coordinates layer by layer, the smallest pixel position in the neighborhood is selected each time, so that the coordinate deviation error after multiple mappings can be controlled.
[0049] Optionally, this application may perform candidate point screening and positioning based on the pyramid image of the QR code image, and this application does not impose any restrictions on this.
[0050] S122: Obtain the number of gradient changes of each first candidate point in the preset direction, and use the number of gradient changes to determine the first candidate point that meets the preset gradient condition, and obtain the second candidate point.
[0051] The gradient change count of each first candidate point can be filtered to obtain the gradient change count of each first candidate point in a preset direction. The preset direction includes multiple directions. Then, using the gradient change count, the first candidate point that meets the preset gradient condition is determined, and the second candidate point is obtained.
[0052] In some implementations, with each first candidate point as the center, the number of gradient changes is searched from a preset direction around the first candidate point. The number of gradient changes represents the number of times the first brightness pixel changes to the second brightness pixel and vice versa. The preset gradient conditions include: the total number of gradient changes in multiple directions is greater than a first threshold, and the minimum number of gradient changes in a single direction is greater than a second threshold. The total number of gradient changes is the sum of the number of gradient changes in multiple directions, the minimum number of gradient changes is the minimum value of the number of gradient changes in multiple directions, and the first threshold is greater than the second threshold. Optionally, the first brightness pixel can be a dark pixel, and the second brightness pixel can be a bright pixel.
[0053] Please see Figure 5 Taking each first candidate point as the center, search for a preset length nSearchLength in each of the four X / Y directions, namely up, down, left, and right, and obtain the number of gradient changes in each direction.
[0054] Please continue reading. Figure 6Taking the rightward search as an example, the preset length nSearchLength=10. Starting from the first candidate point (red marked pixel), search to the right, record the pixel values of 10 pixels to the right in sequence, and save them in the search array. The pixel values of each pixel in the search array can be recorded as p[0]~p[9] in sequence.
[0055] The search proceeds from the first brightness pixel to the second brightness pixel, or from dark to bright (i.e., searching for white pixels). The starting point index nBase = 0 (i.e., the first candidate point) is recorded. Starting from p[i], i = nBase + 1 (i.e., the first pixel in the search direction of the first candidate point), each pixel is sequentially used as a search pixel p[i]. It is determined whether each search pixel satisfies the first gradient condition. If it does, the search pixel p[i] is recorded; otherwise, the search continues to the next pixel p[i+1]. Optionally, the first gradient condition includes at least one of the following: the difference between the search pixel p[i] and the previous pixel p[i-1] is greater than or equal to a preset pixel difference nGradThre3; or the difference between the search pixel p[i] and the first candidate point p[nBase] is greater than or equal to a preset pixel difference nGradThre3. In other words, the first gradient condition includes any of the following conditions: .
[0056] If the searched pixel p[i] satisfies the first gradient condition, then the index i is returned, that is, the searched pixel p[i] is recorded; in this way, pixels that change from dark to light can be searched, which is one gradient change. Otherwise, i+1 is returned, and the search continues to the next pixel p[i+1]. If the search reaches the end point (such as pixel p[9]) and the target is still not found, and the first gradient condition is not satisfied, then -1 is returned, and the subsequent search process stops, that is, the search in other directions is not performed.
[0057] Assuming the previous search was successful, the index Index1 is returned. Then, the second brightness pixel change is performed to the first brightness pixel, searching for a bright -> dark pixel, i.e., finding a black pixel. Similar to the above processing, the current starting point index nBase=Index is recorded. Starting from p[i], i=nBase+1, it is determined whether each search pixel satisfies the second gradient condition. If the second gradient condition is satisfied, the search pixel p[i] is recorded; otherwise, the search continues to the next pixel p[i+1]. Optionally, the second gradient condition includes at least one of the following: the difference between the pixel value of the previous pixel p[i-1] and the search pixel p[i] is greater than or equal to the preset pixel difference nGradThre3; the difference between the pixel value of the first candidate point p[nBase] and the search pixel p[i] is greater than or equal to the preset pixel difference nGradThre3. That is, the second gradient condition includes any of the following conditions: .
[0058] If the searched pixel p[i] meets the condition, return the index i; otherwise, add i+1 and continue searching for the next pixel p[i+1]. If the search reaches the endpoint (such as pixel p[9]) and the target is still not found, and the second gradient condition is not met, return -1 and stop the subsequent search process. That is, the search in other directions can be stopped.
[0059] Assuming the previous search was successful, the index Index2 is returned. Then, the search for light -> dark is performed again, which will not be elaborated here. For the search direction to the right, multiple searches for dark -> light and light -> dark can be performed. Each time the search is successful, the gradient change count is incremented by 1 to record the gradient change count and the boundary point of the gradient change in the right direction (the search pixel point p[i] recorded in the above search).
[0060] Following the search method described above, the other three directions are searched sequentially to obtain the number of gradient changes in each direction, resulting in the number of gradient changes nGradChange[0,1,2,3] in the four directions.
[0061] Determine whether the number of gradient changes in multiple directions of the first candidate point meets a preset gradient condition. If the preset gradient condition is met, the first candidate point is selected as the second candidate point. Optionally, the preset gradient condition includes: the total number of gradient changes is greater than a first threshold, and the minimum number of gradient changes is greater than a second threshold; wherein, the total number of gradient changes... The sum of the number of gradient changes in multiple directions is given, with the minimum number of gradient changes being the minimum of these multiple directions. The first threshold number is greater than the second threshold number. For example, the preset gradient condition can be expressed as follows: .
[0062] in, This represents the total number of gradient changes in multiple directions. This represents the minimum gradient change count in multiple directions. nSumGradThre represents the threshold for the first count, which can be 9 for example. nMinGradThre represents the threshold for the second count, which can be 1 for example. This application does not impose any restrictions on this.
[0063] By filtering the number of gradient changes of each first candidate point according to the above preset gradient conditions, first candidate points that do not meet the preset gradient conditions can be excluded.
[0064] S123: Search for edge points for each second candidate point, and use the edge points to remove second candidate points that meet the angle filtering conditions to obtain the target candidate point.
[0065] For each second candidate point, edge points are searched in preset directions. Optionally, the preset directions may include multiple directions. For example, with each second candidate point as the center point, edge points are searched in the four X / Y directions, namely up, down, left, and right. Then, the edge points of the second candidate points can be used to eliminate second candidate points that meet the angle filtering conditions to obtain the target candidate points.
[0066] In some implementations, in each search direction, edge points include edge points where a first brightness pixel transitions to a second brightness pixel; that is, the edge point belongs to the first brightness pixel, and the next pixel of the edge point belongs to the second brightness pixel. For example, using each second candidate point as the center point, searches are performed in the top, bottom, left, and right directions respectively, searching for edge points from dark to bright, bright to dark, and dark to bright. Similar to the search based on the number of gradient changes described above, multiple edge points can be obtained in each direction.
[0067] For example, please refer to Figure 7 The second candidate point is used as the center point. Starting from the center point, edge points are searched in the X and Y directions, that is, the up, down, left and right directions. Six edge points are obtained in the X and Y directions respectively, namely X0, X1, X2, X3, X4, X5, Y0, Y1, Y2, Y3, Y4 and Y5.
[0068] Then, using the edge points of each second candidate point, second candidate points that meet the angle filtering conditions are eliminated to obtain the target candidate points. The angle filtering conditions include: the angle difference between the angle value in the first direction and the angle value in the second direction is less than or equal to a preset angle threshold. Specifically, for each second candidate point, the angle value of the second candidate point in the first direction is obtained using the edge points in the first direction (e.g., the X direction). Using the edge points in the second direction (such as the Y direction), the angle value of the second candidate point in the second direction is obtained. Then, select the second candidate points that meet the angle filtering conditions, that is, eliminate the angle values in the first direction. Angle value with the second direction The second candidate point whose angle difference is less than or equal to a preset angle threshold is selected as the target candidate point. For example, the preset angle threshold can be 30°. The angle filtering condition can be expressed as follows: .
[0069] That is, the absolute value of the angle difference between the angle values in the X direction and the Y direction can be calculated. If the angle difference is less than or equal to 30°, the current second candidate point can be eliminated; otherwise, the current second candidate point is retained. This is how the target candidate point is obtained.
[0070] Optionally, the angle value of the second candidate point in the X direction can be obtained using each edge point in the X direction. For example, obtain the 8-neighborhood of each edge point in the first direction to get all the 8-neighborhood points in the X direction, which can be used as the 8-neighborhood points of the horizontal checkpoint.
[0071] Please see Figures 8 to 9 For each second candidate point, taking the edge point X0 in the X direction as an example, we can obtain the 8-neighborhood of X0, resulting in 9 neighboring points (including the center point). Similarly, we can obtain the 8-neighborhood of each edge point X0, X1, X2, X3, X4, and X5 in the X direction as the 8-neighborhood of the lateral checkpoint of the second candidate point, containing 54 neighboring points (6*9).
[0072] For each neighboring point, obtain the edge magnitudes in the X and Y directions. Then, using the edge magnitudes in the X and Y directions, the rotation angle (also called the edge angle) of the neighboring point can be obtained. The Sobel operator can be used to calculate the edge magnitudes.
[0073] For example, please refer to Figure 10 Neighborhood point E includes surrounding pixels A, B, C, D, F, G, H, and J within its 8-neighborhood. The edge magnitude in the X-direction can be obtained by using the difference in the X-direction values among the pixels in the 8-neighborhood of a neighboring point E. The edge magnitude G of neighboring point E in the X-direction... x It can be calculated using the following formula: .
[0074] Following the method described above, the magnitude G of the neighborhood point E at the edge in the Y direction can be obtained. y .
[0075] By using the ratio of the edge magnitudes in the X and Y directions, the rotation angle θ of the neighborhood point E in the X direction can be obtained. The rotation angle θ can be calculated using the following formula: .
[0076] Then, using the above method, the rotation angles of the 54 neighboring points in the X direction can be calculated. The average rotation angle of each neighboring point in the X direction is then taken to obtain the angle value of the second candidate point in the X direction. Similarly, referring to the above method, the angle value of the second candidate point in the Y direction can be obtained. .
[0077] Continue reading Figure 1 Following step S12 above, the following steps are also included: S13: Using several target candidate points, determine the location box of the locator.
[0078] The candidate bounding boxes of the locator can be calculated using several target candidate points, and the evaluation value of each candidate bounding box can be obtained. Based on the evaluation value of each candidate bounding box, the candidate bounding boxes that meet the requirements can be selected, thereby obtaining the bounding boxes of the locator.
[0079] In some embodiments, please refer to Figure 11 This embodiment can further extend step S13 of the above embodiment. Using several target candidate points to determine the location box of the locator, this embodiment may include the following steps: S131: Determine the candidate edge line using the first edge point corresponding to the target candidate point and the rotation angle.
[0080] Candidate edge lines of locators can be determined by using the first edge points (at least some edge points) corresponding to each target candidate point and the corresponding rotation angle (or angle value).
[0081] Optionally, a first edge point can be selected from several edge points corresponding to the target candidate point. For example, the middle edge point can be selected as the first edge point from three edge points in each direction of the target candidate point. For example, edge points X1, X4, Y1, and Y4 can be selected as the first edge points.
[0082] To obtain the first candidate edge line of the first edge point in the QR code image, the first candidate edge line can be determined using the first edge point and the rotation angle. Specifically, the first edge point can be mapped onto the original image of the pyramid image to calculate the precise edge point. Then, using the first edge point and the calculated rotation angle, the first candidate edge line corresponding to the first edge point can be obtained, that is, four candidate edge lines can be obtained.
[0083] The first candidate edge lines can be shifted inward and outward by preset units respectively to obtain the second candidate edge lines. The preset unit can be a module unit, such as the unit of a white module or a black module, etc., and can be determined according to the specific position; this application does not impose any restrictions on this. For example, shifting the four first candidate edge lines outward by one module unit to form a new straight line yields four second candidate edge lines; shifting the four first candidate edge lines inward by one module unit to form a new straight line also yields four second candidate edge lines. The aforementioned first candidate edge lines and / or second candidate edge lines can be used as candidate edge lines.
[0084] Optionally, candidate edge lines corresponding to each edge point can be obtained by using each edge point X0, X1, X2, X3, X4, X5, Y0, Y1, Y2, Y3, Y4, Y5 and the rotation angle of each edge point, resulting in 12 candidate edge lines.
[0085] S132: Perform interval sampling based on candidate edge lines to obtain the sampling map of the locator.
[0086] By sampling at intervals along the candidate edge lines, a number of sampling points can be obtained. Based on these sampling points, an adoption map of the locator can be obtained.
[0087] Optionally, the overlapping range between each candidate edge line can be obtained, and sampling can be performed within each overlapping range at preset intervals to obtain several sampling points. The several sampling points can be located between each candidate edge line.
[0088] Please see Figure 12 Each sampling point can be distributed to a map of a preset size (such as 14*14) to obtain a sampling map of the locator.
[0089] S133: Remove sampled images that do not meet the preset evaluation conditions to obtain candidate boxes for locators.
[0090] The evaluation values of each sampled image are obtained to eliminate sampled images that do not meet the preset evaluation conditions, thus obtaining candidate boxes for locators. The preset evaluation conditions include an evaluation value greater than a preset evaluation threshold. The evaluation value is obtained based on the grid score of preset color blocks in the sampled images; for example, preset color blocks may include white blocks.
[0091] In some implementations, the sampled image is divided into several grid blocks. Then, the evaluation value of the sampled image is determined using the fourth neighborhood (e.g., 8-neighborhood) of each preset color block. Thus, sampled images whose evaluation values do not meet the preset evaluation conditions are eliminated, resulting in candidate boxes for the locators.
[0092] For details, please refer to Figure 13 The sampled image can be divided into blocks of a preset size (e.g., 2*2) to obtain 7*7 grid blocks, containing 49 grid blocks.
[0093] Optionally, each grid block can be marked as a black block or a white block according to a preset rule. For example, black blocks can be marked as 0 and white blocks as 1. An example, the preset rule can be expressed by the following formula: .
[0094] in, This indicates that the grid block at coordinate (0,0) is marked as 1. This indicates that the grid block at coordinate (0,0) will be marked as 0.
[0095] Using the fourth neighborhood of a white block (e.g., a black block in its 8-neighborhood), the grid score of each white block is determined. The grid score of each white block is then calculated to obtain the evaluation value of the sampled image. Specifically, the sum of grayscale values of all 16 white blocks (nSumLightPixel) and the sum of grayscale values of all 33 black blocks (nSumDarkPixel) can be obtained. The contrast threshold nContrastThre of the sampled image is then calculated using the sum of these two grayscale values, as follows: .
[0096] For each of the 16 white blocks in the sampled image, calculate its individual grid score. For example, taking white block number 8 as an example, check if the grayscale difference between the current white block and all its 8-neighboring black blocks is greater than the score threshold nContrastThre. If it is greater than the score threshold nContrastThre, then accumulate its grayscale differences. For example, the grid score of white block number 8 can be represented as follows: .
[0097] Where nSumScore represents the grid score of the white block. This represents the current white block; the others... to This represents the black block in the 8-neighborhood of the white block.
[0098] Using the same method, the grid scores of the remaining white blocks are calculated. Assuming all colored blocks meet the requirements, the total score is 88.
[0099] The sum of the grid scores for all white blocks can be obtained to get the evaluation value of the sampled image. If the evaluation value is greater than the preset evaluation threshold nMinScore, the sampled image is retained; otherwise, if the evaluation value is less than or equal to the preset evaluation threshold nMinScore, the sampled image is removed, that is, the candidate box corresponding to the current sampled image is removed.
[0100] Following the above method, by removing sampled images whose evaluation values do not meet the preset evaluation conditions, the retained sampled images can be used as candidate boxes for locators.
[0101] S134: Obtain candidate boxes that meet the preset combination conditions, and obtain the positioning boxes of the locator.
[0102] By utilizing the combination relationships of candidate boxes of several locators, candidate boxes that satisfy preset combination conditions are obtained, thus obtaining the locator's bounding box. The preset combination conditions include minimizing the combination error value. The combination relationship includes combinations of three candidate boxes; for example, there may be two sets of two candidate boxes in a parallel relationship, and one set of two candidate boxes in a diagonal relationship.
[0103] In some implementations, the similarity error value and positional relationship between each pair of candidate boxes can be obtained, thereby determining whether the positional relationship is parallel.
[0104] Optionally, the similarity error between the two candidate boxes can be obtained using the area error and scale error. For example, the similarity error between the two candidate boxes can be expressed by the following formula: .
[0105] Where fSimilarErr represents the similarity error value. This represents the area error between the two candidate boxes. This represents the scale error of the two candidate boxes, such as the aspect ratio error.
[0106] Optionally, the positional relationship can include a parallel relationship or a diagonal relationship. For example, the top left candidate box and the top right candidate box are parallel, the top left candidate box and the bottom left candidate box are parallel, and the bottom left candidate box and the top right candidate box are diagonal.
[0107] The combination error value of each combo box is obtained. Each combo box contains a preset number of candidate boxes. The combination error value includes the similarity error value between two candidate boxes with a first positional relationship, the similarity error value between two candidate boxes with a second positional relationship, and the distance error value between any two candidate boxes. For example, if a combo box contains three candidate boxes, with the first positional relationship being parallel and the second positional relationship being diagonal, two sets of similarity error values between two candidate boxes with the first positional relationship and one set of similarity error values between two candidate boxes with the second positional relationship can be obtained.
[0108] For example, the combo box contains candidate box i, candidate box j, and candidate box m. The combo error value fErrScore of the combo box can be calculated using the following formula: .
[0109] in, The similarity error value represents two parallel candidate boxes (i and j); This represents the similarity error value between two parallel candidate boxes (j and m). This represents the similarity error value between two candidate boxes (i and m) that are diagonally related. This represents the distance error value between any two candidate boxes, and can contain up to three sets of distance error values.
[0110] Based on the combination relationships of any three candidate boxes, the combination of positioning boxes that can form a locator contains two parallel relationships and one diagonal relationship. Calculate the combination error value of all combination boxes based on the combination error value of each combination box.
[0111] Select the combo box with the smallest combination error value as the target combo. The combo box values can be sorted from smallest to largest; the smaller the combination error value, the higher the probability that it is a positioned box. The combo box with the smallest combination error value can be selected as the target combo.
[0112] Then, by using the positions of each candidate box in the target combination, the candidate vertices of the QR code are determined, that is, the coordinates of the four vertex positions. Based on the candidate vertices, the positioning box of the locator is obtained.
[0113] For example, based on the positions of the three candidate boxes in the target combination, the coordinates of the four vertices of the QR code can be inferred. For instance, the points p1, p2, and p3 closest to the outermost edges of the three candidate boxes are obtained as the three vertex positions. Then, the center point pc is obtained using these three vertex positions. Finally, using the center point pc and the vertex positions p1, the fourth vertex position p4 is obtained. This gives the coordinates of the four vertices of the QR code. The box formed by the four vertex positions p1, p2, p3, and p4 can represent the locator's bounding box.
[0114] For example, the position p4 of the fourth vertex can be calculated using the following formula: .
[0115] in,( , ) represents the coordinates of the fourth vertex, p4. , ) represents the coordinates of the first vertex, p1. , () represents the coordinates of the center point pc.
[0116] Continue reading Figure 1 Following step S13 above, the following steps are also included: S14: Select several first positioning points on each side of the positioning frame, and obtain the inner edge points corresponding to each first positioning point to obtain several second positioning points; fit the second positioning points to obtain the inner edge line, and move the inner edge line outward to obtain the positioning edge line.
[0117] Several first positioning points are selected on each side of the positioning frame, and the corresponding inner edge points of each first positioning point are obtained to obtain several second positioning points. That is, the inner edge of the positioning frame can be precisely positioned by calipers to obtain the inner edge caliper precise positioning points. Then, the second positioning points are fitted to obtain the inner edge line. By moving the inner edge line outward, the positioning edge line is obtained.
[0118] In some embodiments, please refer to Figure 14 This embodiment can be further extended to step S14 of the above embodiment. This embodiment may include the following steps: S141: Select several first positioning points on the candidate boxes on each side of the positioning box; wherein the side includes the side of one or two candidate boxes.
[0119] The positioning box contains a preset number (e.g., 3) of candidate boxes corresponding to locators. Several first positioning points located on the candidate boxes can be selected on each side of the positioning box, wherein the side contains the side of one or two candidate boxes.
[0120] Optionally, each side of the positioning frame may include a left side, a right side, a top side, and a bottom side. Several first positioning points may be selected on each side and on the side of the candidate frame, for example, 2, 4, or 5 first positioning points may be selected. This application does not limit the number of selections.
[0121] S142: For each first positioning point, determine the inner edge point of the side from the inner direction of the side to obtain the second positioning point corresponding to the first positioning point.
[0122] For each first positioning point, the inner edge point of the side is determined from the inner direction of the side, thus obtaining the second positioning point corresponding to the first positioning point, which is also the inner edge caliper precision positioning point. For example, for the left side of the positioning frame, the inner direction can be represented as a direction from left to right. For example, for the right side of the positioning frame, the inner direction can be represented as a direction from right to left. Similarly, other sides can be treated in a similar way, and this application does not impose any restrictions on this.
[0123] Optionally, an inner edge point refers to the first edge point from the first color pixel to the second color pixel in the direction from the inside of the side. For example, an edge point from a black pixel to a white pixel can also be called an edge caliper point.
[0124] Optionally, the second positioning point includes a second positioning point corresponding to two candidate boxes or a second positioning point corresponding to a single candidate box. For example, if the side of a positioning box contains two candidate boxes, then a first positioning point is selected on the side of the two candidate boxes, thereby obtaining the second positioning point of the two positioning boxes. For example, if the side of a positioning box contains a single candidate box, then a first positioning point is selected on the side of the single candidate box, thereby obtaining the second positioning point of the single positioning box.
[0125] S143: Fit the second positioning point of the side to obtain the inner edge line of the side.
[0126] The second positioning points selected on each side are fitted, such as by line fitting. For example, the least squares method can be used to fit the second positioning points with a straight line to obtain the inner edge lines of each side. This application does not limit the algorithm for line fitting. In this way, the inner edge lines of each side can be obtained, that is, four inner edge lines can be obtained.
[0127] Optionally, the inner edge line includes a first inner edge line obtained by fitting the second positioning points corresponding to two candidate boxes and / or a second inner edge line obtained by fitting the second positioning points corresponding to a single candidate box.
[0128] S144: Translate each inner edge line outward by a preset unit to obtain the corresponding positioning edge line.
[0129] The preset unit can be a module unit, such as the unit of a black module, and this application does not limit this. The inner edge line of each side is translated outward by one module unit to obtain the corresponding positioning edge line, that is, 4 positioning edge lines can be obtained.
[0130] The above steps will be described below with reference to specific embodiments.
[0131] Example 1 The first inner edge line is obtained by fitting a straight line to the inner edge of the two candidate boxes contained on the side of the positioning box. For example, points p1, p2, p3, and p4 on the two candidate boxes are selected from the left side of the positioning box, which are the first positioning points. Then, the edge caliper points from the black pixel to the white pixel are found from left to right to obtain the second positioning points: pt1, pt2, pt3, and pt4.
[0132] A straight line is fitted to the four points pt1, pt2, pt3, and pt4 of the second positioning point to obtain the first inner edge line L1. The first inner edge line L1 is then shifted outward by one module unit to obtain a positioning edge line L2.
[0133] Example 2 The second inner edge line is obtained by fitting a straight line to the inner edge of one candidate box from the side of the positioning box. From the right side of the positioning box, select points p5, p6, p7, p8, and p9 on one candidate box, which are the first positioning points. Then, find the edge caliper points from the black pixel to the white pixel from right to left to obtain the second positioning points: pt5, pt6, pt7, pt8, and pt9.
[0134] Linear fitting is performed on the five points pt5, pt6, pt7, pt8, and pt9 of the second positioning point to obtain the second inner edge line L3. The second inner edge line L3 is shifted outward by one module unit to obtain one positioning edge line L4.
[0135] Following the above method, select the first positioning point on the left, right, top, and bottom sides of the positioning frame to obtain the positioning edge lines of the corresponding sides. That is, the positioning edge lines {Line1, Line2, Line3, Line4} of each side can be obtained.
[0136] Continue reading Figure 1Following step S14 above, the following steps are also included: S15: Use the positioning edge lines to determine the location information of the QR code.
[0137] The location information of the QR code can be determined by using the position of each positioning edge line.
[0138] Optionally, the intersection points of each positioning edge line can be obtained to get the corner positions of the QR code, and then the position information of the QR code can be determined based on the connection of the corner positions.
[0139] For example, by intersecting each of the four positioning edge lines {Line1, Line2, Line3, Line4} in pairs, the four corner points (Pt1, Pt2, Pt3, Pt4) are obtained, which are the corner points of the QR code. Based on the four corner points of the QR code, the position information of the QR code can be determined, and thus, the QR code can be located using this position information.
[0140] The above scheme acquires a QR code image containing its locator. First, it identifies several candidate points from the QR code image that meet preset filtering criteria. Using these candidate points, it determines the locator's bounding box. This candidate point filtering and initial locator box positioning improves the accuracy of locator recognition and reduces interference from irrelevant information. Then, it selects several first locator points on each side of the locator box and obtains the corresponding inner edge points for each first locator point, resulting in several second locator points. It fits these second locator points to obtain inner edge lines, which are then moved outwards to obtain positioning edge lines. These positioning edge lines are used to determine the QR code's position information. Through fine fitting and outward movement of the inner edge, a more accurate positioning edge is obtained, improving the accuracy of QR code position determination. This method can adapt to complex situations such as interference around the QR code, zero-silence zones, and background interference, enhancing the robustness and reliability of the QR code positioning method.
[0141] It is understood that in the above method of specific implementation, the order in which each step is written does not mean 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.
[0142] In some embodiments, this application also provides a QR code positioning device for implementing the QR code positioning method of any of the above embodiments.
[0143] Please see Figure 15 , Figure 15 This is a schematic diagram of an embodiment of the QR code positioning device of this application. The QR code positioning device 20 includes an acquisition module 21, a filtering module 22, an edge module 23, and a position module 24. All modules are interconnected.
[0144] The acquisition module 21 is used to acquire a QR code image, which contains the QR code's locator.
[0145] The filtering module 22 is used to determine several target candidate points that meet the preset filtering conditions from the QR code image; and to determine the positioning box of the locator using the several target candidate points.
[0146] The edge module 23 is used to select several first positioning points on each side of the positioning frame, and obtain the inner edge points corresponding to each first positioning point to obtain several second positioning points; fit the second positioning points to obtain the inner edge line, and move the inner edge line outward to obtain the positioning edge line.
[0147] The location module 24 is used to determine the location information of the QR code by using the positioning edge line.
[0148] It should be noted that the QR code positioning device and the QR code positioning method provided in the above embodiments belong to the same concept. The specific operation methods of each module and unit have been described in detail in the method embodiments and will not be repeated here. In practical applications, the QR code positioning device provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. This application does not impose any limitations on this.
[0149] It is understood that the QR code positioning method in this application can be executed by an electronic device, which can be any device with processing capabilities, such as a mobile device, computer, server, etc., and this application does not impose any restrictions on it. In some possible implementations, the QR code positioning method can be implemented by the processor calling program data stored in memory.
[0150] Please see Figure 16 , Figure 16 This is a schematic diagram of the structure of an embodiment of the electronic device of this application. The electronic device 30 includes a memory 31 and a processor 32 coupled to each other. The memory 31 stores program data, and the processor 32 is used to execute the program data to implement the steps of any embodiment of the QR code positioning method described above. In a specific implementation scenario, the electronic device 30 may include, but is not limited to, a microcomputer or a server. In addition, the electronic device 30 may also include mobile devices such as laptops and tablets, which are not limited herein.
[0151] In this embodiment, processor 32 can also be referred to as a CPU (Central Processing Unit). Processor 32 may be an integrated circuit chip with signal processing capabilities. Processor 32 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 32 can be any conventional processor. Furthermore, processor 32 can be implemented using integrated circuit chips.
[0152] The methods described in the above embodiments can be implemented as computer programs; therefore, this application proposes a computer-readable storage medium. Please refer to [link to relevant documentation]. Figure 17 , Figure 17 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present application. The computer-readable storage medium 40 stores program data 41 that can be executed by a processor. The program data 41 can be executed by the processor to implement the steps of any embodiment of the QR code positioning method described above.
[0153] The computer-readable storage medium 40 in this embodiment includes: a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc., which can store program data 41. Alternatively, it can be a server storing the program data 41. The server can send the stored program data 41 to other devices for execution, or it can run the stored program data 41 itself.
[0154] In some embodiments, the functions or modules of the apparatus provided in this application can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments. For the sake of brevity, this application will not repeat the details here.
[0155] The description of the various embodiments above tends to emphasize the differences between the various embodiments. The similarities or similarities between them can be referred to. For the sake of brevity, the present application will not repeat them here.
[0156] In the several embodiments provided in this application, it should be understood that the disclosed methods and apparatus can be implemented in other ways. For example, the apparatus implementations described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0157] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0158] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0159] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it 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 an electronic 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 of the various embodiments of this application.
[0160] Obviously, those skilled in the art should understand that the modules or steps of this application described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, and thus stored in a computer-readable storage medium for execution by a computing device, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Therefore, this application is not limited to any particular hardware and software combination.
[0161] 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, include: Obtain a QR code image, wherein the QR code image contains a QR code locator; From the QR code image, several target candidate points that meet preset screening conditions are determined, including: By using the preset neighborhood of each pixel in the QR code image, each pixel is filtered to obtain the first candidate point; The number of gradient changes of each first candidate point in a preset direction is obtained. Using the number of gradient changes, the first candidate point that satisfies the preset gradient condition is determined, and the second candidate point is obtained. For each second candidate point, search for edge points, and use the edge points to remove second candidate points that meet the angle filtering conditions to obtain the target candidate point; Using the aforementioned candidate target points, the bounding box of the locator is determined, including: The candidate edge line is determined by using the first edge point corresponding to the target candidate point and the rotation angle; Based on the candidate edge lines, an interval sampling is performed to obtain a sampling map of the locator; Remove sampled images that do not meet the preset evaluation conditions to obtain candidate boxes for locators; Get the candidate boxes that meet the preset combination conditions, and obtain the positioning boxes of the locators; Several first positioning points are selected on each side of the positioning frame, and the inner edge points corresponding to each first positioning point are obtained to obtain several second positioning points; the second positioning points are fitted to obtain inner edge lines, and each inner edge line is translated outward by a preset unit to obtain the corresponding positioning edge line. Determining the location information of a QR code using the positioning edge lines includes: obtaining the intersection points of each positioning edge line to obtain the corner positions of the QR code; and determining the location information of the QR code based on the corner positions.
2. The method according to claim 1, characterized in that, The positioning frame includes a preset number of candidate frames corresponding to positioning symbols; a number of first positioning points are selected on each side of the positioning frame, and the inner edge points corresponding to each first positioning point are obtained to obtain a number of second positioning points. Fitting the second positioning point yields the inner edge line, including: On each side of the positioning frame, a plurality of first positioning points located on the candidate frame are selected; wherein, the side includes the side of one or two candidate frames; For each first positioning point, determine the inner edge point of the side from the inner direction of the side to obtain the second positioning point corresponding to the first positioning point; The second positioning point of the side is fitted to obtain the inner edge line of the side.
3. The method according to claim 2, characterized in that, The inner edge point represents the first edge point from the first color pixel to the second color pixel in the direction from the inside of the side; and / or, the inner edge line includes a first inner edge line obtained by fitting the second positioning points corresponding to two candidate boxes and / or a second inner edge line obtained by fitting the second positioning points corresponding to a single candidate box.
4. The method according to claim 1, characterized in that, The step of filtering each pixel in the QR code image using a preset neighborhood to obtain a first candidate point includes: By utilizing the different preset neighborhoods of each pixel, each pixel is filtered multiple times to obtain the first candidate point; wherein, the range of the preset neighborhood of the subsequent filtering is larger than that of the previous filtering.
5. The method according to claim 4, characterized in that, The step of using different preset neighborhoods of each pixel to perform multiple screenings on each pixel to obtain the first candidate point includes: By utilizing the first neighborhood of each pixel, pixels that meet the first neighborhood condition are selected to obtain initial candidate points; Using the second neighborhood of each initial candidate point, initial candidate points that satisfy the conditions of the second neighborhood are selected to obtain the first candidate point; wherein, the range of the second neighborhood is larger than the range of the first neighborhood. The first neighborhood condition includes: the first number corresponding to the pixel is greater than or equal to the first threshold, where the first number is the total number of pixels in the first neighborhood whose gray value is greater than the pixel. The second neighborhood condition includes: the second number corresponding to the initial candidate point is greater than the second threshold, the second number is the number of gray-level differences in the second neighborhood that are greater than a preset difference, the gray-level difference is the difference between the first statistical gray-level value and the second statistical gray-level value, the first statistical gray-level value is the difference between the sum of gray-level values in the first neighborhood and the maximum gray-level value; the second statistical gray-level value is the difference between the sum of gray-level values of the pixels in the corresponding neighborhood in the second neighborhood and the minimum gray-level value.
6. The method according to claim 5, characterized in that, The step of obtaining the number of gradient changes of each first candidate point in a preset direction includes: From the preset direction of the first candidate point, search for the number of gradient changes, where the number of gradient changes represents the number of times the first brightness pixel changes to the second brightness pixel and the second brightness pixel changes to the first brightness pixel; And / or, the preset direction includes multiple directions, and the preset gradient condition includes: the total number of gradient changes is greater than the first threshold, and the minimum number of gradient changes is greater than the second threshold; wherein, the total number of gradient changes is the sum of the number of gradient changes in multiple directions, the minimum number of gradient changes is the minimum value of the number of gradient changes in multiple directions, and the first threshold is greater than the second threshold.
7. The method according to claim 5, characterized in that, After filtering each pixel in the QR code image using a preset neighborhood to obtain the first candidate point, the process includes: The first candidate point is magnified by a preset factor to obtain the magnified position; In the third neighborhood of the magnified position, the coordinates of the smallest gray value are selected to obtain the position of the first candidate point after magnification.
8. The method according to claim 1, characterized in that, The process of removing sampled images that do not meet the preset evaluation conditions to obtain candidate boxes for locators includes: The sampled image is divided into blocks to obtain several grid blocks; The evaluation value of the sampled image is determined by using the fourth neighborhood of each preset color block; By removing sampled images whose evaluation values do not meet the preset evaluation conditions, candidate boxes for locators are obtained; And / or, determining the candidate edge line using the first edge point corresponding to the target candidate point and the rotation angle includes: Select the first edge point from a plurality of edge points corresponding to the target candidate point; The first candidate edge line is determined using the first edge point and the rotation angle; The first candidate edge line is translated inward and outward by a preset number of units respectively to obtain the second candidate edge line.
9. The method according to claim 1, characterized in that, The step of obtaining candidate boxes that satisfy preset combination conditions to obtain the positioning boxes of the locators includes: Obtain the combination error value of each combo box, wherein the combo box contains a preset number of candidate boxes; the combination error value includes the similarity error value of two candidate boxes with a first positional relationship, the similarity error value of two candidate boxes with a second positional relationship, and the distance error value between each pair of candidate boxes; Select the combo box with the smallest combined error value as the target combo; By using the positions of each candidate box in the target combination, the candidate vertices of the QR code are determined, and the positioning boxes of the locator are obtained based on the candidate vertices.
10. An electronic device, characterized in that, The method includes a memory and a processor coupled to each other, wherein the memory stores program data and the processor executes the program data to implement the QR code positioning method according to any one of claims 1 to 9.
11. A computer-readable storage medium, characterized in that, The system stores program data that can be executed by a processor, the program data being used to implement the QR code positioning method according to any one of claims 1 to 9.