A method and device for positioning a distorted two-dimensional code

By identifying the L edge and clock edge in the QR code image and combining the method of searching for effective clock edges to find lines, the problem of low positioning accuracy when QR code distortion is solved, and a higher positioning accuracy is achieved.

CN115879489BActive Publication Date: 2025-04-29BEIJING LUSTER LIGHTTECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211723396.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2025-04-29
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

In the prior art, when there is distortion in the QR code, the positioning accuracy is low, making it difficult to accurately locate the QR code position.

Method used

By obtaining the scanned image in the scanning area, the line segment is identified to determine the L-edge combination of the QR code graph, and the clock edge segment to be selected is determined based on the L-edge combination, and the line segment is found in the line segment to search for the valid clock edge to locate the position of the QR code graph.

Benefits of technology

The positioning accuracy of QR codes in the presence of distortion is improved, ensuring accurate positioning of QR codes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115879489B_ABST
    Figure CN115879489B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a method and device for positioning a distorted two-dimensional code, the method comprising acquiring a scanned image within a scanned area, identifying line segments in the scanned image, and determining the first L-edge combination of the two-dimensional code graphic in the line segments; determining the first clock edge line segment to be selected according to the first L-edge combination; searching for the first valid clock edge by line search in the first clock edge line segment to be selected; and locating the position of the two-dimensional code graphic according to the first valid clock edge and the first L-edge combination. On the premise of determining the first L-edge combination, the first clock edge to be selected is determined by line search, and the first valid clock edge is searched in the first clock edge line segment to be selected to verify the validity of the first clock edge, thereby improving the positioning accuracy of the two-dimensional code when the two-dimensional code is distorted.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of image processing technology, and in particular to a method and device for locating a distorted two-dimensional code. Background Art

[0002] In the actual application of QR code recognition, projection distortion often occurs due to the process or imaging. Taking DM (Data Matrix) code positioning as an example, the usual positioning method is to search for line segments in the image, find the fixed pattern edge and the L edge, and take the opposite side of the L edge to form an affine rectangle to obtain the DM code area. However, due to shooting reasons, projection distortion often occurs in the actual decoding process, and the angles of adjacent edges are not right angles. Figure 1 Taking DM in the figure as an example, the angle formed by two adjacent sides of the image is not 90 degrees, and the image is blurred and deformed. At this time, the extracted L side still cannot accurately locate the position of the QR code. Therefore, when the QR code is distorted, its positioning accuracy is low. Summary of the invention

[0003] The present application provides a method and device for positioning a distorted two-dimensional code to solve the problem of low positioning accuracy of the distorted two-dimensional code.

[0004] In a first aspect, the present application provides a method for positioning a distorted two-dimensional code, which obtains a scanned image in a scan area, wherein the scanned image includes a two-dimensional code graphic, and the two-dimensional code graphic includes an L edge and a clock edge;

[0005] Identify a line segment in the scanned image to determine a first L-edge combination of the two-dimensional code pattern in the line segment;

[0006] Determine a first clock edge segment to be selected according to the first L edge combination;

[0007] Searching for a first valid clock edge in the first candidate clock edge line segment;

[0008] The position of the two-dimensional code graphic is located according to the combination of the first effective clock edge and the first L edge.

[0009] Optionally, if the first valid clock edge is not found in the first candidate clock edges, the method for locating the distorted two-dimensional code further includes:

[0010] Performing dilation and corrosion processing on the scanned image;

[0011] Identifying a line segment in the scanned image after the dilation and corrosion processing to determine a second L-edge combination of the two-dimensional code graphic in the line segment;

[0012] Determine a second clock edge segment to be selected according to the second L edge combination;

[0013] Searching for a second valid clock edge in the second candidate clock edge line segment;

[0014] The position of the two-dimensional code graphic is located according to the combination of the second effective clock edge and the second L edge.

[0015] Optionally, determining a first candidate clock edge segment according to the first L edge combination includes:

[0016] Two first clock edge search areas are constructed according to the first L edge combination; wherein the two first clock edge search areas have the same extension direction as the two L edges in the first L edge combination, and the endpoints of the first L edge combination are located in the first clock edge search area;

[0017] Acquire a first target line segment in the first clock edge search area, where the first target line segment is: a line segment that forms an L-shaped line segment combination with any line segment in the first L-edge combination;

[0018] A first candidate clock edge line segment is determined based on the first target line segment; the first candidate clock edge line segment is: a line segment whose at least one endpoint among the multiple first target line segments is within the first clock edge search area, whose line segment length is greater than a length threshold, and whose direction deviation from the ideal clock edge is less than a deviation threshold.

[0019] Optionally, searching for a first valid clock edge in the first candidate clock edge line segment includes:

[0020] Obtain the longest line segment among the first clock edge line segments to be selected;

[0021] Calculate the minimum distance between the endpoint of the longest first candidate clock edge segment and the endpoint of the first L edge combination;

[0022] If the minimum distance is less than a first threshold, the longest first candidate clock edge segment is determined as the first valid clock edge segment.

[0023] Optionally, determining a second candidate clock edge segment according to the second L edge combination includes:

[0024] Constructing two second clock edge search areas according to the second L edge combination; wherein the two second clock edge search areas have the same extension direction as the two L edges in the second L edge combination, and the endpoints of the second L edge combination are located within the second clock edge search area;

[0025] Acquire a second target line segment in the second clock edge search area, where the second target line segment is: a line segment that forms an L-shaped line segment combination with a line segment in the second L-edge combination;

[0026] A second candidate clock edge line segment is determined according to the second target line segment, where the second candidate clock edge line segment is: a line segment in which at least one endpoint of the second target line segment is within the second clock edge search area and an angle with the ideal clock edge is less than a first preset angle.

[0027] Optionally, in the step of determining a second candidate clock edge segment according to the second target segment:

[0028] If an endpoint of the second target line segment is located outside the second clock edge search area, the second target line segment in the second clock edge area is retained as a second clock edge line segment to be selected.

[0029] Optionally, searching for a second valid clock edge in the second candidate clock edge segment includes:

[0030] Acquire a third target line segment, where the third target line segment is the longest line segment among the second candidate clock edge line segments;

[0031] If there is only one line segment in the third target line segment, or the length of the third target line segment is greater than a first preset multiple of the ideal clock edge, the third target line segment is determined to be the second valid clock edge.

[0032] Optionally, if there are multiple third target line segments and the length of the third target line segment is less than or equal to a first preset multiple of the length of the ideal clock edge, searching for a second valid clock edge in the second candidate clock edge line segment further includes:

[0033] Acquire a fourth target line segment, where the fourth target line segment is a line segment in the second candidate clock edge line, the angle between the fourth target line segment and the third target line segment being less than a second preset angle, or the length of the fourth target line segment being greater than or equal to a third preset multiple of the length of the ideal clock edge;

[0034] Acquire a fifth target line segment, and merge the collinear line segments in the fourth target line segment to obtain the fifth target line segment;

[0035] The third target line segment and the fifth target line segment are combined to serve as the second valid clock edge.

[0036] Optionally, in the step of searching for a second valid clock edge in the second candidate clock edge segment:

[0037] A distance between an intersection of the second valid clock edge and the second L edge combination and an endpoint of the second L edge combination is less than a second threshold.

[0038] A second aspect of the present application provides a positioning device for a distorted two-dimensional code, comprising: a scanning module: configured to obtain a scanned image in a scanning area, wherein the scanned image includes a two-dimensional code graphic, and the two-dimensional code graphic includes an L edge and a clock edge;

[0039] A recognition module: configured to recognize line segments in the scanned image;

[0040] A determination module: configured to determine an L-edge combination of the two-dimensional code graphic in the line segment; the determination module is further configured to determine a clock edge line segment to be selected according to the L-edge combination;

[0041] Search module: configured to search for a valid clock edge in the clock edge line segment to be selected;

[0042] Positioning module: configured to locate the position of the two-dimensional code graphic according to the combination of the effective clock edge and the L edge.

[0043] The present application provides a positioning method and device for a distorted two-dimensional code. The positioning method for a distorted two-dimensional code includes acquiring a scanned image in a scanning area, wherein the scanned image includes a two-dimensional code graphic, and the two-dimensional code graphic includes an L edge and a clock edge; identifying a line segment in the scanned image to determine a first L edge combination of the two-dimensional code graphic in the line segment; determining a first candidate clock edge line segment according to the first L edge combination; searching for a first valid clock edge by line finding in the first candidate clock edge line segment; determining the first clock edge by line finding on the premise of determining the first L edge combination, and searching for the first valid clock edge in the first candidate clock edge line segment to verify the validity of the first clock edge, so as to improve the positioning accuracy of the two-dimensional code when the two-dimensional code is distorted. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0045] Figure 1 is a distorted DM code image;

[0046] Figure 2 A schematic diagram of the flow of a method for locating a distorted two-dimensional code in an embodiment of the present application;

[0047] Figure 3 A schematic diagram of a process for determining the first L edge combination in a two-dimensional code graphic in an embodiment of the present application;

[0048] Figure 4 A schematic diagram of a method flow for determining a first clock edge to be selected in an embodiment of the present application;

[0049] Figure 5 A schematic diagram of a process for constructing a first clock edge search area in an embodiment of the present application;

[0050] Figure 6 This is a schematic diagram of the structure of the first L-edge combination in an embodiment of the present application;

[0051] Figure 7 A schematic diagram of a process for determining a first valid clock edge segment in an embodiment of the present application;

[0052] Figure 8 This is a flow chart of another method for locating a distorted two-dimensional code in an embodiment of the present application;

[0053] Fig. 9 Schematic diagram of the process of determining the second clock edge to be selected in this embodiment;

[0054] Fig.10 A schematic diagram of a flow chart of a method for locating a distorted two-dimensional code in a feasible embodiment of the present application;

[0055] Fig.11 A schematic diagram of the structure of a positioning device for a distorted two-dimensional code provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] The following embodiments are described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following embodiments do not represent all implementations consistent with the present application. They are only examples of systems and methods consistent with some aspects of the present application as detailed in the claims.

[0057] In the recognition process of the QR code, whether the QR code recognition is successful depends heavily on the accuracy of the code area position positioning. Taking the DM (Data Matrix) code as an example, the DM code positioning feature is the four sides of the DM code, the two sides in L shape on the left are the L sides, and the two sides on the right and upper sides are called clock sides. The positioning process is to first extract all the line segments in the picture, combine them after extraction, and combine a rectangular area. However, this method can locate the position of the QR code when the QR code is not distorted. When the QR code is distorted, the angles of the four sides are different, and the adjacent sides are often not perpendicular, so it is impossible to accurately locate the exact position of the QR code. The present application proposes a positioning method for distorted QR code graphics, which mainly accurately locates the QR code by secondary line finding.

[0058] Figure 2 , which is a flow chart of a method for locating a distorted two-dimensional code in an embodiment of the present application.

[0059] like Figure 2 As shown, the positioning method of the distorted two-dimensional code provided by the present application includes:

[0060] Step S101: Acquire a scanned image within a scan area.

[0061] The scanned image in the scan area includes a two-dimensional code graphic, and the two-dimensional code graphic includes an L edge and a clock edge. In other words, the two-dimensional code is a frame structure composed of two L edges and two clock edges.

[0062] Step S102: Identify line segments in the scanned image to determine the first L-side combination of the two-dimensional code graphic in the line segments.

[0063] In this step, the line segments in the scanned image are identified. Specifically, the identification means may be to identify the line segments in the scanned image by any line finding method, and find the first L-side combination of the QR code in the identified line segments.

[0064] Step S103: Determine a first candidate clock edge segment according to the first L edge combination.

[0065] Specifically, the method for determining the first candidate clock edge segment is the same as the method for determining the first L edge combination in the above steps. It can be understood that the present application is not a separate line finding method, but on the premise of determining the first L edge combination, the clock edge is determined using the same line finding method as that for identifying the first L edge combination.

[0066] Step S104: searching for a first valid clock edge in the first candidate clock edge segment.

[0067] Specifically, the first valid clock edge is found in the first candidate clock edges. It can be understood that this step is also a verification process for whether the clock edge is valid, thereby improving the positioning accuracy of the two-dimensional code image.

[0068] Step S105: Locate the position of the two-dimensional code graphic according to the combination of the first effective clock edge and the first L edge.

[0069] Specifically, the two-dimensional code positioning method provided in this embodiment is implemented by finding a line, first determining the first L edge combination, and then determining the first clock edge by finding a line according to the first L edge combination, thereby positioning the two-dimensional code graphic by the first clock edge and the first L edge combination. The first clock edge includes the first clock edge 1 and the first clock edge 2. The first L edge combination consists of the first L edge L1 and the first L edge L2.

[0070] It can be understood that the number of times of line finding is not limited in this embodiment. That is to say, in this embodiment, if in the process of line finding, the first clock edge is not found under the premise of determining the first L edge combination (wherein, there are three situations in which the first clock edge is not found: the first clock edge 1 is not found, the first clock edge 2 is not found, and both first clock edges are not found), then the line finding process continues. This embodiment only introduces a method for finding the first clock edge under the premise of determining the first L edge combination. In actual application, the positioning process of the distorted QR code can be achieved by continuously finding the line.

[0071] For example, if the first clock edge 1 is not found, the first clock edge 2 has been found by line finding. Then the determined line segments include the first clock edge 2 and the first L edge combination, but the position of the QR code cannot be determined by three line segments, so the line finding process is continued, and the purpose of this line finding is to find the first clock edge 1. Until both first clock edges are found, the QR code is located by the found first clock edge and first L edge combination, thereby improving the positioning accuracy of the QR code.

[0072] Figure 3 It is a schematic diagram of the process of determining the L edge combination in the two-dimensional code graphic in the embodiment of the present application.

[0073] like Figure 3 As shown, determining the first L edge combination of the two-dimensional code graphic is implemented by the following steps S201-S203:

[0074] Step S201: Obtain any two L-shaped line segment combinations.

[0075] Step S202: Determine whether there is a common line segment between the two L-shaped line segment combinations; if so, execute step S203, if not, end.

[0076] Step S203: Select any line segment combination where the common line segment is located as the first L-side combination of the two-dimensional code graphic.

[0077] Specifically, among the multiple line segments of the scanned image, two line segments that can form an L shape are found, and a line segment combination with an L shape can be formed by the two line segments. Two line segment combinations with an L shape are obtained, and it is further determined whether the two line segment combinations with an L shape have a common line segment. If the two line segment combinations with an L shape have a common line segment, then any one of the L-shaped line segment combinations is taken as the L-side combination of the two-dimensional code graphic, and this is used as the initial position, so as to subsequently find the clock side position of the two-dimensional code.

[0078] Among them, the method for judging whether two L-shaped line segment combinations have a common line segment includes: in the two L-shaped line segment combinations, the angle between the line segment relative to the other line segment in each L-shaped line segment combination is greater than 150° (wherein, relative position refers to two line segments that should be parallel in an ideal state), and at the same time, the length difference between the two relative line segments should not be too large, and the difference ratio is controlled within 0.2. For example, if the length of one of the line segments is 1, then the length of the other line segment is within the range of 0.8-1.2 to determine that the two L-shaped line segment combinations have a common line segment.

[0079] Figure 4 The present invention is a flowchart of a method for determining a first candidate clock edge in an embodiment of the present application.

[0080] like Figure 4 As shown, the method for determining the first candidate clock edge is implemented by the following steps S301 to S303:

[0081] Step S301: construct two first clock edge search areas according to the first L edge combination.

[0082] It can be understood that the first L-edge combination is composed of two L-edges, and the first clock edge search area is constructed at the clock edge position corresponding to the L edge, so as to determine the desired first clock edge segment in the first clock edge search area. There are two first clock edge search areas, and the two first clock edge search areas are respectively in the same extension direction as the two L edges. For example, the two L edges extend in the horizontal and vertical directions respectively, then the two first clock edge search areas also extend in the horizontal and vertical directions, and the two endpoints of the first L edge combination are respectively located inside the first clock edge search area. It can be seen that the first clock edge search area is large enough to facilitate accurate search of the first clock edge. Of course, it can also be understood that the two first clock edge search areas are parallel to the two L edges.

[0083] Step S302: Acquire a first target line segment in a first clock edge search area.

[0084] Specifically, the first target line segment is a line segment that can form an L-shaped line segment combination with any line segment in the first L-edge combination. By the same method as in step S202, a line segment that can form an L-shaped line segment combination with any line segment in the first L-edge combination is found in the search area. It can also be understood that the line segment combination with an L shape is also searched, and at this time, one side of the L-shaped line segment combination is in the first clock edge search area, and the other side is an side in the first L-edge combination in the aforementioned embodiment, and all line segments that meet this condition are found.

[0085] It should be emphasized that the L-shaped line segment combination in this application includes "L" in different directions, that is, the L-shaped line segment combination in this application is not "L" in the strict sense. Among them, "L" opens to the right, and the L-shaped line segment combination pointed out in this application includes "L" with different opening directions, including but not limited to opening to the right, opening to the left, opening downward, upward, to the upper right, to the lower right, to the upper left, to the lower left, etc., all of which are included in the L-shaped line segment combination in this application.

[0086] Step S303: determining a first candidate clock edge segment according to the first target segment.

[0087] The first candidate clock edge line segment is a line segment whose at least one endpoint among the multiple first target line segments is within the clock edge search area, whose line segment length is greater than a length threshold, and whose direction deviation from the ideal clock edge is less than a deviation threshold.

[0088] A first candidate clock edge line segment is determined in the first target line segment, that is, a line segment that can be used as the first candidate clock edge is determined in the first target line segment, and the range of the first candidate clock edge is continuously narrowed by finding the line.

[0089] Specifically, the first target line segment can be determined as the first candidate clock edge only if it meets certain conditions. Among the multiple first target line segments, at least one endpoint is within the first clock edge search area, and the line segment length is greater than the length threshold, and the line segment whose direction deviation from the ideal clock edge is less than the deviation threshold is the first candidate clock edge line segment.

[0090] In a feasible embodiment, the deviation threshold value ranges from 25° to 35°. For example, the deviation threshold value is 25°, 30° or 35°. When the deviation threshold value is 30°, the angle between the first candidate clock edge and the ideal clock edge is less than 30°. The length threshold value can be set according to actual conditions.

[0091] Figure 5 A schematic diagram of the process of constructing a first clock edge search area in an embodiment of the present application.

[0092] like Figure 5 As shown, step S301 is implemented by the following steps S401-S402.

[0093] Step S401: Determine an ideal clock edge position according to a first L-edge combination.

[0094] Step S402: construct a first clock edge search area according to the ideal clock edge position.

[0095] In the first clock edge search area in the two-dimensional code pattern, two L edges in the first L edge combination are used to construct the position of the ideal clock edge, and then the first clock edge search area is determined according to the position of the ideal clock edge, and then the desired first clock edge line segment is determined in the first clock edge search area. The ideal clock edge refers to a line segment that is set at the position corresponding to the L edge and can form a two-dimensional code pattern with the first L edge combination.

[0096] Figure 6 Schematic diagram of the structure of the first L-edge combination in the embodiment of the present application.

[0097] See also Figure 6 Specifically, the ideal clock edge is located at the center of the first clock edge search area. That is to say, the first clock edge search area is an area range formed by expanding outward with the ideal clock edge as the center. For example, the side lengths of the two-dimensional code graphic are L1, L2, Clock1, and Clock2, respectively, where L1 and L2 form the first L edge combination, and Clock1 and Clock2 are the ideal clock edge 1 and the ideal clock edge 2, respectively. L1 and Clock2 are parallel to each other and have the same length. L2 and Clock1 are parallel to each other and have the same length. In the process of constructing the first clock edge search area, the position of Clock1 is used as the center position to expand outward to form the first clock edge search area S1, and the position of Clock2 is used as the center position to expand outward to form the clock edge search area S2.

[0098] Specifically, the first clock edge search area S1 and the first clock edge search area S2 have the same size, and the two endpoints of the first L edge combination are respectively located in the first clock edge search area S1 and the first clock edge search area S2. In the first clock edge search area S1, the center position is the ideal clock edge Clock1, and Clock1 and L2 are parallel to each other and have the same size. The size of the first clock edge search area S1 is between 1.3 times and 1.5 times the size of the ideal clock edge Clock1.

[0099] In a feasible embodiment, 1.4 times is taken as an example. That is, the height of the first clock edge search area is 1.4 times the height of the ideal clock edge, and the width of the first clock edge search area is 1.4 times the width of the ideal clock edge. It can be understood that when constructing the first clock edge search area, with the ideal clock edge as the center position, the length of the first clock edge search area is expanded to the left and right by 0.2 times in the horizontal direction, and the width of the first clock edge search area is expanded to the top and bottom by 0.2 times in the vertical direction.

[0100] Figure 7 The figure is a schematic diagram of a process for determining a first valid clock edge segment in an embodiment of the present application.

[0101] like Figure 7As shown, determining the first valid clock edge segment in step S104 is implemented by the following steps S501-S503.

[0102] Step S501: Obtain the longest line segment among the first candidate clock edge segments.

[0103] Step S502: Calculate the minimum distance between the endpoint of the longest first candidate clock edge segment and the endpoint of the first L-edge combination.

[0104] Step S503: If the minimum distance is less than the first threshold, determine the longest first candidate clock edge segment as the first valid clock edge segment.

[0105] Specifically, the searched first candidate clock edge segments are arranged in descending order of length, and the longest first candidate clock edge segment is selected. The distance from the endpoint of the longest first candidate clock edge to the endpoint of the first L edge combination is calculated, and if the smallest distance among the distances is less than the first threshold, it is determined to be the first valid clock edge segment.

[0106] It is worth noting that the first L-edge combination has two endpoints, and the minimum endpoint distance from the endpoint of the first candidate clock edge segment to the first L-edge combination is less than the first threshold, which means: the minimum distance from the endpoint of the first candidate clock edge segment to the two endpoints of the first L-edge combination.

[0107] In a feasible embodiment, the value range of the first threshold is 3-5 pixels, for example, the first threshold is 4 pixels. When the longest first candidate clock edge segment satisfies the minimum distance from the endpoint to the endpoint of the first L-edge combination is less than 4 pixels, the longest first candidate clock edge segment is used as the first valid clock edge segment.

[0108] Figure 8 Another method for locating a distorted two-dimensional code is provided in an embodiment of the present application.

[0109] like Figure 8 As shown, the embodiment of the present application further provides a method for positioning a distorted two-dimensional code. Different from the above embodiment, when the first valid clock edge is not searched, the method for positioning the distorted two-dimensional code further includes:

[0110] Step S601: performing dilation and corrosion processing on the scanned image.

[0111] The two-dimensional code positioning method provided in this embodiment can be understood as, when the first clock edge is not completely found in the first line finding process, the line finding operation is continued after processing the scanned image.

[0112] Specifically, the dilation and corrosion processing of the scanned image includes corrosion processing of the black code in the two-dimensional code image and dilation processing of the white code.

[0113] Step S602: Identify the line segments in the scanned image after the dilation and erosion processing to determine the second L-edge combination of the two-dimensional code graphic in the line segments.

[0114] Step S603: Determine a second candidate clock edge segment according to the second L edge combination.

[0115] Step S604: searching for a second valid clock edge in the second candidate clock edge segment.

[0116] Step S605: Locate the position of the two-dimensional code graphic according to the second effective clock edge and the second L edge combination.

[0117] Specifically, the method of searching for the second valid clock edge in step S602 to step S605 is the same as the method of searching for the first valid clock edge in the aforementioned embodiment. On the premise that the second L edge combination is determined, the second valid clock edge is searched by finding the line. At the same time, the search range is continuously narrowed during the process of finding the line.

[0118] It is worth noting that the first L edge combination is different from the second L edge combination. The second L edge combination can be understood as an L edge combination different from the first L edge combination obtained by performing dilation and corrosion processing on the scanned image without searching for the first valid clock edge.

[0119] Fig. 9 A schematic diagram of a flow chart for determining a second clock edge to be selected provided in the present application.

[0120] like Fig. 9 As shown, an embodiment of the present application further provides a method for positioning a distorted two-dimensional code, wherein determining a second clock edge to be selected includes:

[0121] Step S701: construct two second clock edge search areas according to the second L edge combination.

[0122] Step S702: Acquire a second target line segment in the second clock edge search area.

[0123] Step S703: Determine a second candidate clock edge segment according to the second target segment.

[0124] The second clock edge line segment to be selected is: a line segment in which at least one endpoint of the second target line segment is within the second clock edge search area and the angle between the line segment and the ideal clock edge is smaller than the first preset angle.

[0125] Among them, similar to the above-mentioned embodiment, in the process of determining the second candidate clock edge in the embodiment of the present application, a clock edge area is constructed, and a line search operation is performed in the constructed clock edge area.

[0126] Specifically, two second clock edge search areas are constructed, wherein the two second clock edge search areas are respectively in the same extension direction as the two L edges in the second L edge combination, and the endpoints of the second L edge combination are located in the second clock edge search area. In other words, the search for the second clock edge is limited to the second clock edge search difference, and the search range of the second clock edge to be selected is gradually narrowed by continuously finding lines.

[0127] In some embodiments, step S703 determines the second candidate clock edge segment according to the second target segment, and searches for the second target segment as the second candidate clock edge segment when at least one endpoint is within the second clock edge search area and the angle with the ideal clock edge is less than a first preset angle.

[0128] It can be understood that there are two situations in which at least one endpoint is within the second clock edge search area. One is that both endpoints are within the second clock edge search area. In this case, the entire line segment of the second target segment is within the second clock edge search area. The other is that one endpoint is within the second clock edge search area. In this case, the second target line segment has one endpoint within the second clock edge search area and the other endpoint outside the second clock edge search area. In this case, part of the second target line segment within the second clock edge area is retained as the second clock edge line segment to be selected. Among them, part of the second target line segment within the second clock edge area is understood to be that the boundary line of the second clock edge area divides the second target line segment into two parts, one part is within the second clock edge area, and the other part is outside the second clock edge area, and the line segment within the second clock edge area is retained.

[0129] In a feasible embodiment, the value range of the first preset angle is 25°-35°. For example, the first preset angle is 30°, that is, the line segment with an angle less than 30° with the ideal clock edge is used as the second clock edge line segment to be selected.

[0130] In some embodiments, the method for determining the second valid clock edge includes: searching for the second valid clock edge by line search in the second clock edge to be selected. The longest line segment in the second clock edge to be selected is obtained as the third target line segment. If the third target line segment meets the preset conditions, then the third target line segment is used as the second valid clock edge. In other words, the third line segment that meets the preset conditions is obtained in the second clock edge to be selected as the second valid clock edge. Specifically, the longest line segment in the second clock edge to be selected is selected as the third target line segment, and the third target line segment should meet the following conditions: if there is one third target line segment, or the length of the third target line segment is greater than the first preset multiple of the ideal clock edge, then the third target line segment is the second valid clock edge.

[0131] In a feasible embodiment, the first preset multiple is in the range of 0.4 to 0.6. For example, the first preset multiple is 0.5. For example, if the length of the third target line segment is greater than 0.5 times the length of the ideal clock edge, then the third target line segment is the second valid clock edge.

[0132] If the longest line segment in the second candidate clock edge is not unique and the length of the longest line segment does not satisfy the first preset multiple greater than the ideal clock edge, then other line segments that are collinear with the longest line segment and can be merged are searched and the line segments are merged.

[0133] If, among the remaining line segments in the second candidate clock edge except the third target line segment, there is an angle with the longest line segment that is less than the second preset angle, or if there is a line segment among the remaining line segments whose length is greater than or equal to the third preset multiple of the ideal clock edge, the line segment that meets the above conditions is determined as the fourth target line segment, the fifth target line segment is obtained, and the colinear line segments in the fourth target line segment are merged to obtain the fifth target line segment; the fifth target line segment is merged with the third target line segment to obtain the second valid clock edge.

[0134] Specifically, the condition for determining collinear line segments is to select two fourth target line segments, calculate the angle between the connecting line segment of the two fourth target line segments and one of the fourth target line segments, and if the angle is less than or equal to the third preset angle, the two fourth target line segments are collinear line segments.

[0135] The connecting line segment is the longest line segment among the line segments formed by any connecting lines between the four endpoints of the two fourth target line segments.

[0136] The process of merging collinear line segments is as follows: respectively obtain the coordinates of the starting and ending points of the collinear line segments. Specifically, according to the direction of the collinear line segments, in the coordinate system, the extreme points of the starting and ending points of multiple collinear line segments are taken to obtain the final merged line segment, i.e., the fifth target line segment. The determination of the merging direction of the line segments and the merging method are the same as those of the merging direction of the broken line segments.

[0137] In a feasible embodiment, the second preset angle has a value range of 8-12°, for example, the second preset angle can be 8°, 10°, and 12°. The third preset multiple has a value range of 0.12-0.18 times, for example, the third preset multiple can be 0.14 times, 0.15 times, and 0.16 times. When the second preset angle is 10° and the third preset multiple is 0.15 times, if there is a line segment whose angle with the third target is less than 10°, or the length of the line segment is greater than 0.15 times the ideal clock edge, the line segment is the fourth target line segment.

[0138] In a feasible embodiment, the value range of the third preset angle is less than or equal to 15°, for example, the third preset angle may be 10°, 13°, or 15°.

[0139] In a feasible embodiment, the second valid clock edge should satisfy that the distance from the intersection with the second L edge combination to the endpoint of the second L edge combination is less than a second threshold. By way of example, the value range of the second threshold is 3-5 pixels. For example, the distance between the intersection of the second valid clock edge and the second L edge combination is less than 4 pixels. At this time, the distance refers to the minimum distance between the intersection and the endpoint of the second L edge combination.

[0140] In the line finding method provided in the embodiment of the present application, if the first valid clock edge is not found, the image is corroded and expanded, and the processed image is subjected to the edge finding operation of the same method to further determine the clock edge of the two-dimensional code graphic. It is worth noting that in the actual line finding operation, there may be a variety of situations, such as finding clock edge 1 for the first time, further finding the line to find clock edge 2, or finding clock edge 2 for the first time, further finding the line to find clock edge 1, or not finding any clock edge for the first time, and other situations are also possible. Then, by repeating the line finding operation in the present application, if all the clock edges are not found, the line finding is further continued until all the clock edges are found, thereby realizing the positioning of the two-dimensional code graphic.

[0141] Fig.10 This is a method for positioning a distorted two-dimensional code in a feasible embodiment of the present application.

[0142] like Fig.10 As shown, the positioning method of the distorted QR code includes:

[0143] Step S801: whether to perform a secondary line search operation; if yes, execute step S802, if no, execute step S803.

[0144] Specifically, in the positioning of the distorted two-dimensional code, it is first determined whether to perform a secondary line search operation, wherein the secondary line search operation is introduced in the aforementioned embodiment, and the clock edge is determined by twice finding the line on the premise of determining the L edge combination.

[0145] Step S802: Use the L edge of the same DM code group to search for the clock edge.

[0146] Step S803: Grouping the L edges of the DM code.

[0147] Step S804: The search for both clock edges is successful; if yes, execute step S812; if not, execute step S805.

[0148] Step S805: Is it the first secondary line search operation? If yes, execute step S806; if no, execute step S807.

[0149] Step S806: Morphological operation (black code: corrosion processing, white code: dilation processing).

[0150] Specifically, the image after resolution reduction is subjected to dilation and corrosion processing. White codes are subjected to dilation processing, and black codes are subjected to corrosion processing. When the resolution is reduced to 1 / 16 of the original resolution of the original image, a size of 5*5 is used. Or when the resolution is other than 1 / 8 of the original resolution of the original image or 1 / 4 of the original resolution of the original image, a size of 3*3 is used for morphological processing. The image after morphological processing is subjected to line finding operation.

[0151] Step S807: Check whether the clock edge 1 is successfully searched by borrowing; if yes, execute step S810; if no, execute step S809.

[0152] Step S808: Execute a secondary line search operation.

[0153] Then the L-edge combination is used to find the effective clock edge.

[0154] Step S809: Search for clock edge 1 from the first line search result.

[0155] Step S810: Check whether the clock edge 2 is successfully searched by borrowing; if yes, execute step S812; if no, execute step S811;

[0156] Step S811: Search for clock edge 2 from the line segments obtained by the secondary line search.

[0157] Step S812: The clock edge and the L edge are combined into a two-dimensional code area.

[0158] Specifically, in the method for locating a two-dimensional code provided in this embodiment, in the line finding method, after finding the L edge combination, it is further determined whether clock edge 1 and clock edge 2 are found. Step S808 is the process of finding the line again, wherein the valid clock edges include clock edge 1 and clock edge 2.

[0159] Different from the above-mentioned embodiment, in this embodiment, morphological processing is first performed on the image before performing secondary line finding, and white code and black code are processed separately, so as to facilitate the subsequent line finding operation. Meanwhile, in this embodiment, steps S807 and S810 are the verification process of clock edge 1 and clock edge 2. If the verification is successful, it indicates a valid clock edge, and then the valid clock edge is combined with the L edge to realize the positioning process of the distorted two-dimensional code.

[0160] It can be understood that the search for the clock edge of the two-dimensional code is performed by searching the line twice, as shown in steps S808 to S807 and S809. If the valid clock edge 1 is not found in the second line search, then the valid clock edge 1 is found in the result of the first line search. As shown in steps S808 to S807 and S810, if the valid clock edge 1 is found in the second line search, then it is further determined whether the valid clock edge 2 has been found. Thus, the two-dimensional code graphic is located when both the valid clock edge 1 and the valid clock edge 2 have been found.

[0161] In a feasible embodiment, after finding the QR code pattern, the QR code pattern can also be verified to determine whether the QR code pattern after the secondary line search meets the DM code pattern characteristics. If there are no two adjacent edges that meet the clock edge characteristics (the reason may be that the judgment conditions are relatively wide, and blob analysis is performed at the center of the line segment, with at least two results, and the ratio of the largest area to the second largest area is not greater than 2, and the height in the main axis direction is less than 0.7 of the image height), then the result is deleted.

[0162] Fig.11 A schematic diagram of the structure of a positioning device for a distorted two-dimensional code provided in an embodiment of the present application.

[0163] like Fig.11 As shown, the embodiment of the present application also provides a positioning device for a distorted two-dimensional code, including a scanning module, an identification module, a determination module, a search module and a positioning module. Among them, the scanning module is configured to obtain a scanned image in a scanning area, the scanned image includes a two-dimensional code graphic, and the two-dimensional code graphic includes an L edge and a clock edge; the identification module is configured to identify a line segment in the scanned image; the determination module is configured to determine the L edge combination of the two-dimensional code graphic in the line segment; the determination module is also configured to determine the clock edge line segment to be selected according to the L edge combination; the search module is configured to find a line to search for a valid clock edge in the clock edge line segment to be selected; the positioning module is configured to locate the position of the two-dimensional code graphic according to the combination of the valid clock edge and the L edge.

[0164] Specifically, in the process of identifying the distorted two-dimensional code, the scanning module is first used to scan the graphics to be scanned in the scanning area. The scanning module is mainly used to scan the two-dimensional code graphics so that the recognition module can identify the line segments in the scanned image, and then the L side and the clock side of the two-dimensional code are determined according to the identified line segments. First, the L side combination in the two-dimensional code graphics is determined by the determination module, and the clock side line segment is determined again on the premise that the L side combination is determined. The judgment module is used to determine the number of searches for the clock side, so as to realize the secondary line search operation for the clock side. The search module searches for the valid clock side according to the clock side line segment line search. Finally, the positioning module combines the L side combination and the found clock side to obtain the position of the two-dimensional code graphics, so as to realize the positioning process of the two-dimensional code image. That is to say, on the premise of determining the L side combination, the clock side is determined by the secondary line search method, and the valid clock side is searched in multiple clock side line segments to be selected to verify the validity of the clock side, and the positioning accuracy of the two-dimensional code is improved when the two-dimensional code is distorted.

[0165] It is understandable that the above-mentioned L-edge combination includes the first L-edge combination and the second L-edge combination, and may also include other L-edge combinations, that is, taking the determination module in the present application as an example, the determination module is used to determine the L-edge combination, and the L-edge combination here does not limit the number of times the L-edge combination is determined. The same is true for the search module and the positioning module.

[0166] Similar parts between the embodiments provided in this application can be referenced to each other. The specific implementation methods provided above are only a few examples under the general concept of this application and do not constitute a limitation on the protection scope of this application. For those skilled in the art, any other implementation methods expanded based on the scheme of this application without creative work belong to the protection scope of this application.

Claims

1. A method for locating a distorted two-dimensional code, characterized in that: include: Acquire a scanned image in the scanned area, wherein the scanned image includes a two-dimensional code graphic, and the two-dimensional code graphic includes an L edge and a clock edge; the clock edge is the right edge and the upper edge of the DM code; Identify a line segment in the scanned image to determine a first L-edge combination of the two-dimensional code pattern in the line segment; Determine a first clock edge segment to be selected according to the first L edge combination; Searching for a first valid clock edge in the first candidate clock edge line segment; Locate the position of the two-dimensional code graphic according to the combination of the first effective clock edge and the first L edge; Determining a first candidate clock edge segment according to the first L edge combination includes: Two first clock edge search areas are constructed according to the first L edge combination; wherein the two first clock edge search areas have the same extension direction as the two L edges in the first L edge combination, and the endpoints of the first L edge combination are located in the first clock edge search area; Acquire a first target line segment in the first clock edge search area, where the first target line segment is: a line segment that forms an L-shaped line segment combination with any line segment in the first L-edge combination; Determine a first candidate clock edge line segment according to the first target line segment; the first candidate clock edge line segment is: a line segment of which at least one endpoint among the plurality of first target line segments is within the first clock edge search area, the line segment length is greater than a length threshold, and the direction deviation from the ideal clock edge is less than a deviation threshold; The searching for the first valid clock edge in the first candidate clock edge line segment comprises: Obtain the longest line segment among the first clock edge line segments to be selected; Calculate the minimum distance between the endpoint of the longest first candidate clock edge segment and the endpoint of the first L edge combination; If the minimum distance is less than a first threshold, the longest line segment of the first candidate clock edge is determined as the first valid clock edge.

2. The method for locating a distorted two-dimensional code according to claim 1, characterized in that: If the first valid clock edge is not found in the first candidate clock edges, the method for locating the distorted two-dimensional code further includes: Performing dilation and corrosion processing on the scanned image; Identifying a line segment in the scanned image after the dilation and corrosion processing to determine a second L-edge combination of the two-dimensional code graphic in the line segment; Determine a second clock edge segment to be selected according to the second L edge combination; Searching for a second valid clock edge in the second candidate clock edge line segment; The position of the two-dimensional code graphic is located according to the combination of the second effective clock edge and the second L edge.

3. The method for locating a distorted two-dimensional code according to claim 2, characterized in that: Determining the second candidate clock edge segment according to the second L edge combination includes: Constructing two second clock edge search areas according to the second L edge combination; wherein the two second clock edge search areas have the same extension direction as the two L edges in the second L edge combination, and the endpoints of the second L edge combination are located within the second clock edge search area; Acquire a second target line segment in the second clock edge search area, where the second target line segment is: a line segment that forms an L-shaped line segment combination with a line segment in the second L-edge combination; A second candidate clock edge line segment is determined according to the second target line segment, where the second candidate clock edge line segment is: a line segment in which at least one endpoint of the second target line segment is within the second clock edge search area and an angle with the ideal clock edge is less than a first preset angle.

4. The method for locating a distorted two-dimensional code according to claim 3, characterized in that: In the step of determining the second candidate clock edge segment based on the second target segment: if an endpoint of the second target segment is outside the second clock edge search area, retain the second target segment in the second clock edge area as the second candidate clock edge segment.

5. The method for locating a distorted two-dimensional code according to claim 2, characterized in that: The searching for a second valid clock edge in the second candidate clock edge line segment comprises: Acquire a third target line segment, where the third target line segment is the longest line segment among the second clock edge line segments to be selected; If there is only one line segment in the third target line segment, determining the third target line segment as the second valid clock edge; If the length of the third target line segment is greater than a first preset multiple of the ideal clock edge, the third target line segment is determined to be the second valid clock edge.

6. The method for locating a distorted two-dimensional code according to claim 5, characterized in that: If there are multiple third target line segments and the length of the third target line segment is less than or equal to a first preset multiple of the length of the ideal clock edge, searching for a second valid clock edge in the second candidate clock edge line segment further includes: Acquire a fourth target line segment, where the fourth target line segment is a line segment in the second candidate clock edge line, the angle between the fourth target line segment and the third target line segment being less than a second preset angle, or the length of the fourth target line segment being greater than or equal to a third preset multiple of the length of the ideal clock edge; Acquire a fifth target line segment, merge the colinear line segments in the fourth target line segment to obtain the fifth target line segment; merge the third target line segment and the fifth target line segment to serve as the second valid clock edge.

7. The method for locating a distorted two-dimensional code according to claim 6, characterized in that: In the step of searching for a second valid clock edge in the second candidate clock edge line segment: A distance between an intersection of the second valid clock edge and the second L edge combination and an endpoint of the second L edge combination is less than a second threshold.

8. A positioning device for a distorted two-dimensional code, characterized in that: include: Scanning module: configured to obtain a scanned image in a scanning area, wherein the scanned image includes a two-dimensional code graphic, and the two-dimensional code graphic includes an L edge and a clock edge; A recognition module: configured to recognize line segments in the scanned image; A determination module: configured to determine an L-edge combination of the two-dimensional code graphic in the line segment; the determination module is further configured to determine a clock edge line segment to be selected according to the L-edge combination; Search module: configured to search for a valid clock edge in the clock edge line segment to be selected; Positioning module: configured to locate the position of the two-dimensional code graphic according to the combination of the effective clock edge and the L edge; The determination module is further configured to: Two clock edge search areas are constructed according to the L edge combination; wherein the two clock edge search areas are respectively in the same extension direction as the two L edges in the L edge combination, and the endpoints of the L edge combination are located in the clock edge search area; Acquire a target line segment in the clock edge search area, wherein the target line segment is: a line segment that forms an L-shaped line segment combination with any line segment in the L edge combination; Determine a candidate clock edge line segment according to the target line segment; the candidate clock edge line segment is: a line segment of which at least one endpoint among the plurality of target line segments is within the clock edge search area, the line segment length is greater than a length threshold, and the direction deviation from the ideal clock edge is less than a deviation threshold; The search module is further configured to: Obtain the longest line segment among the clock edge line segments to be selected; Calculate the minimum distance between the endpoint of the longest clock edge segment to be selected and the endpoint of the L edge combination; If the minimum distance is less than a threshold, the longest line segment of the candidate clock edge is determined as the valid clock edge.

Citation Information

Patent Citations

  • Random anti-counterfeit mark sampling method and device and server

    CN109034327A

  • DM code positioning method and device, terminal and storage medium

    CN110414649A