Two-dimensional code recognition preprocessing method
By graying, binarizing and morphological processing of QR code images, screening and rotating the QR code area, combining edge extraction and superposition processing, the problems of low accuracy and high cost of QR code recognition are solved, and more efficient QR code recognition is achieved.
Patent Information
- Application Number
- CN202510118291.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-05-27
AI Technical Summary
The existing QR code recognition technology has low recognition accuracy, high cost and poor versatility when the image is not clear or the QR code is far away.
A preprocessing method for identifying QR codes is proposed, including grayscale, binarization, operation and non-operation processing, extracting the pixel continuous position sequence of the connected area, filtering the area containing the QR code, obtaining the position information of the smallest external rectangle through principal component analysis, performing rotation processing and edge extraction, and finally performing superposition and adaptive binarization processing to obtain the preprocessed QR code image.
It improves the accuracy of QR code recognition, reduces cost, and enhances the universality of the method. Especially when the QR code distance is far away and the image is not clear, the recognition distance can reach 11.5cm.
Smart Images

Figure CN120047692A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image recognition, and particularly relates to a preprocessing method for two-dimensional code recognition. Background Art
[0002] With the continuous development of the Internet, two-dimensional code recognition technology has been widely applied in industries such as retail, finance, transportation, culture and entertainment, education, and medical care, as well as in actual life application scenarios. The factors affecting the recognition accuracy of two-dimensional codes include image quality, two-dimensional code size, illumination conditions, scanning distance, etc.
[0003] When the image is unclear, the existing preprocessing methods for improving the recognition accuracy of two-dimensional codes are mainly as follows: 1) Using a super-resolution algorithm based on deep learning to make the image clear, and then performing two-dimensional code recognition; 2) Increasing the image contrast by adjusting the lens image signal processor (ISP), and then performing two-dimensional code recognition; 3) Selecting a lens with a larger depth of field and a higher image resolution, and then performing two-dimensional code recognition. However, although the super-resolution algorithm based on deep learning can make the image clear, it has high hardware requirements and high costs; increasing the contrast by adjusting the lens ISP is only applicable to color images and is ineffective for black-and-white images; selecting a lens with a larger depth of field and a higher resolution will also increase costs.
[0004] Therefore, in order to further improve the recognition accuracy of two-dimensional codes, reduce costs, and have good versatility, especially for the problem that two-dimensional codes are not well recognized when the image is unclear at a relatively far position, a preprocessing method for two-dimensional code recognition is proposed. Summary of the Invention
[0005] The purpose of the present invention is to propose a preprocessing method for two-dimensional code recognition aiming at the above problems, which improves the recognition accuracy of two-dimensional codes, has low costs, and good versatility, and is especially suitable for recognizing blurred two-dimensional codes at a long distance.
[0006] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0007] A preprocessing method for two-dimensional code recognition proposed by the present invention includes the following steps:
[0008] (1) Obtain the original two-dimensional code image and form a grayscale image;
[0009] (2) Perform binarization processing on the grayscale image to obtain a binarized image;
[0010] (3) Perform opening operation processing and NOT operation processing on the binarized image in sequence to obtain a first image;
[0011] (4) Extract the pixel continuous position sequences of each connected region in the first image;
[0012] (5) Count the number of pixels in the corresponding connected region according to the pixel continuous position sequence of all connected regions, and screen out the connected regions containing QR codes. The screening of the connected regions containing QR codes is as follows:
[0013] If the number of pixels in the corresponding connected region is greater than the preset quantity and less than half of the total number of pixels of the first image, then consider this connected region as a connected region containing a QR code and execute step (6); otherwise, consider this connected region as a connected region without a QR code and end the process.
[0014] (6) Use the principal component analysis method to obtain the position information of the minimum circumscribed rectangle of all connected regions containing QR codes. The position information includes the center coordinates (x center , y center ), width w, height h, and rotation angle angle, and calculate the four corner coordinates Pt0, Pt1, Pt2, and Pt3 of the corresponding minimum circumscribed rectangle. Among them, x center is the abscissa of the center, y center is the ordinate of the center. Pt0 and Pt2 are opposite corner coordinates, Pt1 and Pt3 are opposite corner coordinates, and angle is the angle between the first side of the corresponding minimum circumscribed rectangle encountered when the coordinate horizontal axis rotates counterclockwise and the coordinate horizontal axis. Then, take the length of the first side as w and the length of the adjacent side of the first side as h.
[0015] (7) Obtain the corresponding preprocessed QR code images for QR code recognition according to the position information and corner coordinates of each minimum circumscribed rectangle respectively.
[0016] Preferably, obtain the corresponding preprocessed QR code images for QR code recognition according to the position information and corner coordinates of each minimum circumscribed rectangle respectively, and specifically perform the following operations:
[0017] (7.1) If the difference between the width w and height h of the current minimum circumscribed rectangle is within the preset number of pixels, then take the center coordinates (x center , y center ) as the center, perform an affine transformation on the original QR code image to rotate it counterclockwise by angle degrees to obtain the corresponding rotation transformation matrix M. Then, perform an M transformation on each pixel of the original QR code image to obtain the rotated image, and intercept the rotated image with Pt1 as the upper left corner point, height h, and width w to obtain the cropped image. If the difference between the width w and height h of the current minimum circumscribed rectangle exceeds the preset number of pixels, then take the center coordinates (x center , y center)Centered around , the original QR code image is rotated counterclockwise by angle + 90° using an affine transformation to obtain the corresponding rotation transformation matrix M. Then, each pixel of the original QR code image is transformed by M to obtain the rotated image. The cropped image is obtained by cropping the rotated image with the corner coordinate Pt2 as the upper left corner point, height h, and width w;
[0018] (7.2) Edge extraction is performed on the cropped image to obtain the edge image;
[0019] (7.3) The edge image and the cropped image are superimposed to obtain the superimposed image;
[0020] (7.4) The superimposed image is enlarged, and the enlarged superimposed image is subjected to adaptive binarization processing. The obtained adaptive binarization image is the preprocessed QR code image for QR code recognition.
[0021] Preferably, the binarization processing of the grayscale image is as follows:
[0022] When the grayscale value of the pixel point in the grayscale image is greater than the preset threshold, the grayscale value of the corresponding pixel point is set to 255; otherwise, the grayscale value of the corresponding pixel point is set to 0.
[0023] Preferably, the preset quantity is 500, the preset pixel is 100, and the preset threshold is 160.
[0024] Preferably, the superimposed image satisfies:
[0025] img_cut_add = img_cut - 0.7 * img_cut_lap
[0026] where img_cut_add represents the superimposed image, img_cut represents the cropped image, and img_cut_lap represents the edge image.
[0027] Preferably, enlarging the superimposed image specifically means doubling both the length and width of the superimposed image.
[0028] Preferably, the coordinate formulas for the four corner points are as follows:
[0029] Pt0 = (x center - sin(angle) * h / 2 - cos(angle) * w / 2, y center + cos(angle) * h / 2 - sin(angle) * w / 2);
[0030] Pt1 = (x center + sin(angle) * h / 2 - cos(angle) * w / 2, y center-cos(angle)*h / 2 - sin(angle)*w / 2);
[0031] Pt2 = (x center + sin(angle)*h / 2 + cos(angle)*w / 2, y center -cos(angle)*h / 2 + sin(angle)*w / 2);
[0032] Pt3 = (x center -sin(angle)*h / 2 + cos(angle)*w / 2, y center + cos(angle)*h / 2 + sin(angle)*w / 2);
[0033] In the formula, taking the upper left point of the original QR code image as the coordinate origin, Pt0 is the coordinate of the lower right corner point of the corresponding minimum circumscribed rectangle, Pt1 is the coordinate of the lower left corner point of the corresponding minimum circumscribed rectangle, Pt2 is the coordinate of the upper left corner point of the corresponding minimum circumscribed rectangle, and Pt3 is the coordinate of the upper right corner point of the corresponding minimum circumscribed rectangle.
[0034] Preferably, the grayscale image is obtained as follows:
[0035] Judge whether the original QR code image is a color image. If so, perform grayscale transformation to obtain the grayscale image; if not, directly obtain the grayscale image without performing grayscale transformation.
[0036] Preferably, the pixel continuous position sequence of each connected region in the first image is extracted by using the findConontours function.
[0037] Preferably, QR code recognition is performed using the recognition function of the zxing library or the zbar library.
[0038] Compared with the prior art, the beneficial effects of the present invention are:
[0039] In this application, the original QR code image is successively subjected to grayscale conversion, binarization, opening operation, and negation operation to extract the pixel continuous position sequence of each connected region, and then the connected region containing the QR code is screened out. According to the position information and corner coordinates of each minimum bounding rectangle, the corresponding preprocessed QR code image can be obtained for QR code recognition. After rotating the contour according to the position information and corner coordinates of the minimum bounding rectangle and intercepting the target region image (cropped image), edge extraction is performed on the obtained target region image to obtain an edge image. The edge image is superimposed on the intercepted target region image to ensure that there is more information in the region, and adaptive binarization processing is performed after magnifying the superimposed image to increase the proportion of the QR code in the image. This method solves the problem in the prior art that when the QR code is at a relatively long distance, the image will be unclear, resulting in the inability to recognize the QR code information. Through the present invention, the recognition effect can be improved, and the cost is lower compared to the preprocessing method using the super-resolution algorithm based on deep learning in the prior art or the solution of replacing the lens with a larger depth of field and higher resolution. For example, with the same lens, the recognition distance of the prior art can reach 7 cm, while the recognition distance of this application can reach 11.5 cm. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 is a flowchart of the preprocessing method for QR code recognition of the present invention;
[0041] Figure 2 is a schematic diagram of the minimum bounding rectangle of the present invention;
[0042] Figure 3 is a schematic diagram of the calculation principle of the four corner coordinates of the minimum bounding rectangle of the present invention;
[0043] Figure 4 is the original QR code image (a) and the recognition result image (b) using the preprocessing method for QR code recognition of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0044] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0045] It should be noted that unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field of the present application. The terms used in the specification of the present application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application.
[0046] In image recognition, image preprocessing is a very important step. The main purpose is to filter out interference information in the image and enhance useful real information, thereby improving the reliability of feature extraction, image segmentation, matching, and recognition.
[0047] As Figures 1-4 shown, a preprocessing method for QR code recognition includes the following steps:
[0048] (1) Obtain the image containing the QR code as the original QR code image img. If the original QR code image img is an RGB image (color image), perform grayscale transformation to obtain the corresponding grayscale image img_gray; if the original QR code image img is directly a grayscale image img_gray, there is no need to perform grayscale transformation.
[0049] (2) Perform binarization processing on the grayscale image img_gray. When the grayscale value of a pixel point in the grayscale image is greater than 160 (this preset threshold can be adjusted according to the actual situation), set the grayscale value of the corresponding pixel point to 255; otherwise, set the grayscale value of the corresponding pixel point to 0 to obtain the binarized image img_thre.
[0050] (3) Perform opening operation on the binarized image img_thre to obtain the dilated image img_open after the opening operation, which is used to eliminate noise, separate objects, and smooth boundaries. Then perform non-operation on the dilated image img_open to obtain the first image img_non, which is used to reduce background interference and turn the QR code area from black to white for subsequent extraction.
[0051] (4) Use the findConontours function to extract the pixel continuous position sequence contours of each connected region from the first image img_non.
[0052] (5) According to the pixel continuous position sequences of all connected regions, count the number of pixels in the corresponding connected regions and screen out the connected regions containing QR codes. If the number of pixels in the corresponding connected region is greater than 500 and less than half of the total number of pixels of the first image, then consider this connected region as the connected region containing the QR code and execute step (6); otherwise, consider this connected region as the connected region without QR codes and end the process.
[0053] (6) Use the principal component analysis method to obtain the position information of the minimum bounding rectangle of all connected regions containing QR codes, and then obtain the center coordinates (x center , y center )、width w、height h and rotation angle angle of the corresponding minimum bounding rectangle, where x center is the center abscissa, y centeris the central ordinate, Pt0 and Pt2 are opposite corner coordinates, Pt1 and Pt3 are opposite corner coordinates, angle is the angle between the first side of the corresponding minimum bounding rectangle encountered when the coordinate horizontal axis (the horizontal axis is the X-axis) rotates counterclockwise and the coordinate horizontal axis, then the length of the first side is w, and the length of the adjacent side of the first side is h.
[0054] Then, according to the center coordinates (x center , y center ), width w, height h, and rotation angle angle, calculate and obtain the four corner coordinates Pt0, Pt1, Pt2, and Pt3 of the corresponding minimum bounding rectangle, taking Figure 2 the positions of the four corners in the image as an example. Among them, let the intermediate quantity θ = -angle, the angle range of angle is (-90, 0], with the upper left point of the original QR code image as the coordinate origin O, and the X-axis and Y-axis directions are as Figure 2 shown. As Figure 3 shown, the four corner coordinates are Pt0 = (x 0 , y 0 ), Pt1 = (x 1 , y 1 ), Pt2 = (x 2 , y 2 ), Pt3 = (x 3 , y 3 ), then the coordinates of the four corners are calculated as follows:
[0055] x 0 = x center + AB - BC = x center + (h / 2) * sin(θ) - (w / 2) * cos(θ)
[0056] = x center + (h / 2) * sin(-angle) - (w / 2) * cos(-angle)
[0057] = x center - (h / 2) * sin(angle) - (w / 2) * cos(angle)
[0058] y 0 = y center + oA + AD 1 = y center + (h / 2) * cos(θ) + (w / 2) * sin(θ)
[0059] = y center + (h / 2) * cos(-angle) + (w / 2) * sin(-angle)
[0060] = ycenter +(h / 2)*cos(angle)-(w / 2)*sin(angle)
[0061] x 1 = x center -oE r -EE 1 = x center -(h / 2)*sin(θ)-(w / 2)*cos(θ)
[0062] = x center -(h / 2)*sin(-angle)-(w / 2)*cos(-angle)
[0063] = x center +(h / 2)*sin(angle)-(w / 2)*cos(angle)
[0064] y 1 = y center -F 1 Pt1+E 1 F 1 = y center -(h / 2)*cos(θ)+(w / 2)*sin(θ)
[0065] = y center -(h / 2)*cos(-angle)+(w / 2)*sin(-angle)
[0066] = y center -(h / 2)*cos(angle)-(w / 2)*sin(angle)
[0067] x 2 = x center -HPt2+EE 1 = x center -(h / 2)*sin(θ)+(w / 2)*cos(θ)
[0068] = x center -(h / 2)*sin(-angle)+(w / 2)*cos(-angle)
[0069] = x center +(h / 2)*sin(angle)+(w / 2)*cos(angle)
[0070] y 2 = y center +oG 1 +GG 1 = y center+(h / 2)*cos(θ)+(w / 2)*sin(θ)
[0071] = y center +(h / 2)*cos(-angle)+(w / 2)*sin(-angle)
[0072] = y center +(h / 2)*cos(angle)-(w / 2)*sin(angle)
[0073] x 3 = x center + B 1 Pt3 + B 1 B 2 = x center +(h / 2)*sin(θ)+(w / 2)*cos(θ)
[0074] = x center +(h / 2)*sin(-angle)+(w / 2)*cos(-angle)
[0075] = x center -(h / 2)*sin(angle)+(w / 2)*cos(angle)
[0076] y 3 = y center + BB 3 - BB 1 = y center +(h / 2)*cos(θ)-(w / 2)*sin(θ)
[0077] = y center +(h / 2)*cos(-angle)-(w / 2)*sin(-angle)
[0078] = y center +(h / 2)*cos(angle)+(w / 2)*sin(angle)
[0079] Figure 3 In it, point O represents the coordinate origin, that is, the upper left point of the original QR code image. The positive X-axis direction of the original QR code image is horizontally to the right, and the positive Y-axis direction of the original QR code image is vertically downward. Pt0, Pt1, Pt2, and Pt3 are the four corner points of the minimum circumscribed rectangle respectively, point o is the center point of the minimum circumscribed rectangle, θ is an intermediate quantity, w is the width of the minimum circumscribed rectangle, and h is the height of the minimum circumscribed rectangle. The dashed line such as oD 1, oB, oPt0, AB, Pt0C, BD are auxiliary lines for calculating the corner coordinates of Pt0. Among them, point B is the midpoint of the line segment Pt0Pt3, and the line segment oD 1 is perpendicular to the line segment passing through point Pt0 and parallel to the X-axis, and the intersection point is D 1 , the line segment AB is parallel to the X-axis and perpendicular to oD 1 The lines intersect at point A. The line segment BD is parallel to the Y-axis and intersects the line segment passing through point Pt0 and parallel to the X-axis at point D. The line segment Pt0C is parallel to the Y-axis and intersects the line AB at point C. The dotted lines oPt1, oF, oE 1 , oO 1 , O 1 F 1 , FE are auxiliary lines for calculating the corner coordinates of Pt1. Among them, O 1 is the midpoint of the line segment Pt0Pt1, and F is the midpoint of the line segment Pt1Pt2. The line segment oE 1 is perpendicular to the line segment passing through point Pt1 and parallel to the Y-axis, and the intersection point is E 1 , the line segment O 1 F 1 is perpendicular to the line segment passing through point Pt1 and parallel to the Y-axis, and the intersection point is F 1 , the line segment FE is perpendicular to the line segment oE 1 and the intersection point is E. The dotted lines such as oPt2, oO 2 , O 2 H, oG, O 2 G 1 are auxiliary lines for calculating the corner coordinates of Pt2. Among them, O 2 is the midpoint of the line segment Pt2Pt3. The line segment O 2 H is perpendicular to the line segment passing through point Pt2 and parallel to the X-axis, and the intersection point is H. The line segment oG is parallel to the Y-axis and intersects the line segment Pt2H at point G. The line segment O 2 G 1 is perpendicular to the line segment oG, and the intersection point is G 1 . The dotted lines such as Pt3B 2 , BB 3 , oB 3 are auxiliary lines for calculating the corner coordinates of Pt3. Among them, BB 3 is perpendicular to the line segment passing through point o and parallel to the X-axis, and the intersection point is B 3 , Pt3B 2 is perpendicular to the line segment oD 1 and the intersection point is B 2 , the line segment Pt3B 2 intersects the line segment BB 3 at point B 1 .
[0080] (7) According to the position information and corner coordinates of each minimum bounding rectangle, obtain the corresponding preprocessed QR code image for QR code recognition. The specific operations are as follows:
[0081] (7.1) If the difference between the width w and height h of the current minimum bounding rectangle is within 100 pixels, then, with the center coordinates (x center , y center ) as the center, perform an affine transformation on the original QR code image img, rotate it counterclockwise by an angle of angle (equivalent to Figure 2 the minimum bounding rectangle in it rotates clockwise by θ, and after rotation, Pt1 is the upper left corner point of the minimum bounding rectangle), obtain the corresponding rotation transformation matrix M. Then, perform an M transformation on each pixel of the original QR code image img to obtain the rotated image img_rotatio. Crop the rotated image img_rotatio with the corner coordinates Pt1 as the upper left corner point, height h, and width w to obtain the cropped image img_cut; if the difference between the width w and height h of the current minimum bounding rectangle exceeds 100 pixels, then, with the center coordinates (x center , y center ) as the center, perform an affine transformation on the original QR code image img, rotate it counterclockwise by angle + 90° (equivalent to Figure 2 the minimum bounding rectangle in it rotates counterclockwise by 90 - θ, and after rotation, Pt2 is the upper left corner point of the minimum bounding rectangle), obtain the corresponding rotation transformation matrix M. Then, perform an M transformation on each pixel of the original QR code image img to obtain the rotated image img_rotatio. Crop the rotated image img_rotatio with the corner coordinates Pt2 as the upper left corner point, height h, and width w to obtain the cropped image img_cut. Generally, the rotated QR code is contained in the cropped image img_cut.
[0082] (7.2) Perform edge extraction on the cropped image to obtain an edge image. When the target is far away, the cropped image may have problems such as unclear image and the QR code imaging being small in the cropped image. To ensure that more information of the QR code is not lost, perform Laplacian edge extraction on the cropped image img_cut (other edge extraction methods well-known to those skilled in the art can also be used) to obtain the edge image img_cut_lap.
[0083] (7.3) Superimpose the edge image img_cut_lap and the cropped image img_cut to obtain a superimposed image img_cut_add. Among them, the superimposed image satisfies: img_cut_add = img_cut - 0.7 * img_cut_lap.
[0084] (7.4) Enlarge the superimposed image img_cut_add, and perform adaptive binarization processing img_cut_adp on the enlarged superimposed image img_cut_resize. The obtained adaptive binarized image img_cut_adp is the preprocessed QR code image for QR code recognition. Preferably, both the length and width of the superimposed image are enlarged by two times (the magnification factor can be adjusted according to the actual situation). For QR code recognition of the preprocessed QR code image, the zxing library recognition function or the zbar library recognition function can be used, or other recognition parameters well-known to those skilled in the art can also be used.
[0085] As Figure 4 shown, Figure (a) is the original QR code image, and the QR code in the figure is relatively blurred. The recognition result of the preprocessed QR code image obtained by using the method of this application is Figure (b). The detected content information is the QR code recognition result of Figure (a), and QR code recognition can be accurately performed.
[0086] The technical features of the above-described embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.
[0087] The above-described embodiments only represent the embodiments of this application that are described in more specific and detailed ways, but should not be construed as a limitation on the scope of the patent application. It should be noted that for those of ordinary skill in the art, without departing from the concept of this application, several modifications and improvements can still be made, and these all belong to the protection scope of this application. Therefore, the protection scope of the patent of this application shall be subject to the appended claims.
Claims
1. A two-dimensional code recognition preprocessing method, characterized in that: The two-dimensional code recognition preprocessing method comprises the following steps: (1) Obtaining the original two-dimensional code image and forming a grayscale image; (2) Binarizing the grayscale image to obtain a binary image; (3) performing opening and closing operations on the binary image in sequence to obtain a first image; (4) extracting a sequence of continuous pixel positions of each connected region in the first image; (5) Counting the number of pixels in the corresponding connected regions according to the pixel continuous position sequences of all connected regions, and screening out the connected regions containing the two-dimensional code, wherein the connected regions containing the two-dimensional code are screened as follows: If the number of pixels in the corresponding connected area is greater than a preset number and less than half of the total number of pixels in the first image, the connected area is considered to be a connected area containing a two-dimensional code, and step (6) is executed; otherwise, the connected area is considered to be a connected area without a two-dimensional code, and the process ends; (6) The principal component analysis method is used to obtain the position information of the minimum circumscribed rectangle of all connected areas containing the two-dimensional code, and the position information includes the center coordinates (x center ,y center ), width w, height h and rotation angle angle, and calculate the coordinates of the four corner points of the corresponding minimum circumscribed rectangle Pt0, Pt1, Pt2 and Pt3, where x center is the central horizontal coordinate, y center is the center ordinate, Pt0 and Pt2 are the relative corner coordinates, Pt1 and Pt3 are the relative corner coordinates, angle is the angle between the first side of the corresponding minimum circumscribed rectangle encountered when the coordinate horizontal axis rotates counterclockwise and the coordinate horizontal axis, the length of the first side is w, and the length of the adjacent side of the first side is h; (7) According to the position information and corner point coordinates of each minimum circumscribed rectangle, a corresponding pre-processed two-dimensional code image is obtained for use in two-dimensional code recognition.
2. The two-dimensional code recognition preprocessing method according to claim 1, characterized in that: According to the position information and corner point coordinates of each minimum circumscribed rectangle, the corresponding pre-processed two-dimensional code image is obtained for two-dimensional code recognition, and the specific operations are as follows: (7.1) If the difference between the width w and height h of the current minimum bounding rectangle is within the preset pixel range, the center coordinate (x center ,y center ) as the center, use affine transformation to rotate the original two-dimensional code image counterclockwise by angle angle to obtain the corresponding rotation transformation matrix M, then perform M transformation on each pixel of the original two-dimensional code image to obtain the rotated image, and intercept the rotated image with the corner point coordinates Pt1 as the upper left corner point, height h, and width w to obtain the cropped image; if the difference between the width w and height h of the current minimum bounding rectangle exceeds the preset pixels, then the center coordinates (x center ,y center ) as the center, use affine transformation to rotate the original two-dimensional code image counterclockwise by angle+90° to obtain the corresponding rotation transformation matrix M, then perform M transformation on each pixel of the original two-dimensional code image to obtain the rotated image, and intercept the rotated image with the corner point coordinate Pt2 as the upper left corner point, height h, and width w to obtain the cropped image; (7.2) extracting edges of the cropped image to obtain an edge image; (7.3) superimposing the edge image and the cropped image to obtain a superimposed image; (7.4) The superimposed image is enlarged, and the enlarged superimposed image is adaptively binarized. The obtained adaptive binarized image is the preprocessed two-dimensional code image for two-dimensional code recognition.
3. The two-dimensional code recognition preprocessing method according to claim 2, characterized in that: The grayscale image is binarized as follows: When the grayscale value of a pixel in the grayscale image is greater than a preset threshold, the grayscale value of the corresponding pixel is set to 255, otherwise, the grayscale value of the corresponding pixel is set to 0.
4. The two-dimensional code recognition preprocessing method according to claim 3, characterized in that: The preset number is 500, the preset pixels are 100, and the preset threshold is 160.
5. The two-dimensional code recognition preprocessing method according to claim 2, characterized in that: The superimposed image satisfies: img_cut_add=img_cut-0.7*img_cut_lap Among them, img_cut_add represents the overlay image, img_cut represents the cropped image, and img_cut_lap represents the edge image.
6. The two-dimensional code recognition preprocessing method according to claim 2, characterized in that: The enlarging the superimposed image specifically includes enlarging the length and width of the superimposed image by two times.
7. The two-dimensional code recognition preprocessing method according to claim 1, characterized in that: The coordinate formulas of the four corner points are as follows: Pt0=(x center -sin(angle)*h / 2-cos(angle)*w / 2,y center +cos(angle)*h / 2-sin(angle)*w / 2); Pt1=(x center +sin(angle)*h / 2-cos(angle)*w / 2,y center -cos(angle)*h / 2-sin(angle)*w / 2); Pt2=(x center +sin(angle)*h / 2+cos(angle)*w / 2,y center -cos(angle)*h / 2+sin(angle)*w / 2); Pt3=(x center -sin(angle)*h / 2+cos(angle)*w / 2,y center +cos(angle)*h / 2+sin(angle)*w / 2); In the formula, the upper left point of the original two-dimensional code image is taken as the coordinate origin, then Pt0 is the coordinate of the lower right corner point of the corresponding minimum enclosing rectangle, Pt1 is the coordinate of the lower left corner point of the corresponding minimum enclosing rectangle, Pt2 is the coordinate of the upper left corner point of the corresponding minimum enclosing rectangle, and Pt3 is the coordinate of the upper right corner point of the corresponding minimum enclosing rectangle.
8. The two-dimensional code recognition preprocessing method according to claim 1, characterized in that: The grayscale image is obtained as follows: Determine whether the original two-dimensional code image is a color image. If so, perform grayscale transformation to obtain a grayscale image; if not, directly obtain a grayscale image without performing grayscale transformation.
9. The two-dimensional code recognition preprocessing method according to claim 1, characterized in that: The pixel continuous position sequence of each connected area in the first image is extracted using the findConontours function.
10. The two-dimensional code recognition preprocessing method according to claim 1, characterized in that: The two-dimensional code recognition adopts the zxing library recognition function or the zbar library recognition function.