A method for locating low-quality QR codes

By morphological processing and line segment merging of low-quality QR codes and combined with L-side completion, the problem of failed positioning of low-quality QR codes in the existing technology is solved, and the reading rate of QR codes is improved.

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

Patent Information

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

AI Technical Summary

Technical Problem

The existing QR code positioning methods cannot adapt to low-quality QR codes, resulting in failed or incomplete positioning, affecting information reading.

Method used

By morphological processing and LSD linear segment detection on the QR code image, segments in different directions are obtained, segment merging and L-edge completion are performed to obtain the bit code area.

Benefits of technology

The reading rate of low-quality QR codes is improved, ensuring accurate positioning of QR codes, and can work effectively even in poor quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115965038B_ABST
    Figure CN115965038B_ABST
Patent Text Reader

Abstract

The present application provides a method and device for locating low-quality two-dimensional codes, including the following steps: performing morphological operations on images in different directions to obtain multiple preprocessed images; performing straight line detection on multiple preprocessed images, and obtaining line segments in different directions from different preprocessed images; merging the obtained line segments; performing L-edge search and completion based on the merged line segments, so as to accurately locate the L-edge position of the low-quality code. The method for locating low-quality two-dimensional codes of the present application obtains the bit code area by performing line segment merging and fitting, L-edge grouping and line segment screening, and L-edge completion on the poor-quality two-dimensional code, thereby improving the recognition rate of the two-dimensional code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of two-dimensional code positioning, and in particular to a positioning method for low-quality two-dimensional codes. Background Art

[0002] In the process of QR code reading, before extracting and decoding its binary information, it is necessary to first determine the bit code area, that is, the QR code positioning. Therefore, in the process of code reading, if the QR code cannot be positioned, it will directly cause the QR code reading to fail.

[0003] At present, the commonly used two-dimensional code positioning methods include: using Hough or LSD methods to obtain straight line segments in the two-dimensional code; then, selecting fixed pattern edges, namely L edges, from the obtained straight line segments; finally, taking the minimum circumscribed affine rectangle of the L edge as the bit code area of ​​the two-dimensional code to complete the positioning of the two-dimensional code. If the quality of the two-dimensional code is good and the L edge is complete, the above method can accurately locate the two-dimensional code.

[0004] However, in actual application, due to backward process technology, poor adhesion of the material in the printing area (such as metal) to the QR code, mechanical collision during transportation, etc., low-quality QR codes such as low clarity, uneven grayscale or damaged images are often produced. Figure 1 This is a common low-quality QR code image. As shown in the figure, low-quality QR codes have problems such as L-side disconnection, uneven arrangement of L-side modules, or incomplete positioning areas such as low contrast. If the above-mentioned existing positioning method is still used, positioning failure or incomplete positioning will occur, thereby affecting the reading of the QR code information and causing code reading failure. Summary of the invention

[0005] The present application provides a method for locating a low-quality two-dimensional code to solve the problem that the existing two-dimensional code positioning method cannot be adapted to low-quality two-dimensional codes, thereby causing the low-quality two-dimensional code to be unable to be positioned due to an incomplete positioning area.

[0006] The present application provides a method for locating a low-quality two-dimensional code, comprising:

[0007] According to a preset morphological operation direction, morphological processing is performed on the two-dimensional code image to obtain a preprocessed image corresponding to the operation direction, wherein the morphological operation direction includes a first morphological operation direction and a second morphological operation direction;

[0008] Using the LSD straight line segment detection algorithm, obtain line segments within a first angle range in the preprocessed image corresponding to the first morphological operation direction, and obtain line segments within a second angle range in the preprocessed image corresponding to the second morphological operation direction;

[0009] Performing line segment merging processing on the line segments within the first angle range and the line segments within the second angle range to obtain merged fitting line segments, wherein the fitting line segments include the first fitting line segments and the second fitting line segments;

[0010] If the first fitting line segment and the second fitting line segment are L-edge pair line segments, L-edge completion is performed on the L edge formed by the first fitting line segment and the second fitting line segment.

[0011] In some embodiments, the morphological processing of the two-dimensional code image to obtain a pre-processed image corresponding to the operation direction includes:

[0012] According to the background image of the two-dimensional code image, the polarity of the two-dimensional code is obtained, and the polarity of the two-dimensional code includes a black code and a white code;

[0013] If the polarity of the two-dimensional code is a black code, the two-dimensional code image is eroded in the first morphological operation direction and the second morphological operation direction respectively to obtain a preprocessed image corresponding to each morphological operation direction;

[0014] If the polarity of the two-dimensional code is a white code, the two-dimensional code graphic is expanded in the first morphological operation direction and the second morphological operation direction respectively to obtain a preprocessed image corresponding to each morphological operation direction.

[0015] In some embodiments, the morphological operation direction includes 0°, 45°, 90° or 135°.

[0016] In some embodiments, the LSD straight line segment detection algorithm is used to obtain line segments within the first angle range in the preprocessed image corresponding to the first morphological operation direction.

[0017] If the first morphological operation direction is 0°, the corresponding first angle range is 0-22.5° and 157.5-180°;

[0018] If the first morphological operation direction is 45°, the corresponding first angle range is 67.5-11.25°;

[0019] If the first morphological operation direction is 90°, the corresponding first angle range is 112.5-157.5°;

[0020] If the first morphological operation direction is 135°, the corresponding first angle range is 22.5-67.5°.

[0021] In some embodiments, the line segments within the first angle range and the line segments within the second angle range are merged to obtain merged fitting line segments, wherein the fitting line segments include the first fitting line segments and the second fitting line segments, including:

[0022] Divide the line segments within the first angle range and the line segments within the second angle range that meet the merging condition into a group, including a first merged line segment group and a second merged line segment group;

[0023] Sorting the line segments in the first merged line segment group according to a preset insertion order, and connecting the starting point of the first line segment in the group with the end point of the last line segment to obtain a first fitting line segment;

[0024] The line segments in the second merged line segment group are sorted according to a preset insertion order, and the starting point of the first line segment in the group is connected with the end point of the last line segment to obtain a second fitting line segment.

[0025] In some embodiments, the merging conditions include:

[0026] The outward expansion rectangle of the line segment within the first angle range intersects with the outward expansion rectangle of the line segment within the second angle range, wherein the outward expansion rectangle of the line segment within the first angle range is a line segment rectangle formed by expanding the circumscribed rectangle of the line segment by a preset pixel, and the outward expansion rectangle of the line segment within the second angle range is a line segment rectangle formed by expanding the circumscribed rectangle of the line segment by a preset pixel;

[0027] The included angle between the line segment within the first angle range and the line segment within the second angle range is smaller than a preset angle value;

[0028] The maximum distance between the line segment within the first angle range and the line segment within the second angle range is less than the preset line distance.

[0029] In some embodiments, the angle between a line segment within the first angle range and a line segment within the second angle range is calculated as follows:

[0030]

[0031] Among them, E2E1 is the length of the line segment within the first angle range, and E3E4 is the length of the line segment within the second angle range.

[0032] In some embodiments, the first fitting line segment and the second fitting line segment meet the condition that the L-edge pair line segment is:

[0033] The first fitting line segment is orthogonal to the second fitting line segment;

[0034] The length ratio of the first fitting line segment to the second fitting line segment is in a range of 0.5 to 4.5, wherein the first fitting line segment is a long side and the second fitting line segment is a short side.

[0035] In some embodiments, the first fitting line segment and the second fitting line segment meet the condition of L-edge pair line segment:

[0036] The first fitting line segment is orthogonal to the second fitting line segment;

[0037] The length ratio of the first fitting line segment to the second fitting line segment is in a range of 0.5 to 4.5, wherein the first fitting line segment is a long side and the second fitting line segment is a short side.

[0038] In some embodiments, the L-edge completion of the L-edge composed of the first fitting line segment and the second fitting line segment specifically includes: determining the directions of the two fitting line segments in the L-edge combination, judging whether it is a horizontal or vertical direction, and determining the direction of the intersection of the L-edge; calculating a reference value, that is, a grayscale contrast threshold for determining whether a certain point is on the L-edge; judging the completion direction of the L-edge; and completing the L-edge according to the reference value.

[0039] The present application provides a method and device for locating a low-quality two-dimensional code, comprising the following steps: performing morphological operations on images in different directions to obtain multiple preprocessed images; performing straight line detection on multiple preprocessed images, and obtaining line segments in different directions from different preprocessed images; merging the obtained line segments; performing L-edge search and completion based on the merged line segments, thereby accurately locating the L-edge position of the low-quality code. A method for locating a low-quality two-dimensional code provided in an embodiment of the present application obtains a bit code area by performing line segment merging and fitting, L-edge grouping and line segment screening, and L-edge completion on a two-dimensional code with poor quality, thereby improving the recognition rate of the two-dimensional code. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] 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.

[0041] Figure 1 It is a common low-quality QR code image;

[0042] Figure 2 A sorting diagram of the first line segment and the second line segment of the present application;

[0043] Figure 3 This is a schematic diagram of the L-side group pair line segment of this application;

[0044] Figure 4 This is a schematic diagram of finding the full L side for this application;

[0045] Figure 5 is the original image of the QR code image in this example;

[0046] Figure 6 The line segment graphs obtained from different morphological operation directions for this example;

[0047] Figure 7 A graph of all the line segments obtained for the morphological operation direction of this instance;

[0048] Figure 8 This is a schematic diagram of the line segment grouping in this example;

[0049] Fig. 9 This is a schematic diagram of merging grouped segments in this example;

[0050] Fig.10 is a schematic diagram of the L-edge combination graph of this example;

[0051] Fig.11 This is a comparison chart of the processing effects before and after L edge completion in this example. DETAILED DESCRIPTION

[0052] In order to solve the problem that the QR code positioning method cannot be adapted to low-quality QR codes, resulting in the low-quality QR codes being unable to be positioned due to incomplete positioning areas, the present application provides a low-quality QR code positioning method, which specifically includes the following steps.

[0053] Step S100, according to a preset morphological operation direction, morphologically process the two-dimensional code image to obtain a pre-processed image corresponding to the operation direction, wherein the morphological operation direction includes a first morphological operation direction and a second morphological operation direction.

[0054] It should be noted that the number of pre-selected morphological operation directions is not limited to two, and can be adjusted according to actual conditions, such as 3, 4 or 6, all of which belong to the scope of this application. In addition, the morphological operation direction can select a suitable angle according to actual needs, such as 0°, 45°, 60°, 90°, 120° or 135°, all of which belong to the protection scope of this application.

[0055] In some embodiments, the morphological processing of the two-dimensional code image to obtain the preprocessed image corresponding to the operation direction includes, according to the background image of the two-dimensional code, obtaining the polarity of the two-dimensional code, and the polarity of the two-dimensional code includes black code and white code; if the polarity of the two-dimensional code is black code, then the two-dimensional code graphic is corroded in the first morphological operation direction and the second morphological operation direction respectively, and the preprocessed image corresponding to each morphological operation direction is obtained, including the first preprocessed image and the second preprocessed image; if the polarity of the two-dimensional code is white code, then the two-dimensional code is expanded in the first morphological operation direction and the second morphological operation direction respectively, and the preprocessed image corresponding to each morphological operation direction is obtained, including the first preprocessed image and the second preprocessed image. It should be noted that the number of preprocessed images is not limited to 2, and the number of other morphological operation directions corresponds, for example, when 4 morphological operation directions are included, the number of preprocessed images corresponds to 4. It should be noted that obtaining the polarity of the two-dimensional code and the corrosion / expansion operation are both common technologies in the field, and the specific implementation process of the two-dimensional code polarity acquisition process and the corrosion / expansion operation is described in detail here.

[0056] In some examples, the expansion / erosion operation with the structural elements of 1*3 and 3*1 is performed on the QR code image, which can remove the influence of pattern edge pollution, thereby accurately locating the QR code with partially damaged pattern edges. It should be noted that in the actual expansion / erosion operation process, the appropriate structural element can be selected according to the actual situation, and it will be specifically limited here.

[0057] Step S200, using the LSD straight line segment detection algorithm, obtains line segments within a first angle range in the preprocessed image corresponding to the first morphological operation direction, and obtains line segments within a second angle range in the preprocessed image corresponding to the second morphological operation direction. This operation can improve the continuity of line segments in different directions, thereby improving the detection of line segments.

[0058] In some examples, the LSD straight line segment detection algorithm is used to obtain line segments within a first angle range in the preprocessed image corresponding to the first morphological operation direction, and to obtain line segments within a second angle range in the preprocessed image corresponding to the second morphological operation direction. The first morphological operation direction and the first angle range have an angle consistency relationship. To facilitate the description of the consistency relationship between the two, the following will be described through specific practice.

[0059] For example, when the first morphological operation direction is the horizontal direction, that is, the 0° direction, the corresponding first angle range is located near 0° or 180°. For example, the first angle range can be set to [0, 22.5] and [157.5, 180]. Of course, it can be adjusted according to actual needs.

[0060] For example, when the first morphological operation direction is 45°, the corresponding first angle range is located near 45°, such as the first angle is [112.5, 157.5]. Of course, it can be adjusted according to actual needs;

[0061] For example, the first morphological operation direction is the vertical direction, that is, the 90° direction, and the corresponding first angle range is located near 90°, such as the first angle range is [67.5, 11.25]. Of course, it can be adjusted according to actual needs;

[0062] For example, when the first morphological operation direction is 135°, the corresponding first angle range is located near 135°, such as the first angle range is [22.5, 67.5]. Of course, it can be adjusted according to actual needs.

[0063] Similarly, there is an angle-consistent relationship between the second morphological operation direction and the second angle, which is consistent with the corresponding relationship between the first morphological operation direction and the first angle, and will not be repeated here. In addition, the number of angle ranges is not limited to the first angle range and the second angle range, which corresponds to the number of morphological operation directions. For example, when 4 morphological operation directions are included, the number of pre-processed images corresponds to 4, and the corresponding angle range of the line segment is 4.

[0064] It should be noted that the LSD straight line segment detection algorithm is a commonly used technology in this field, and its specific implementation process will not be described in detail here.

[0065] Step S300: performing line segment merging processing on the line segments within the first angle range and the line segments within the second angle range to obtain merged fitting line segments, wherein the fitting line segments include a first fitting line segment and a second fitting line segment.

[0066] In some embodiments, the line segment merging process includes the following steps: the line segments within the first angle range and the line segments within the second angle range are grouped together, that is, the line segments within the two angle ranges are grouped together so that all the line segments can be processed in subsequent steps; the line segments within the first angle range and the line segments within the second angle range that meet the merging conditions are divided into a group, including a first merged line segment group and a second merged line segment group; the line segments within the first merged line segment group are sorted according to a preset order, and the starting point of the first line segment in the group and the end point of the last line segment are connected to obtain a first fitting line segment; the line segments within the second merged line segment group are sorted according to a preset order, and the starting point of the first line segment in the group and the end point of the last line segment are connected to obtain a second fitting line segment. It should be noted that the data of the fitting line segments are only taken as an example of 2, and the specific number shall be subject to the fitting line segments actually obtained.

[0067] The merger conditions include:

[0068] 1) The outward expansion rectangle of the line segment within the first angle range intersects with the outward expansion rectangle of the line segment within the second angle range, wherein the outward expansion rectangle of the line segment within the first angle range is a line segment rectangle formed by expanding the circumscribed rectangle of the line segment by preset pixels, and the outward expansion rectangle of the line segment within the second angle range is a line segment rectangle formed by expanding the circumscribed rectangle of the line segment by preset pixels. It should be noted that those skilled in the art can adjust the preset pixels according to actual needs, for example 10 pixels, which all fall within the scope of protection of the present application.

[0069] 2) The angle between the line segment within the first angle range and the line segment within the second angle range is less than the preset angle value. It should be noted that those skilled in the art can adjust the preset angle value according to actual needs, for example 5°, which all fall within the protection scope of this application.

[0070] In some instances, the angle between line segments is calculated as:

[0071]

[0072] Among them, E2E1 is the length of the line segment within the first angle range, and E3E4 is the length of the line segment within the second angle range.

[0073] 3) The maximum distance between the line segment within the first angle range and the line segment within the second angle range is less than the preset line distance. It should be noted that those skilled in the art can adjust the preset line distance according to actual needs, for example, 10 pixels, which all fall within the protection scope of this application.

[0074] It should be noted that the line segments in a merged line segment group are not limited to two line segments, and may include more than three line segments, and the specific number depends on the actual situation, and will not be specifically limited here. In addition, the merged line segment group is not limited to the first merged line segment group and the second merged line segment group, and may also include the third merged line segment group, the fourth merged line segment group, or the fifth merged line segment group. The specific number of the merged line segment group depends on the actual situation, and will not be specifically limited here.

[0075] In some examples, the line segments in the first merged line segment group are sorted according to a preset insertion order, and the start point of the first line segment in the group and the end point of the last line segment are connected to obtain the first fitting line segment, which specifically includes sorting the line segments in the first merged line segment group according to the line segment direction, wherein the process of determining the line segment direction is: comparing the distance D1 from the first segment of the first line segment to the end of the second line segment with the distance D2 from the first segment of the second line segment to the end of the first line segment, if D1≥D2, then the first line segment is inserted in front of the second line segment, and if D1 is less than D2, then the second line segment is inserted in front of the first line segment. It should be noted that the first line segment and the second line segment here are line segments in the first merged line segment group, which are only marks of different line segments in the first merged line segment group, and are not a limitation on the name and number of line segments in the first merged line segment group.

[0076] To facilitate those skilled in the art to better understand the process, the following will be described by way of example. Figure 2 As shown in a in , for the first line segment S1E1 and the second line segment S2E2, the distance from the first line segment S1 to the second line segment end E2 is greater than the distance from the first line segment S2 to the first line segment end E1, so the first line segment S1E1 is inserted in front of the second line segment S2E2. For another example, Figure 2 As shown in b, for the first line segment S1E1 and the second line segment S2E2, the distance from the first line segment S1 to the second line segment's tail end E2 is smaller than the distance from the second line segment S2 to the first line segment's tail end E1. Therefore, the second line segment S2E2 is inserted in front of the first line segment S1E1.

[0077] Afterwards, in order to improve the accuracy of the line segment, the edge points on the current group of line segments are taken to perform straight line fitting, and the fitted line segment is used as the final fitted line segment. It should be noted that the straight line fitting process of the line segment is a common technology in this field, so the process will not be repeated here.

[0078] The process of obtaining the second fitting line segment is the same as the process of obtaining the first fitting line segment, and the process will not be described in detail here. Please refer to the process of obtaining the first fitting line segment for details.

[0079] Step S400: If the first fitting line segment and the second fitting line segment are L-edge pair line segments, L-edge completion is performed on the L edge formed by the first fitting line segment and the second fitting line segment.

[0080] In some instances, the first fitting line segment and the second fitting line segment meet the conditions of the L-edge group pair segment: (1) the first fitting line segment is orthogonal to the second fitting line segment, (2) the length ratio of the first fitting line segment to the second fitting line segment is between 0.5 and 4.5, wherein the first fitting line segment is the long side and the second fitting line segment is the short side. It should be noted that the first fitting side and the second fitting side are only marks of different fitting sides within the fitting segment, and are not limitations on the names and numbers of the fitting sides. In addition, the lengths of any two fitting line segments are not fixed. Here, it is taken as an example that the length of the first fitting line segment is greater than that of the second fitting line segment. In order to facilitate those skilled in the art to better understand the process, an example is given below. Figure 3 As shown in the figure, the length of the first fitting edge P1P2 is L1, the length of the second fitting edge P3P4 is L2, the first fitting edge P1P2 is orthogonal to the second fitting edge P3P4, and L1 / L2=1∈(0.5~4.5), therefore, the first fitting edge P1P2 and the second fitting edge P3P4 are L-edge group line segments.

[0081] Two fitted line segments that meet the L-edge group can form an L-edge. However, the L-edge searched in the above steps may be an incomplete L-edge, and the length of the L-edge needs to be re-determined based on the grayscale information near the L-edge. In some embodiments, the L-edge composed of the first fitted line segment and the second fitted line segment is completed, specifically including: determining the direction of the two fitted line segments in the L-edge combination, judging whether it is approximately horizontal or vertical, and determining the direction of the intersection of the L-edge; calculating the reference value, that is, the grayscale contrast threshold to determine whether a certain point is on the L-edge; judging the completion direction of the L-edge; completing the L-edge according to the reference value. The above four steps will be described in detail below.

[0082] In some embodiments, determining the directions of two fitted line segments in the L-edge combination, judging whether they are approximately horizontal or vertical, and determining the direction of the L-edge intersection specifically include, for example: Figure 4As shown, obtain the intersection point O of the two L edges and the other two vertices P1 and P2 of the two L edge fitting segments L1 and L2 except the intersection point, and determine the positional relationship between P1 and O. If the horizontal distance between P1 and O is greater than the vertical distance, L1 is the horizontal L edge and L2 is the vertical L edge. Otherwise, the arrangement order is reversed.

[0083] In some embodiments, the reference value G is calculated th , that is, the grayscale contrast threshold for determining whether a point is on the L edge, specifically including: reference value G th To determine whether a point is on the L edge, the grayscale contrast threshold is calculated by comparing the grayscale contrast ΔG of a point p. p With G th The size relationship determines whether the current point is a point on the L edge, ΔG p >Th, the point is on the L edge, otherwise it is not on the L edge.

[0084] In some embodiments, the completion direction of the L side is determined, specifically including: calculating the grayscale contrast of the end point of the L side to be completed, and comparing it with a reference value; if it is greater than the reference value, it means that the current point has not reached the actual end point of the L side, and the completion direction is to complete along the direction of the L side; if it is less than the reference value, it means that the current end point is outside the actual L side, the original L side is longer than it actually is, and it is necessary to complete it in the opposite direction of the original L side.

[0085] In some embodiments, the L edge is completed according to the reference value, specifically including: along the search direction obtained in the previous step, the grayscale contrast of each point is calculated, if along the positive direction, two consecutive points are less than the reference value, which means that the L edge has been completed, and the first point less than the reference value is the new end point of the L edge; if along the reverse direction, two consecutive points are greater than the reference value, which means that the current point has reached the actual L edge, and the first point greater than the reference value is the new end point of the L edge. According to the horizontal and vertical L edge arrangement order in the L edge combination obtained in the above steps, the two completed L edges are reorganized and output to complete the completion of the L edge combination.

[0086] In order to facilitate those skilled in the art to better understand the technical solution of the present application, the specific use process of the present application is explained below through an example.

[0087] Step S100: According to a preset morphological operation direction, a two-dimensional code image (such as Figure 5 The morphological processing is performed on the image (as shown) to obtain the preprocessed image corresponding to the operation direction.

[0088] In this example, the preselected morphological operation directions include a first morphological operation direction, a second morphological operation direction, a third morphological operation direction and a fourth morphological operation direction, wherein the first morphological operation direction is a horizontal direction, i.e., a 0° direction, the second morphological operation direction is a 45° direction, the third morphological operation direction is a vertical direction, i.e., a 90° direction, and the fourth morphological operation direction is a 135° direction.

[0089] According to the background image of the two-dimensional code image, the polarity of the two-dimensional code is obtained. In this example, the polarity of the two-dimensional code is a black code. The two-dimensional code image is corroded in the first, second, third and fourth morphological operation directions to obtain a preprocessed image corresponding to each morphological operation direction. The process specifically includes: corroding the two-dimensional code image in the first morphological operation direction (horizontal direction, i.e., 0° direction) to obtain a preprocessed image corresponding to the first morphological operation direction, i.e., a first preprocessed image; corroding the two-dimensional code image in the second morphological operation direction (45° direction) to obtain a preprocessed image corresponding to the second morphological operation direction, i.e., a second preprocessed image; corroding the two-dimensional code image in the third morphological operation direction (vertical direction, i.e., 90° direction) to obtain a preprocessed image corresponding to the third morphological operation direction, i.e., a third preprocessed image; corroding the two-dimensional code image in the fourth morphological operation direction (135° direction) to obtain a preprocessed image corresponding to the fourth morphological operation direction, i.e., a fourth preprocessed image.

[0090] Step S200, using the LSD straight line segment detection algorithm, obtain line segments within a first angle range in the preprocessed image corresponding to the first morphological operation direction, obtain line segments within a second angle range in the preprocessed image corresponding to the second morphological operation direction; obtain line segments within a third angle range in the preprocessed image corresponding to the third morphological operation direction; obtain line segments within a fourth angle range in the preprocessed image corresponding to the fourth morphological operation direction.

[0091] In this example, when the first morphological operation direction is the horizontal direction, that is, the 0° direction, the corresponding first angle range is [0, 22.5] and [157.5, 180]. The line segments within the corresponding angles are obtained as follows: Figure 6 As shown in a in the figure; when the second morphological operation direction is 45°, the corresponding second angle range is [112.5, 157.5], and the line segments within the corresponding angles are obtained as follows Figure 6 As shown in b in the figure; the third morphological operation direction is the vertical direction, that is, the 90° direction, and the corresponding third angle range is [67.5, 11.25]. The line segments within the corresponding angles are as follows Figure 6 As shown in c in the figure; when the fourth morphological operation direction is 135°, the corresponding fourth angle range is [22.5, 67.5], and the line segments within the corresponding angles are obtained as follows Figure 6 As shown in d. Figure 7 It is a collection graph of all line segments within the first, second, third and fourth angle ranges.

[0092] Step S300, dividing the line segments within the first angle range, the line segments within the second angle range, the line segments within the third angle range, and the line segments within the fourth angle range that meet the merging condition into a merged line segment group, Figure 8 This is a schematic diagram of the line segment grouping of this example. This example includes the first merged line segment group, the second merged line segment group and the nth merged line segment group. According to the preset insertion order, the line segments in the first merged line segment group are sorted, and the starting point of the first line segment in the group and the end point of the last line segment are connected to obtain the first fitting line segment; according to the preset insertion order, the line segments in the second merged line segment group are sorted, and the starting point of the first line segment in the group and the end point of the last line segment are connected to obtain the second fitting line segment; according to the preset insertion order, the line segments in the nth merged line segment group are sorted, and the starting point of the first line segment in the group and the end point of the last line segment are connected to obtain the nth fitting line segment. Fig. 9 This is a schematic diagram of the merging of grouped line segments in this example.

[0093] Step S400: if the first fitting line segment and the second fitting line segment are L-edge pair line segments, L-edge completion is performed on the L-edge formed by the first fitting line segment and the second fitting line segment. The specific implementation process includes the following steps.

[0094] First, the n fitting line segments obtained in the previous step are determined to have L edge pairs, and the resulting graph that meets the L edge pairs is obtained, as shown in Fig.10 As shown. The conditions for meeting the L-edge group pair line segment are: (1) the first fitting line segment is orthogonal to the second fitting line segment, (2) the length ratio of the first fitting line segment to the second fitting line segment is between 0.5 and 4.5, wherein the first fitting line segment is the long side and the second fitting line segment is the short side.

[0095] Then, the L edge composed of the first fitting line segment and the second fitting line segment is completed, specifically including: determining the directions of the two fitting line segments in the L edge combination, judging whether they are approximately horizontal or vertical directions, and determining the direction of the intersection of the L edges; calculating a reference value, that is, a grayscale contrast threshold for determining whether a certain point is on the L edge; judging the completion direction of the L edge; and completing the L edge according to the reference value. The above four steps will be described in detail below.

[0096] Among them, the directions of the two fitted line segments in the L-edge combination are determined, and it is judged whether it is approximately horizontal or vertical, and the direction of the L-edge intersection is determined, specifically including obtaining the intersection point O of the two L-edges and the other two vertices P1 and P2 of the two L-edge fitted line segments L1 and L2 except the intersection point, and judging the positional relationship between P1 and O. If the horizontal distance between P1 and O is greater than the vertical distance, L1 is the horizontal L-edge and L2 is the vertical L-edge, otherwise the arrangement order is reversed.

[0097] Calculate the reference value G th , that is, the grayscale contrast threshold for determining whether a point is on the L edge, specifically including: reference value G th To determine whether a point is on the L edge, the grayscale contrast threshold is calculated by comparing the grayscale contrast ΔG of a point p. p With G th The size relationship determines whether the current point is a point on the L edge, ΔG p >Th, the point is on the L edge, otherwise it is not on the L edge.

[0098] Determine the completion direction of the L side, specifically including: calculating the grayscale contrast of the end point of the L side to be completed, and comparing it with the reference value. If it is greater than the reference value, it means that the current point has not reached the actual end point of the L side, and the completion direction is to complete along the direction of the L side. If it is less than the reference value, it means that the current end point is outside the actual L side, the original L side is longer than the actual one, and it is necessary to complete it in the opposite direction of the original L side.

[0099] Completing the L edge according to the reference value specifically includes: calculating the grayscale contrast of each point along the search direction obtained in the previous step. If two consecutive points are smaller than the reference value along the positive direction, it means that the L edge has been completed, and the first point smaller than the reference value is the new end point of the L edge; if two consecutive points are larger than the reference value along the reverse direction, it means that the current point has reached the actual L edge, and the first point larger than the reference value is the new end point of the L edge. According to the horizontal and vertical L edge arrangement order in the L edge combination obtained in the above steps, the two completed L edges are reorganized and output to complete the completion of the L edge combination. Fig.11 The following is a comparison chart of the processing effects before and after L edge completion.

[0100] In summary, the present application provides a method and device for locating low-quality two-dimensional codes, including the following steps: performing morphological operations on images in different directions to obtain multiple preprocessed images; performing straight line detection on multiple preprocessed images, and obtaining line segments in different directions from different preprocessed images; merging the obtained line segments; performing L-edge search and completion based on the merged line segments, so as to accurately locate the L-edge position of the low-quality code. A method for locating low-quality two-dimensional codes provided in an embodiment of the present application obtains the bit code area by merging and fitting the line segments in the two-dimensional code with poor quality, screening the L-edge group of line segments, and completing the L-edge, thereby improving the recognition rate of the two-dimensional code.

[0101] The above is an example of the best implementation method of this application, and the parts not described in detail are common knowledge of ordinary technicians in this field. The protection scope of this application shall be based on the content of the claims, and any equivalent transformation based on the technical enlightenment of this application is also within the protection scope of this application.

Claims

1. A method for locating a low-quality two-dimensional code, characterized in that: include: According to a preset morphological operation direction, morphological processing is performed on the two-dimensional code image to obtain a preprocessed image corresponding to the operation direction, wherein the morphological operation direction includes a first morphological operation direction and a second morphological operation direction, and the morphological operation direction includes 0°, 45°, 90° or 135°; Using the LSD straight line segment detection algorithm, obtain line segments within a first angle range in the preprocessed image corresponding to the first morphological operation direction, and obtain line segments within a second angle range in the preprocessed image corresponding to the second morphological operation direction; Among them, if the first morphological operation direction is 0°, the corresponding first angle range is 0-22.5° and 157.5-180°; if the first morphological operation direction is 45°, the corresponding first angle range is 67.5-11.25°; if the first morphological operation direction is 90°, the corresponding first angle range is 112.5-157.5°; if the first morphological operation direction is 135°, the corresponding first angle range is 22.5-67.5°; Performing line segment merging processing on the line segments within the first angle range and the line segments within the second angle range to obtain merged fitting line segments, wherein the fitting line segments include the first fitting line segments and the second fitting line segments; The line segment merging process is performed on the line segment within the first angle range and the line segment within the second angle range to obtain a merged fitting line segment, wherein the fitting line segment includes the first fitting line segment and the second fitting line segment, including: The line segments within the first angle range and the line segments within the second angle range that meet the merging condition are divided into a group, including a first merged line segment group and a second merged line segment group, wherein the merging condition includes: the outer expansion rectangle of the line segment within the first angle range intersects with the outer expansion rectangle of the line segment within the second angle range, wherein the outer expansion rectangle of the line segment within the first angle range is a line segment rectangle formed by expanding the circumscribed rectangle of the line segment by preset pixels, and the outer expansion rectangle of the line segment within the second angle range is a line segment rectangle formed by expanding the circumscribed rectangle of the line segment by preset pixels; the angle between the line segment within the first angle range and the line segment within the second angle range is less than a preset angle value; and the maximum distance between the line segment within the first angle range and the line segment within the second angle range is less than a preset line distance; Sorting the line segments in the first merged line segment group according to a preset insertion order, and connecting the starting point of the first line segment in the group with the end point of the last line segment to obtain a first fitting line segment; Sorting the line segments in the second merged line segment group according to a preset insertion order, and connecting the starting point of the first line segment in the group with the end point of the last line segment to obtain a second fitting line segment; If the first fitting line segment and the second fitting line segment are L-edge pair line segments, L-edge completion is performed on the L edge formed by the first fitting line segment and the second fitting line segment.

2. The method for locating a low-quality two-dimensional code according to claim 1, characterized in that: The morphological processing of the two-dimensional code image to obtain a pre-processed image corresponding to the operation direction includes: According to the background image of the two-dimensional code image, the polarity of the two-dimensional code is obtained, and the polarity of the two-dimensional code includes a black code and a white code; If the polarity of the two-dimensional code is a black code, the two-dimensional code image is eroded in the first morphological operation direction and the second morphological operation direction respectively to obtain a preprocessed image corresponding to each morphological operation direction; If the polarity of the two-dimensional code is a white code, the two-dimensional code graphic is expanded in the first morphological operation direction and the second morphological operation direction respectively to obtain a preprocessed image corresponding to each morphological operation direction.

3. The method for locating a low-quality two-dimensional code according to claim 1, characterized in that: The angle calculation formula between the line segment within the first angle range and the line segment within the second angle range is: , in, E 2 E 1 is the length of the line segment within the first angle range, E 3 E 4 is the length of the line segment within the second angle range.

4. The method for locating a low-quality two-dimensional code according to claim 1, characterized in that: The condition that the first fitting line segment and the second fitting line segment meet the L-edge pair line segment is: The first fitting line segment is orthogonal to the second fitting line segment; The length ratio of the first fitting line segment to the second fitting line segment is in a range of 0.5 to 4.5, wherein the first fitting line segment is a long side and the second fitting line segment is a short side.

5. The method for locating a low-quality two-dimensional code according to claim 1, characterized in that: The condition that the first fitting line segment and the second fitting line segment meet the L-edge pair line segment is: The first fitting line segment is orthogonal to the second fitting line segment; The length ratio of the first fitting line segment to the second fitting line segment is in a range of 0.5 to 4.5, wherein the first fitting line segment is a long side and the second fitting line segment is a short side.

6. The method for locating a low-quality two-dimensional code according to claim 1, characterized in that: The L-side completion of the L-side composed of the first fitting line segment and the second fitting line segment specifically includes: determining the directions of two fitting line segments in the L-side combination, judging whether they are horizontal or vertical directions, and determining the direction of the intersection of the L-sides; calculating a reference value, that is, a grayscale contrast threshold for determining whether a certain point is on the L-side; judging the completion direction of the L-side; and completing the L-side according to the reference value.

Citation Information

Patent Citations

  • 2D code positioning method and system

    CN106485183A

  • 2D code positioning algorithm based on combination of texture rough positioning and shape fine positioning

    CN113836962A