A robust two-dimensional code DataMatrix decoding method and system

Through the QR code DataMatrix decoding method of steps such as image preprocessing, denoising, precise positioning and perspective transformation, the problem of insufficient robustness in the existing technology is solved, efficient decoding under harsh conditions is achieved, and the two are significantly improved. The robustness and speed stability of R code decoding.

CN113591506BActive Publication Date: 2024-11-26SHENZHEN JIEENSHI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110887858.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-03
Publication Date
2024-11-26
Estimated Expiration
2041-08-03

AI Technical Summary

Technical Problem

The existing QR code decoding algorithms are not robust when facing uneven lighting, noise interference, blur and complex situations, resulting in too long decoding or undecoding, which cannot meet the fast, time-consuming and stable industrial fields. Requirements for robustness.

Method used

Using a robust QR code DataMatrix decoding method, including image preprocessing, denoising, QR code precision positioning, perspective or affine transformation and scanning steps, it is transformed into a grayscale map, remove noise, and locate four vertices. , correct and divide grid scanning codes to ensure efficient decoding under harsh conditions.

Benefits of technology

It has achieved efficient solutions to problems such as code element loss, uneven light distribution, scratches, super-large noise and metal dot matrix codes, and has significantly improved the competitiveness in the field of QR code decoding.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113591506B_ABST
    Figure CN113591506B_ABST
Patent Text Reader

Abstract

The present invention relates to a robust two-dimensional code DataMatrix decoding method, comprising the following steps: image preprocessing, noise removal, two-dimensional code precise positioning, perspective or affine transformation, scanning, and obtaining a decoded character string; by applying the method of the present application, common decoding problems such as missing code elements, severely uneven illumination distribution, scratches, excessive noise, noise similar to code elements, and metal dot matrix codes can be efficiently solved, thereby greatly improving the competitiveness in the field of two-dimensional code decoding.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine vision and image recognition, and more specifically, to a robust two-dimensional code DataMatrix decoding method and system. Background Art

[0002] Although there are many methods for decoding two-dimensional codes at home and abroad, almost all algorithms face the problem of insufficient robustness. For example, when faced with serious uneven lighting, overexposed or dark images, severe noise interference, blurred images, and when the two-dimensional code is a dot matrix code, most algorithms either take too long to decode, or the decoding time fluctuates greatly, or cannot decode at all. In order to meet the requirements of the industry for algorithms: extremely robust, fast, and stable time consumption, a robust two-dimensional code DataMatrix decoding method is needed. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a robust two-dimensional code DataMatrix decoding method and a robust two-dimensional code DataMatrix decoding system in view of the above-mentioned defects of the prior art.

[0004] The technical solution adopted by the present invention to solve its technical problem is:

[0005] A robust two-dimensional code DataMatrix decoding method is constructed, which includes the following steps:

[0006] S1: Image preprocessing:

[0007] Acquire an image, and convert the acquired image into a binary image;

[0008] S2: Noise Removal:

[0009] De-noising the obtained binary image;

[0010] S3: QR code precise positioning:

[0011] Locate the precise positions of the four vertices of the QR code;

[0012] S4: Perspective or affine transformation:

[0013] Correct the four vertices obtained by positioning;

[0014] S5: Scan:

[0015] Divide the grid and scan the QR code;

[0016] S6: Get the decoded string.

[0017] The robust two-dimensional code DataMatrix decoding method of the present invention, wherein the S1: image preprocessing comprises the following specific steps:

[0018] Convert the three-channel color image into a grayscale image using the set ratio;

[0019] Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG;

[0020] Count the white pixels on the edge of the binary image W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color.

[0021] Then the binary image W_IMG is globally scanned to connect the white pixels or remove the white pixels;

[0022] Output the preprocessed image.

[0023] The robust two-dimensional code DataMatrix decoding method of the present invention, wherein the S3: two-dimensional code precise positioning comprises the following specific steps:

[0024] Starting from the four corners of the QR code image, adjacent pairs are combined in 8 directions, and 8 points that meet the set requirements are found in the set area. The 8 points have a total of four line segments, and the 4 intersection points P4 are determined. P4 determines the four line segments L4.

[0025] The robust two-dimensional code DataMatrix decoding method of the present invention, wherein the setting requirements include:

[0026] The minimum value of the distance between the point and the four corner vertices of the set area is less than a set value;

[0027] The minimum distance between a point and the edge of the image is less than a set value;

[0028] The density of white pixels near the point is higher than a set value.

[0029] The robust two-dimensional code DataMatrix decoding method of the present invention, wherein the S4: perspective or affine transformation comprises the following specific steps:

[0030] From the four line segments L4, calculate the angle theta between the opposite line segments;

[0031] Calculate the average length M_L of each of the four line segments L4;

[0032] If there is an angle theta of the opposite side segments that is greater than the set value, the worst point is removed from P4, and the fourth point that satisfies the parallelogram is generated from the positional relationship of the remaining three points to obtain G4;

[0033] Generate new four points N_P4 based on the average length M_L;

[0034] Transform W_IMG using perspective transformation from G4 to N_P4.

[0035] The robust two-dimensional code DataMatrix decoding method of the present invention, wherein the S5: scanning comprises the following specific steps:

[0036] The conventional grid division method is used to perform the scanning cycle operation. If successful, the string is output. If it fails, the position of the virtual edge code element of the QR code is located, and a new scanning grid is generated using the position so that the centers of these grids are exactly the centers of the virtual edge code elements. The scanning cycle operation is then performed again. If successful, the string is output.

[0037] The robust two-dimensional code DataMatrix decoding method of the present invention, wherein the scanning cycle operation includes the following method:

[0038] Given multiple groups: Parameter 1: the ratio of the white area in a single grid to the area of ​​the grid area_thres, Parameter 2: the size of a single grid relative to W_IMG size_thres;

[0039] As the two parameters are different, different grid images D_IMG are scanned and decoded.

[0040] A robust two-dimensional code DataMatrix decoding system, used to implement the above-mentioned robust two-dimensional code DataMatrix decoding method, wherein the system comprises an image preprocessing unit, an image denoising unit, a two-dimensional code precise positioning unit, a perspective or affine transformation unit, a scanning unit and a decoded string output unit;

[0041] The image preprocessing unit is used to acquire an image and convert the acquired image into a binary image;

[0042] The image denoising unit is used to perform denoising processing on the obtained binary image;

[0043] The two-dimensional code precise positioning unit is used to locate the precise positions of the four vertices of the two-dimensional code;

[0044] The perspective or affine transformation unit is used to correct the four vertices obtained by positioning;

[0045] The scanning unit is used to divide the grid into two-dimensional codes;

[0046] The decoded string output unit is used to output the decoded string obtained by scanning the code.

[0047] The robust two-dimensional code DataMatrix decoding system of the present invention, wherein the image preprocessing unit performs image preprocessing:

[0048] Convert the three-channel color image into a grayscale image using the set ratio;

[0049] Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG;

[0050] Count the white pixels on the edge of the binary image W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color.

[0051] Then the binary image W_IMG is globally scanned to connect the white pixels or remove the white pixels;

[0052] Output the preprocessed image.

[0053] The robust two-dimensional code DataMatrix decoding system of the present invention, wherein the two-dimensional code precise positioning unit starts from the four corners of the two-dimensional code image, combines two adjacent ones in eight directions, and searches for eight points that meet the set requirements in a set area, and determines four intersection points P4 from four line segments of the eight points, and P4 determines four line segments L4;

[0054] The perspective or affine transformation unit counts the angles theta of the opposite side segments from the four line segments L4, calculates the average length M_L of each line segment of the four line segments L4, and if there is an opposite side segment angle theta greater than a set value, removes the worst point in P4, generates a fourth point G4 that satisfies the parallelogram based on the positional relationship of the remaining three points, generates new four points N_P4 based on the average length M_L, and performs image transformation on W_IMG using the perspective transformation from G4 to N_P4;

[0055] The scanning unit uses a conventional grid division method to perform a scanning cycle operation. If successful, a character string is output. If failed, the position of the virtual edge code element of the two-dimensional code is located, and a new scanning grid is generated using the position so that the centers of these grids are exactly the centers of the virtual edge code elements. The scanning cycle operation is then performed again. If successful, a character string is output.

[0056] The beneficial effect of the present invention is that by applying the method of the present application, common decoding problems such as missing code elements, severely uneven light distribution, scratches, excessive noise, noise similar to code elements, metal dot codes, etc. can be efficiently solved, thereby greatly improving the competitiveness in the field of two-dimensional code decoding. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the present invention will be further described below in conjunction with the accompanying drawings and embodiments. The drawings described below are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work:

[0058] Figure 1 It is a flow chart of a robust two-dimensional code DataMatrix decoding method according to a preferred embodiment of the present invention;

[0059] Figure 2 It is a flow chart of a robust two-dimensional code DataMatrix decoding method S1 of a preferred embodiment of the present invention;

[0060] Figure 3 is a flow chart of a robust two-dimensional code DataMatrix decoding method S4 of a preferred embodiment of the present invention;

[0061] Figure 4 It is a principle block diagram of a robust two-dimensional code DataMatrix decoding system according to a preferred embodiment of the present invention. DETAILED DESCRIPTION

[0062] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the following will be described clearly and completely in combination with the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are partial embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work belong to the protection scope of the present invention.

[0063] The robust two-dimensional code DataMatrix decoding method of the preferred embodiment of the present invention is as follows Figure 1 See also Figure 2-Figure 3 , including the following steps:

[0064] S1: Image preprocessing:

[0065] Acquire an image, and convert the acquired image into a binary image;

[0066] S2: Noise Removal:

[0067] De-noising the obtained binary image;

[0068] S3: QR code precise positioning:

[0069] Locate the precise positions of the four vertices of the QR code;

[0070] S4: Perspective or affine transformation:

[0071] Correct the four vertices obtained by positioning;

[0072] S5: Scan:

[0073] Divide the grid and scan the QR code;

[0074] S6: Get the decoded string;

[0075] By applying the method of the present application, common decoding problems such as missing code elements, severely uneven light distribution, scratches, excessive noise, noise similar to code elements, and metal dot codes can be efficiently solved, thereby greatly improving the competitiveness in the field of two-dimensional code decoding;

[0076] Preferably, S1: image preprocessing comprises the following specific steps:

[0077] Convert the three-channel color image into a grayscale image using the set ratio;

[0078] Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG;

[0079] Count the white pixels on the edge of the binary image W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color.

[0080] Then the binary image W_IMG is globally scanned to connect the white pixels or remove the white pixels;

[0081] Output the preprocessed image;

[0082] Convert the three-channel color image into a grayscale image using an appropriate ratio. Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG, which can effectively reduce the impact of uneven illumination distribution. Count the white pixels on the edge of W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color. Scan the entire W_IMG image, connect the white pixels, or remove the white pixels. This can effectively approach the problem of hollow circles in the dot matrix code.

[0083] Preferably, S3: QR code precise positioning includes the following specific steps:

[0084] Starting from the four corners of the QR code image, adjacent pairs are combined in 8 directions, and 8 points that meet the set requirements are found in the set area. The 8 points have a total of four line segments, and the 4 intersection points P4 are determined. P4 determines the four line segments L4; the set requirements include:

[0085] The minimum distance between the point and the four corner vertices of the set area is less than a set value;

[0086] The minimum distance between a point and the edge of the image is less than a set value;

[0087] The density of white pixels near the point is higher than a set value.

[0088] From the four corners and eight directions, find the eight most suitable points that meet the following conditions: 1. The point is close enough to the four corner vertices of the area; 2. The point is close enough to the edge of the image; 3. The white pixels near the point are dense. For example, from the upper left vertex LU of W_IMG to the lower left vertex LD of W_IMG is a scanning direction ORIENT. The scanning range in the y direction can be half the height of W_IMG, and the scanning range in the x direction can be half the width of W_IMG. Starting from the upper left vertex LU, scan point by point in the scanning range. Find a white pixel point P that meets the prior conditions. Such P can be one of the eight points, and the same is true for the other seven directions. There are four line segments from the eight points, and the four intersection points P4 are determined. P4 determines the four line segments L4;

[0089] Preferably, S4: perspective or affine transformation comprises the following specific steps:

[0090] From the four line segments L4, calculate the angle theta between the opposite line segments;

[0091] Calculate the average length M_L of each of the four line segments L4;

[0092] If there is an angle theta of the opposite side segments that is greater than the set value, the worst point in P4 is removed, and the fourth point that satisfies the parallelogram is generated based on the positional relationship of the remaining three points to obtain a new P4;

[0093] Generate new four points N_P4 based on the average length M_L;

[0094] Transform W_IMG using perspective transformation from P4 to N_P4.

[0095] From the four line segments L4, determine the angle between two opposite line segments, with an average length of M_L. Select the two best points from L4, that is, determine the three best points of P4. Calculate the angle between opposite sides in L4. If there is an angle greater than a fixed value, remove the worst point in P4. From the positional relationship of the remaining three points, the fourth point that satisfies the parallelogram can be generated to obtain G4. Generate a new four-point N_P4 from M_L, and use the perspective transformation from G4 to N_P4 to transform W_IMG.

[0096] Preferably, S5: scanning comprises the following specific steps:

[0097] The conventional grid division method is used to perform the scanning cycle operation. If successful, the string is output. If it fails, the position of the virtual edge code element of the QR code is located, and a new scanning grid is generated using the position so that the centers of these grids are exactly the centers of the virtual edge code elements. The scanning cycle operation is then performed again. If successful, the string is output.

[0098] Preferably, the scanning cycle operation comprises the method of:

[0099] Given multiple groups: Parameter 1: the ratio of the white area in a single grid to the area of ​​the grid area_thres, Parameter 2: the size of a single grid relative to W_IMG size_thres;

[0100] As the two parameters are different, different grid images D_IMG are scanned and decoded.

[0101] Use the ordinary grid division to perform the scanning loop, and output the string if successful. In the scanning loop, given the parameters area_thres (the ratio of the white area in a single grid to the area of ​​the grid) and size_thres (the size of a single grid relative to W_IMG), different grid graphs D_IMG will be scanned as these two parameters change. However, the edge of this grid graph may be different from the edge of the QR code, although the edge of the QR code only plays a positioning effect. Therefore, we can first generate new edges based on the old edges, and then replace the old edges with the new edges. In this way, a new grid graph D_IMG will be obtained, and the new grid graph D_IMG will be decoded. When successful, the string is output and the scanning loop is exited.

[0102] When the scanning loop has traversed all parameter combinations, some pictures taken under poor shooting conditions still cannot be decoded. This situation is mainly because the number of pixels occupied by the QR code element is too small, such as only 2*2, or the internal code element is offset due to severe and uneven lighting, resulting in errors in the ordinary grid division method. To address this situation, we use an adaptive grid division method to perform the scanning loop. First, a fixed-size grid is used to scan the edge. The number of white pixels in the grid is counted each time the scan is performed. This can determine the edge of the QR code virtual edge and the position of the virtual edge code element. Using the position, a new scanning grid can be generated so that the centers of these grids are exactly the centers of the virtual edge code elements. For the subsequent modified grid, grid decoding is still the same as the ordinary method. When successful, a string is output and the scanning loop is exited.

[0103] A robust two-dimensional code DataMatrix decoding system is used to implement the robust two-dimensional code DataMatrix decoding method as described above, such as Figure 4 As shown, it includes an image preprocessing unit 1, an image denoising unit 2, a two-dimensional code precise positioning unit 3, a perspective or affine transformation unit 4, a scanning unit 5 and a decoded character string output unit 6;

[0104] An image preprocessing unit 1 is used to acquire an image and convert the acquired image into a binary image;

[0105] An image denoising unit 2 is used to perform denoising on the obtained binary image;

[0106] A two-dimensional code precise positioning unit 3, used to locate the precise positions of the four vertices of the two-dimensional code;

[0107] A perspective or affine transformation unit 4, used to correct the four vertices obtained by positioning;

[0108] Scanning unit 5, used to divide the grid and scan the QR code;

[0109] The decoded string output unit 6 is used to output the decoded string obtained by scanning the code;

[0110] By applying the methods and approaches of the present application, it is possible to efficiently solve common decoding problems such as missing code elements, severely uneven light distribution, scratches, excessive noise, noise similar to code elements, metal dot codes, etc., thereby greatly improving competitiveness in the field of two-dimensional code decoding.

[0111] Preferably, when the image preprocessing unit 1 performs image preprocessing:

[0112] Convert the three-channel color image into a grayscale image using the set ratio;

[0113] Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG;

[0114] Count the white pixels on the edge of the binary image W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color.

[0115] Then the binary image W_IMG is globally scanned to connect the white pixels or remove the white pixels;

[0116] Output the preprocessed image;

[0117] Convert the three-channel color image into a grayscale image using an appropriate ratio. Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG, which can effectively reduce the impact of uneven illumination distribution. Count the white pixels on the edge of W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color. Scan the entire W_IMG image, connect the white pixels, or remove the white pixels. This can effectively approach the problem of hollow circles in the dot matrix code.

[0118] Preferably, the two-dimensional code precise positioning unit 3 starts from the four corners of the two-dimensional code image, combines two adjacent points in total, and searches for eight points that meet the set requirements in the set area. The eight points have four line segments, and four intersection points P4 are determined. P4 determines four line segments L4.

[0119] The perspective or affine transformation unit 4 counts the angles theta of the opposite side segments from the four line segments L4, calculates the average length M_L of each line segment of the four line segments L4, and if there is an angle theta of the opposite side segment greater than the set value, removes the worst point in P4, and generates the fourth point G4 that satisfies the parallelogram based on the positional relationship of the remaining three points, generates new four points N_P4 based on the average length M_L, and performs image transformation on W_IMG using the perspective transformation from G4 to N_P4;

[0120] The scanning unit 5 uses the conventional grid division method to perform a scanning cycle operation. If successful, a character string is output. If failed, the position of the virtual edge code element of the two-dimensional code is located, and a new scanning grid is generated using the position so that the centers of these grids are exactly the centers of the virtual edge code elements. The scanning cycle operation is then performed again. If successful, a character string is output.

[0121] It should be understood that those skilled in the art can make improvements or changes based on the above description, and all these improvements and changes should fall within the scope of protection of the appended claims of the present invention.

Claims

1. A robust two-dimensional code DataMatrix decoding method, characterized in that: The following steps are involved: S1: Image preprocessing: Acquire an image, and convert the acquired image into a binary image; S2: Noise Removal: De-noising the obtained binary image; S3: QR code precise positioning: Locate the precise positions of the four vertices of the QR code; S4: Perspective or affine transformation: Correct the four vertices obtained by positioning; S5: Scan: Divide the grid and scan the QR code; S6: Get the decoded string; The S1: image preprocessing comprises the following specific steps: Convert the three-channel color image into a grayscale image using the set ratio; Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG; Count the white pixels on the edge of the binary image W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color. Then the binary image W_IMG is globally scanned to connect the white pixels or remove the white pixels; Output the preprocessed image; The S3: QR code precise positioning includes the following specific steps: Starting from the four corners of the QR code image, find eight points that meet the set requirements in the set area in pairs, and determine four intersection points P4 from four line segments. P4 determines four line segments L4. The setting requirements include: The minimum value of the distance between the point and the four corner vertices of the set area is less than a set value; The minimum distance between a point and the edge of the image is less than a set value; The density of white pixels near the point is higher than a set value; The S4: perspective or affine transformation comprises the following specific steps: From the four line segments L4, calculate the angle theta between the opposite line segments; Calculate the average length M_L of each of the four line segments L4; If there is an angle theta of the opposite side segments that is greater than the set value, the worst point is removed from P4, and the fourth point that satisfies the parallelogram is generated from the positional relationship of the remaining three points to obtain G4; Generate new four points N_P4 based on the average length M_L; Transform W_IMG using perspective transformation from G4 to N_P4; The S5: scanning comprises the following specific steps: The conventional grid division method is used to perform the scanning cycle operation. If successful, the string is output. If failed, the position of the virtual edge code element of the two-dimensional code is located, and a new scanning grid is generated using the position so that the center of these grids is exactly the center of the virtual edge code element. The scanning cycle operation is performed again. If successful, the string is output; The scanning cycle operation includes the following method: Given multiple groups: Parameter 1: the ratio of the white area in a single grid to the area of ​​the grid area_thres, Parameter 2: the size of a single grid relative to W_IMG size_thres; As the two parameters are different, different grid images D_IMG are scanned and decoded.

2. A robust two-dimensional code DataMatrix decoding system, used to implement the robust two-dimensional code DataMatrix decoding method as claimed in claim 1, characterized in that: It includes an image preprocessing unit, an image denoising unit, a QR code precise positioning unit, a perspective or affine transformation unit, a scanning unit and a decoded character string output unit; The image preprocessing unit is used to acquire an image and convert the acquired image into a binary image; The image denoising unit is used to perform denoising processing on the obtained binary image; The two-dimensional code precise positioning unit is used to locate the precise positions of the four vertices of the two-dimensional code; The perspective or affine transformation unit is used to correct the four vertices obtained by positioning; The scanning unit is used to divide the grid into two-dimensional codes; The decoded string output unit is used to output the decoded string obtained by scanning the code; When the image preprocessing unit performs image preprocessing: Convert the three-channel color image into a grayscale image using the set ratio; Divide the grayscale image into several small intervals, and perform binarization in each interval to obtain a binary image W_IMG; Count the white pixels on the edge of the binary image W_IMG to determine whether it is a white code on a black background or a black code on a white background. If it is the latter, invert the color. Then the binary image W_IMG is globally scanned to connect the white pixels or remove the white pixels; Output the preprocessed image; The two-dimensional code precise positioning unit starts from the four corners of the two-dimensional code image, and searches for eight points that meet the set requirements in a set area in pairs, and determines four intersection points P4 from four line segments of the eight points, and P4 determines four line segments L4; The perspective or affine transformation unit counts the angles theta of the opposite side segments from the four line segments L4, calculates the average length M_L of each line segment of the four line segments L4, and if there is an opposite side segment angle theta greater than a set value, removes the worst point in P4, generates a fourth point G4 that satisfies the parallelogram based on the positional relationship of the remaining three points, generates new four points N_P4 based on the average length M_L, and performs image transformation on W_IMG using the perspective transformation from G4 to N_P4; The scanning unit uses a conventional grid division method to perform a scanning cycle operation. If successful, a character string is output. If failed, the position of the virtual edge code element of the two-dimensional code is located, and a new scanning grid is generated using the position so that the centers of these grids are exactly the centers of the virtual edge code elements. The scanning cycle operation is then performed again. If successful, a character string is output.