A method and device for positioning a two-dimensional code
By acquiring and updating QR code line segments at different resolutions, and combining overlay and fitting methods, the problem of QR code recognition instability in complex backgrounds was solved, achieving higher recognition accuracy and robustness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING LUSTER LIGHTTECH
- Filing Date
- 2022-12-29
- Publication Date
- 2026-04-21
AI Technical Summary
Existing technologies perform poorly in QR code recognition under complex background interference, and it is difficult to effectively locate features at different resolutions, resulting in unstable recognition and low accuracy.
By acquiring and traversing line segments at different resolutions, the update conditions are selected using the superposition results of the line segments, and the line segments are updated and combined using a straight line fitting method to determine the QR code position.
It improves the recognition accuracy and robustness of QR codes in complex backgrounds, ensuring accurate positioning and recognition in scenarios such as blurriness, high noise, small code area, and background interference.
Smart Images

Figure CN116029317B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a method and apparatus for locating QR codes. Background Technology
[0002] QR code applications are complex and diverse, and background interference can lead to unstable feature extraction or significant deviations from reality. Figure 1 Taking the DM (Data Matrix) code shown as an example, in actual industrial scenarios, QR code images are often accompanied by noise and background interference, making it very difficult to directly extract accurate line segments. Figure 1 The image shown has issues with pixel blurring and unclear boundaries. Therefore, sampling is necessary. At lower resolutions, the continuity of localization features is better, and extraction is more stable. However, at this point, the recognition process is uncertain because the size of the code region is unknown; that is, it's unclear at which resolution the image should be downsampled for extraction. For example, some images have larger modules that require localization at a lower resolution, while others are small and features are almost impossible to extract at lower resolutions, requiring higher resolutions. Therefore, it's difficult to be compatible with all scenarios using a single resolution for localization, resulting in poor QR code recognition performance. Summary of the Invention
[0003] This application provides a method and apparatus for locating QR codes to solve the problem of QR codes not being effectively recognized.
[0004] This application provides a method for locating a QR code, comprising: acquiring a first image to be scanned at a first resolution; traversing line segments in the first image to be scanned at the first resolution; acquiring a second image to be scanned at a second resolution, wherein the second resolution is greater than the first resolution; traversing line segments in the second image to be scanned at the second resolution; mapping the coordinates of the line segments at the first resolution to the coordinate system of the second resolution; selecting an update condition for the line segments based on the superposition result of the line segments at the first resolution and the line segments at the second resolution; updating the line segments in the second image to be scanned according to the selected update condition; and determining the position of the QR code based on the multiple updated line segments.
[0005] Optionally, based on the superposition result of line segments at the first resolution and line segments at the second resolution, the update condition for the line segments is selected, including: obtaining the overlap quantity of line segments at the first resolution and line segments at the second resolution; if the overlap quantity is 0, then the line segments at the first resolution are retained. If the overlap quantity is not 0, then the line segments in the second image to be scanned are updated according to the overlap quantity of line segments at the first resolution and line segments at the second resolution.
[0006] Optionally, updating the line segments in the second image to be scanned based on the number of overlaps between the line segments at the first resolution and the line segments at the second resolution includes: if the number of overlaps is 1, then retaining the overlapping portion of the line segments at the first resolution and the line segments at the second resolution as the line segments in the updated second image to be scanned; if the number of overlaps is not 1, then determining the straight line direction of multiple line segments among the line segments at the first resolution and the line segments at the second resolution by a straight line fitting method, mapping the endpoints of the multiple line segments to the straight line direction, and taking the longest line segment in the straight line direction as the line segment in the updated second image to be scanned.
[0007] Optionally, obtaining the number of overlaps between line segments at the first resolution and line segments at the second resolution includes: obtaining the endpoint projection coordinates of the line segments at the first resolution; calculating the distance from the projection coordinates to the line segments in the second resolution coordinates; if the distance is less than a first preset distance, determining that the line segments at the first resolution and line segments at the second resolution overlap, and counting the number of overlaps determined to be the line segments at the first resolution and line segments at the second resolution.
[0008] Optionally, obtaining the number of overlaps between line segments at the first resolution and line segments at the second resolution further includes: obtaining the angle between line segments at the first resolution and line segments at the second resolution; if the angle is less than a first preset angle, then determining that line segments at the first resolution and line segments at the second resolution overlap, and counting the number of overlaps determined to be between line segments at the first resolution and line segments at the second resolution.
[0009] Optionally, obtaining the number of overlaps between line segments at the first resolution and line segments at the second resolution further includes: obtaining the overlap length between line segments at the first resolution and line segments at the second resolution; calculating the ratio of the overlap length to the length of the line segments at the first resolution; if the ratio is within a first preset range, then determining that the line segments at the first resolution and line segments at the second resolution overlap, and statistically analyzing the number of overlaps determined to be between line segments at the first resolution and line segments at the second resolution.
[0010] Optionally, the first preset distance is in the range of 1-3 pixels; the first preset angle is in the range of 1.5°-2.5°; and the first preset range is 0.5-1.
[0011] A second aspect of this application provides a QR code positioning device, including an acquisition module, a traversal module, a selection module, a mapping module, and a positioning module. The acquisition module is configured to acquire a first image to be scanned at a first resolution and a second image to be scanned at a second resolution, respectively. The traversal module is configured to traverse line segments in the first image to be scanned at the first resolution and line segments in the second image to be scanned at the second resolution, respectively. The mapping module is configured to map the line segments at the first resolution to the coordinate system of the second resolution. The selection module is configured to determine the update conditions of the line segments based on the superposition result of the line segments at the first resolution and the line segments at the second resolution. The positioning module is configured to update the line segments in the second image to be scanned according to the selected update conditions, and determine the position of the QR code based on the multiple updated line segments.
[0012] Optionally, the selection module is configured to: obtain the overlap number between line segments at the first resolution and line segments at the second resolution; if the overlap number is 0, then retain the line segments at the first resolution. If the overlap number is not 0, then update the line segments in the second image to be scanned according to the overlap number between the line segments at the first resolution and line segments at the second resolution.
[0013] Optionally, the selection module is further configured to: if the overlap number is 1, retain the overlapping portion of the line segments at the first resolution and the line segments at the second resolution as the line segments in the updated second image to be scanned; if the overlap number is not 1, determine the straight line direction of multiple line segments in the line segments at the first resolution and the line segments at the second resolution by a straight line fitting method, map the endpoints of the multiple line segments onto the straight line, and take the longest line segment in the straight line direction as the line segment in the updated second image to be scanned.
[0014] The QR code positioning method and apparatus provided in this application, when updating line segments using the method in this embodiment, involves three scenarios: retaining the line segments at the first resolution, retaining the overlapping portion of the line segments at the first and second resolutions, and retaining the longest line segment among multiple line segments in the straight line direction at both the first and second resolutions. After obtaining multiple updated line segments, these segments are combined to form the border structure of the QR code, thereby achieving QR code positioning. Through the line segment recognition and updating method at different resolutions in this application, the detection capability for QR code side length is stronger, the region positioning is more robust, and a more complete set of line segments is retained. This ensures accurate positioning of the code area even in scenarios with blurriness, high noise, small code area, and background interference, thus guaranteeing recognition rate and improving recognition accuracy. Attached Figure Description
[0015] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 DM code images in complex scenes;
[0017] Figure 2 This is a schematic diagram of the QR code positioning method in an embodiment of this application;
[0018] Figure 3 This is a flowchart illustrating the process of selecting line segment update conditions in an embodiment of this application;
[0019] Figure 4 This is a flowchart illustrating the process of selecting line segment update conditions when line segments overlap, as described in an embodiment of this application.
[0020] Figure 5 This is a schematic flowchart of the method for determining the number of overlaps based on the projection distance in an embodiment of this application;
[0021] Figure 6 This is a flowchart illustrating the method for determining the number of overlaps based on the included angle of line segments in an embodiment of this application.
[0022] Figure 7 This is a flowchart illustrating the method for determining the number of overlaps based on the overlap ratio of line segments in the implementation of this application;
[0023] Figure 8 This is a schematic diagram of the QR code positioning device in the embodiments of this application. Detailed Implementation
[0024] The embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described below do not represent all embodiments consistent with this application. They are merely examples of systems and methods consistent with some aspects of this application as detailed in the claims.
[0025] In the process of identifying a two-dimensional code, whether the two-dimensional code can be successfully identified depends severely on the accuracy of the positioning of the code area. If the positioning deviation is large, no matter how robust the subsequent processing algorithm is, since the processing area is incorrect, the encoded information of the two-dimensional code still cannot be extracted. Most two-dimensional code positioning methods involve extracting the features of the two-dimensional code from the entire image and combining the features. For example, for a DM (Data Matrix) code, its features are four pattern edges, and for a QR (Quick Response) code, they are three square-shaped positioning patterns. The general idea is to first extract line segments or areas conforming to the square feature from the entire image and then determine whether there is a feature combination that can form the code area among all the extracted features.
[0026] Taking the DM code as an example, the positioning features of the DM code are the four edges of the DM code. The two edges on the left side in an L shape are called L edges, and the two edges on the right side and the upper side are called clock edges. The positioning process is to first extract all the line segments in the image, combine them after extraction to form a rectangular area, and then perform subsequent judgments. However, for a DM code with degraded quality, the above recognition method will not be able to accurately identify the content of the two-dimensional code. For example Figure 1 the DM code in the complex scenario shown.
[0027] To identify a DM code with degraded quality, in some embodiments, repeated scanning can be performed at different resolutions. Since the detection effects of a DM code with degraded quality are different at different resolutions, for example, at a low resolution, the L-edge line segments found are long but the directions are inaccurate, and at a high resolution, the line segment directions are accurate but the line segments are severely disconnected. Merging the line segments at different resolutions can improve the positioning accuracy. Therefore, for a scenario with degraded quality, the line segments detected at the current resolution are merged with the line segments detected at the previous level as the final line segments at the current resolution.
[0028] Figure 2 This is a schematic flowchart of a method for positioning a two-dimensional code in an embodiment of the present application.
[0029] See Figure 2 The present application provides a method for positioning a two-dimensional code, including:
[0030] Step S11: Obtain a first to-be-scanned image at a first resolution.
[0031] Step S12: Traverse the line segments in the first to-be-scanned image at the first resolution.
[0032] Step S13: Obtain a second to-be-scanned image at a second resolution.
[0033] Step S14: Traverse the line segments in the second to-be-scanned image at the second resolution.
[0034] Specifically, the second resolution is greater than the first resolution. This means the first resolution is low-resolution, and the second resolution is high-resolution. In other words, the location of a QR code is achieved by upscaling its resolution. The first image to be scanned is the QR code image at the first resolution (low resolution), and the second image to be scanned is the QR code image at the second resolution. The QR code recognition and location process is achieved through these different resolutions.
[0035] Step S15: Map the line segment coordinates under the first resolution to the second resolution coordinate system.
[0036] It is understandable that a QR code is a frame structure composed of line segments, and the process of identifying and locating a QR code is essentially the process of identifying this frame structure. By traversing the line segments in the first and second images to be scanned, and mapping the obtained line segments at the first resolution to the second resolution coordinate system, the border position of the QR code can be easily determined by comparing the line segments, thus achieving the process of identifying and locating the QR code.
[0037] Step S16: Select the update conditions for the line segments based on the superposition results of the line segments at the first resolution and the line segments at the second resolution.
[0038] At this point, in the second resolution coordinate system, there exist line segments under the first resolution and line segments under the second resolution. It can be understood that, taking the same side of a QR code as an example, if the height of one side of the QR code under the first resolution matches that of a line segment under the second resolution, then these two line segments can be determined to be the same side of the QR code. Therefore, this embodiment of the application also uses this superposition of line segments to determine the side length of the QR code. Specifically, in this embodiment, in the second resolution coordinate system, the update condition for the line segments is selected based on the superposition result of the line segments under the first resolution and the line segments under the second resolution. The update condition refers to updating the second image to be scanned under the second resolution after determining that a certain line segment is a valid line segment of the QR code border structure. That is, if the line segment is determined to be the side length of the QR code, then the line segment is retained; for line segments that do not meet the update condition, no retention is performed.
[0039] Step S17: Update the line segments in the second image to be scanned according to the selected update conditions, and determine the position of the QR code based on the multiple updated line segments.
[0040] The second image to be scanned is updated, and after multiple line segments have been updated, the border of the QR code can be obtained, thereby determining the position of the QR code and realizing the positioning operation of the QR code. Through the line segment recognition and updating method at different resolutions in this application, the detection capability of QR code side length is stronger, the region positioning is more robust, and a more complete set of line segments is retained. It ensures the positioning of the code area in scenarios such as blurriness, high noise, small code area, and background interference, thereby ensuring the recognition rate and improving the recognition accuracy.
[0041] For example, we'll illustrate this using different resolutions of the original image. Specifically, we'll use 1 / 16 and 1 / 32 of the original image's resolution as examples. 1 / 32 of the original image's resolution is considered low resolution compared to 1 / 16, while 1 / 16 is considered high resolution compared to 1 / 32. We set 1 / 32 of the original image's resolution as the initial resolution. At this initial resolution, line segments are detected and combined once to search for rectangular regions at the initial resolution. Then, we increase the resolution and search again at 1 / 16 of the original image's resolution, combining line segments in the same way as at the initial resolution. At this point, the searched line segments at 1 / 16 of the original image's resolution include the mapped line segments from the initial resolution. We then search for line segments that satisfy the criteria for a QR code region. This method effectively improves the robustness of QR code region extraction.
[0042] Figure 3 This is a schematic diagram illustrating the selection of line segment update conditions in an embodiment of this application.
[0043] like Figure 3 As shown, in some embodiments, step S16, which involves selecting the update condition for the line segment based on the superposition result of the line segment at the first resolution and the line segment at the second resolution, can be specifically implemented through the following steps S21-S23:
[0044] Step S21: Obtain the number of overlaps between line segments at the first resolution and line segments at the second resolution.
[0045] Specifically, after mapping line segments from the first resolution coordinate system to the second resolution coordinate system, there are two possible outcomes: either the two coordinate systems overlap, or they do not. By determining the update conditions based on the amount of overlap, different update conditions can be selected for different overlap amounts, thus enabling targeted line segment updates. This improves line segment recognition efficiency, thereby enhancing the positioning accuracy of QR codes and improving the robustness of QR code regions.
[0046] Step S22: If the overlap is 0, then retain the line segments at the first resolution.
[0047] It is understandable that after a line segment at the first resolution is mapped to the second resolution coordinate system, if a line segment does not overlap with a line segment at the second resolution, then that line segment may still be the side length of the QR code. To avoid accidentally deleting valid line segments, the line segment is retained when it does not overlap with a line segment in the second resolution coordinate system.
[0048] Step S23: If the overlap number is not 0, update the line segments in the second image to be scanned according to the overlap number between the line segments at the first resolution and the line segments at the second resolution.
[0049] Specifically, when line segments at the first resolution and line segments at the second resolution overlap, the line segments in the second image to be scanned are updated according to the amount of overlap. In other words, this embodiment does not perform a single update whenever overlap exists, but rather performs targeted update operations based on the specific amount of overlap, which can improve the efficiency of line segment recognition.
[0050] Figure 4 This is a schematic diagram of the process for selecting line segment update conditions when line segments overlap in an embodiment of this application.
[0051] like Figure 4 As shown, in some embodiments, step S23, which updates the line segments in the second image to be scanned based on the overlap between the line segments at the first resolution and the line segments at the second resolution, can be specifically implemented through the following steps S31-S32:
[0052] Step S31: If the overlap is 1, then retain the overlapping part of the line segments at the first resolution and the line segments at the second resolution as the line segments in the updated second image to be scanned.
[0053] It is understandable that if the line segments at the first resolution coincide with the line segments at the second resolution, then the line segment is more likely to be the side length of the QR code. Therefore, the line segment is retained, which makes it easier to form the border of the QR code by integrating the line segments later.
[0054] Step S32: If the number of overlaps is not 1, the straight line direction of multiple line segments in the first resolution and the second resolution is determined by the straight line fitting method, and the endpoints of the multiple line segments are mapped to the straight line. The longest line segment in the straight line direction is taken as the line segment in the updated second image to be scanned.
[0055] Specifically, if the overlap number is not 1, it indicates that there are multiple overlaps. That is, there are multiple similar line segments. The direction of these lines is determined by line fitting, and the endpoints of the multiple line segments are mapped onto this line. The longest line segment on this line is then selected as the updated line segment and saved. This can be understood as fitting multiple line segments together to determine one valid line segment.
[0056] During the line segment update process using the method in this embodiment, three scenarios exist when determining the line segment update: retaining the line segment at the first resolution, retaining the overlapping portion of the line segment at the first resolution and the line segment at the second resolution, and retaining the longest line segment among multiple line segments in the straight line direction from the line segments at the first resolution and the line segment at the second resolution. After obtaining multiple updated line segments, these updated line segments are combined to form the border structure of the QR code, thereby achieving the positioning of the QR code.
[0057] Figure 5 This is a schematic diagram of the method for determining the amount of overlap based on the projection distance in an embodiment of this application.
[0058] like Figure 5 As shown, in some embodiments, the number of overlapping line segments can be determined by the projection distance, specifically including:
[0059] Step S41: Obtain the endpoint projection coordinates of the line segment at the first resolution.
[0060] Step S42: Calculate the distance from the projected coordinates to the line segment in the second resolution coordinates.
[0061] Step S43: If the distance is less than the first preset distance, then determine that the line segment under the first resolution overlaps with the line segment under the second resolution, and count the number of overlaps between the line segment under the first resolution and the line segment under the second resolution.
[0062] Specifically, whether two line segments overlap can be determined based on the distance between a line segment at a first resolution and a line segment at a second resolution. The coordinates of the endpoint of the line segment at the first resolution are obtained, and the distance from those coordinates to the line segment at the second resolution is calculated. It can be understood that if the distance between two line segments is very small, they can be considered to overlap; if the distance between two line segments is large, they are not similar and are two independent line segments. The distance between the endpoint of the line segment at the first resolution and the line segment at the second resolution is compared with a first preset distance to determine whether they overlap. If the distance between them is less than the first preset distance, they are determined to overlap, and the number of overlaps is counted.
[0063] In one feasible embodiment, the first preset distance ranges from 1 pixel to 3 pixels. For example, the first preset distance can be 1 pixel, 2 pixels, or 3 pixels. When the preset distance is 2 pixels, if the distance from the projected coordinates of the endpoint of the line segment at the first resolution to the line segment at the second resolution coordinates is less than 2 pixels, then the line segments are determined to be in an overlapping state.
[0064] Figure 6 This is a schematic diagram of the method for determining the number of overlaps based on the included angle of line segments in an embodiment of this application.
[0065] like Figure 6 As shown, in some embodiments, the number of overlapping line segments can be determined by the included angle of the line segments, specifically including:
[0066] Step S51: Obtain the angle between the line segment at the first resolution and the line segment at the second resolution.
[0067] Step S52: If the included angle is less than the first preset angle, then determine that the line segment under the first resolution overlaps with the line segment under the second resolution, and count the number of overlaps between the line segment under the first resolution and the line segment under the second resolution.
[0068] Specifically, whether a line segment at the first resolution coincides with a line segment at the second resolution can be determined by the angle between the line segments. The angle between the line segments at the first resolution and the line segment at the second resolution is obtained. If this angle is less than a first preset angle, it indicates that the angle is small, and the line segments at the first resolution and the second resolution tend to coincide. Therefore, it is determined that the line segments overlap, and the number of overlaps is counted.
[0069] In a feasible embodiment, the value range of the first preset angle is 1.5°-2.5°; for example, the first preset angle can be 1.5°, 2°, or 2.5°. When the first preset angle is 2°, if the angle between the line segment at the first resolution and the line segment at the second resolution is less than 2°, it is determined that the line segments are in an overlapping state.
[0070] Figure 7 This is a flowchart illustrating the method for determining the number of overlaps based on the overlap ratio of line segments in the implementation of this application.
[0071] like Figure 7 As shown, in some embodiments, the amount of overlap can be determined by using the overlap ratio of line segments, specifically including:
[0072] Step S61: Obtain the overlap length between the line segment at the first resolution and the line segment at the second resolution.
[0073] Step S62: Calculate the ratio of the overlap length to the line segment length at the first resolution.
[0074] Step S63: If the ratio is within the first preset range, then determine that the line segments at the first resolution overlap with the line segments at the second resolution, and count the number of overlaps between the line segments at the first resolution and the line segments at the second resolution.
[0075] Specifically, the overlap length of a line segment at the first resolution and the line segment at the second resolution is obtained. It can be understood that if the overlap length between two line segments is relatively long, then they can be determined to be overlapping. After calculating the overlap length, the ratio of the overlap length to the line segment length at the first resolution is calculated. If this ratio is within a first preset range, it indicates that the ratio is large, and the overlap length is long, thus the line segment can be identified as overlapping. When determining if a line segment is overlapping, the number of overlaps is counted.
[0076] In one feasible embodiment, the first preset range is 0.5-1, that is, if the ratio of the overlap length to the first resolution is in the range of 0.5-1, it indicates that the line segments are in an overlapping state.
[0077] Figure 8 This is a schematic diagram of the QR code positioning device in the embodiments of this application.
[0078] like Figure 8 As shown, a second aspect of this application provides a QR code positioning device, including an acquisition module, a traversal module, a selection module, a mapping module, and a positioning module. The acquisition module is configured to acquire a first image to be scanned at a first resolution and a second image to be scanned at a second resolution, respectively. The traversal module is configured to traverse line segments in the first image to be scanned at the first resolution and line segments in the second image to be scanned at the second resolution, respectively. The mapping module is configured to map line segments at the first resolution to a coordinate system at the second resolution. The selection module is configured to determine update conditions for line segments based on the superposition result of line segments at the first resolution and line segments at the second resolution. The positioning module is configured to update line segments in the second image to be scanned according to the selected update conditions, and determine the position of the QR code based on multiple updated line segments.
[0079] Specifically, the acquisition module obtains a first image to be scanned at a first resolution and a second image to be scanned at a second resolution. Then, the traversal module iterates through the line segments in both images. The second resolution is greater than the first resolution. In other words, the first resolution is low-resolution, and the second resolution is high-resolution. That is, the QR code positioning process is achieved by upscaling the resolution. The first image to be scanned is the QR code image at the first resolution (low resolution), and the second image to be scanned is the QR code image at the second resolution (high resolution). The QR code recognition and positioning process is achieved through these different resolutions.
[0080] The mapping module maps line segments at the first resolution to a second resolution coordinate system. This can be understood as follows: a QR code is a frame structure composed of line segments, and the process of recognizing and locating a QR code is essentially the process of recognizing this frame structure. By mapping line segments in the first and second images to the second resolution coordinate system, the line segments at the first resolution are mapped to the second resolution coordinate system. This facilitates the determination of the QR code's border position through line segment comparison, thereby achieving the QR code recognition and location process.
[0081] The selection module is configured to select the update conditions for line segments based on the superposition result of the line segments. Line segments at the first resolution are mapped to the second coordinate system, and the selection module selects the update conditions for the line segments based on the superposition result. In the second resolution coordinate system, there are line segments at the first resolution and line segments at the second resolution. It can be understood that, taking the same side of a QR code as an example, if the height of one side of the QR code at the first resolution matches that of a line segment at the second resolution, it can be determined that these two line segments are likely the same side of the QR code. Therefore, this embodiment of the application also uses this superposition of line segments to determine the side length of the QR code. Specifically, in this embodiment, in the second resolution coordinate system, the update conditions for the line segments are selected based on the superposition result of the line segments at the first resolution and the line segments at the second resolution. The update condition refers to updating the second image to be scanned at the second resolution after determining that a certain line segment is the side length of the QR code. That is, if the line segment is determined to be the side length of the QR code, then the line segment is retained; for line segments that do not meet the update conditions, no retention is performed.
[0082] The determination module is used to determine the location of the QR code. The second image to be scanned is updated, and after multiple line segments have been updated, the border of the QR code can be obtained, thus determining its location and enabling QR code positioning. Through the line segment recognition and updating method at different resolutions in this application, the detection capability for QR code side length is stronger, the region positioning is more robust, and a more complete set of line segments is retained. This ensures accurate positioning of the QR code area even in scenarios with blurriness, high noise, small code area, and background interference, thereby guaranteeing the recognition rate and improving recognition accuracy.
[0083] In some embodiments, the selection module is used to select the update conditions for line segments. Specifically, after mapping line segments at the first resolution to the second resolution coordinate system, there are two possible outcomes: either they overlap or they do not. By determining the update conditions based on the amount of overlap, different update conditions can be selected for different overlap amounts, thereby enabling targeted line segment updates to improve line segment recognition efficiency, enhance QR code positioning accuracy, and improve QR code region robustness. After mapping line segments at the first resolution to the second resolution coordinate system, if a line segment does not overlap with a line segment at the second resolution, that line segment may still be a possible QR code side length. To avoid erroneously deleting valid line segments, line segments at the first resolution are retained when they do not coincide with line segments in the second resolution coordinate system. When line segments at the first and second resolutions overlap, the line segments in the second image to be scanned are updated specifically based on the amount of overlap. In other words, this embodiment does not perform a single update simply because overlap exists, but rather performs targeted update operations based on the specific amount of overlap, which improves line segment recognition efficiency.
[0084] In some embodiments, the selection module is used to select the update conditions for line segments. It can be understood that if a line segment at the first resolution overlaps with a line segment at the second resolution, then that line segment is likely the side length of the QR code, and thus the line segment is retained, facilitating the subsequent integration of line segments to form the border of the QR code. Specifically, when the overlap number is not 1, it indicates that there are multiple overlaps. That is, there are multiple similar line segments, and the direction of these line segments is determined by straight line fitting. The endpoints of the multiple line segments are mapped onto this straight line, and the longest line segment on this straight line is selected as the updated line segment and saved. This can be understood as determining a valid line segment after fitting multiple line segments together.
[0085] In the process of updating line segments using the method in this embodiment, there are three scenarios when determining the line segment update: retaining the line segment at the first resolution, retaining the overlapping portion of the line segment at the first resolution and the line segment at the second resolution, and retaining the longest line segment among multiple line segments in the straight line direction from the line segments at the first resolution and the line segments at the second resolution. After obtaining multiple updated line segments, the multiple updated line segments are combined to form the border structure of the QR code, thereby achieving the positioning of the QR code.
[0086] Similar parts between the embodiments provided in this application can be referred to mutually. The specific implementation methods provided above are only a few examples under the overall concept of this application and do not constitute a limitation on the scope of protection of this application. For those skilled in the art, any other implementation methods extended from the solution of this application without creative effort shall fall within the scope of protection of this application.
Claims
1. A method for locating a QR code, characterized in that, include: Acquire the first image to be scanned at the first resolution; Traverse the line segments in the first image to be scanned at the first resolution; Acquire a second image to be scanned at a second resolution, where the second resolution is greater than the first resolution; Traverse the line segments in the second image to be scanned at the second resolution; Map the line segment coordinates at the first resolution to the second resolution coordinate system; Based on the superposition result of the line segments at the first resolution and the line segments at the second resolution, the update conditions for the line segments in the second image to be scanned are selected. The line segments in the second image to be scanned are updated according to the update conditions of the selected line segments in the second image to be scanned, and the position of the QR code is determined based on the multiple updated line segments in the second image to be scanned.
2. The QR code positioning method according to claim 1, characterized in that, Based on the superposition result of line segments at the first resolution and line segments at the second resolution, update conditions for line segments in the second image to be scanned are selected, including: Obtain the number of overlaps between line segments at the first resolution and line segments at the second resolution; If the number of overlaps is 0, then the line segments at the first resolution are retained; If the number of overlaps is not 0, the line segments in the second image to be scanned are updated according to the number of overlaps between the line segments at the first resolution and the line segments at the second resolution.
3. The QR code positioning method according to claim 2, characterized in that, Updating the line segments in the second image to be scanned based on the overlap between line segments at the first resolution and line segments at the second resolution includes: If the number of overlaps is 1, then the overlapping portion of the line segments at the first resolution and the line segments at the second resolution is retained as the line segments in the updated second image to be scanned; If the number of overlaps is not 1, the straight line direction of multiple line segments in the first resolution and the second resolution is determined by straight line fitting, and the endpoints of the multiple line segments are mapped to the straight line corresponding to the straight line direction to obtain the longest line segment in the straight line direction. The longest line segment in the straight line direction is used as the line segment in the updated second image to be scanned.
4. The QR code positioning method according to claim 3, characterized in that, Obtaining the overlap between line segments at the first resolution and line segments at the second resolution includes: Obtain the endpoint projection coordinates of the line segment at the first resolution; Calculate the distance from the projected coordinates to the line segment in the second resolution coordinates; If the distance is less than the first preset distance, then it is determined that the line segment at the first resolution overlaps with the line segment at the second resolution, and the number of overlaps determined to be the line segment at the first resolution overlaps with the line segment at the second resolution is counted.
5. The QR code positioning method according to claim 4, characterized in that, Obtaining the overlap between line segments at the first resolution and line segments at the second resolution further includes: Obtain the angle between the line segment at the first resolution and the line segment at the second resolution; If the included angle is less than the first preset angle, then it is determined that the line segment at the first resolution overlaps with the line segment at the second resolution, and the number of overlaps determined to be the line segment at the first resolution overlaps with the line segment at the second resolution is counted.
6. The QR code positioning method according to claim 5, characterized in that, Obtaining the overlap between line segments at the first resolution and line segments at the second resolution further includes: Obtain the overlap length between the line segment at the first resolution and the line segment at the second resolution; Calculate the ratio of the overlap length to the line segment length at the first resolution; If the ratio is within a first preset range, then it is determined that the line segment at the first resolution overlaps with the line segment at the second resolution, and the number of overlaps determined to be the line segment at the first resolution overlaps with the line segment at the second resolution is counted.
7. The QR code positioning method according to claim 6, characterized in that, The first preset distance ranges from 1 to 3 pixels; The value range of the first preset angle is 1.5°-2.5°; The first preset range is 0.5-1.
8. A positioning device for a QR code, characterized in that, It includes modules for obtaining, traversing, selecting, mapping, and locating. The acquisition module is configured to acquire a first image to be scanned at a first resolution and a second image to be scanned at a second resolution, respectively. The traversal module is configured to traverse the line segments in the first image to be scanned at the first resolution and the line segments in the second image to be scanned at the second resolution, respectively. The mapping module is configured to map line segments at the first resolution to the second resolution coordinate system; The selection module is configured to: determine the update conditions for line segments in the second image to be scanned based on the superposition result of line segments at the first resolution and line segments at the second resolution; The positioning module is configured to: update the line segments in the second image to be scanned according to the update conditions of the selected line segments in the second image to be scanned, and determine the position of the QR code based on the multiple updated line segments in the second image to be scanned.
9. The positioning device for a QR code according to claim 8, characterized in that, The selection module is configured as follows: Obtain the number of overlaps between line segments at the first resolution and line segments at the second resolution; If the number of overlaps is 0, then the line segments at the first resolution are retained; If the number of overlaps is not 0, the line segments in the second image to be scanned are updated according to the number of overlaps between the line segments at the first resolution and the line segments at the second resolution.
10. The positioning device for a QR code according to claim 9, characterized in that, The selection module is also configured to: If the number of overlaps is 1, then the overlapping portion of the line segments at the first resolution and the line segments at the second resolution is retained as the line segments in the updated second image to be scanned; If the number of overlaps is not 1, the straight line direction of multiple line segments in the first resolution and the second resolution is determined by straight line fitting, and the endpoints of the multiple line segments are mapped to the straight line corresponding to the straight line direction to obtain the longest line segment in the straight line direction. The longest line segment in the straight line direction is used as the line segment in the updated second image to be scanned.
Citation Information
Patent Citations
Image recognition method and device and computer readable storage medium
CN114693918A
Method and apparatus for producing overlapping image area
US5513300A