Fast decoding method, system and device for scanner based on image technology
By detecting the QR code boundary line in Hough space and correcting it in combination with the graphic position relationship and pixel point difference, the problem of inaccurate QR code boundary detection in traditional methods is solved, and the distortion correction and decoding of QR code images is improved. sex.
Patent Information
- Application Number
- CN202410954872.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-07-17
AI Technical Summary
Traditional QR code recognition methods rely on accurate detection of image vertices. However, due to uneven boundaries of QR codes, Hough linear detection is difficult to accurately reflect the true boundary characteristics, resulting in insufficient accuracy of distortion correction.
Using a fast decoding method based on image technology, a possible boundary straight line is obtained in the Hough space through Hough line detection, combining the position relationship of the image search graph and the difference in the number of pixels, the correction factor is calculated, and the possibility of the boundary straight line is adjusted, and then a QR code is performed. Distortion correction and decoding of images.
It improves the ability of Hough line to represent the real QR code boundaries, enhances the accuracy of distortion correction, and ensures effective decoding of QR code images.
Smart Images

Figure CN118839708B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image data processing, and in particular to a fast decoding method, system and device for a scanner based on image technology. Background Art
[0002] QR code is a two-dimensional barcode technology that can be quickly scanned and read by a scanner. Due to its anti-information loss and data transmission security, QR code is widely used in people's daily life. The scanner can obtain the QR code image through the built-in optical sensor and use the decoding algorithm to extract the information in the QR code to complete the interaction and application of devices, systems or information. However, in daily life, QR codes are often distorted, which affects the recognition of QR codes.
[0003] In QR code recognition and distortion correction, the four corner points (upper left, upper right, lower left and lower right) of the QR code are often detected, and then these corner points are used to determine the geometric transformation parameters of the QR code. By mapping these four corner points to an assumed standard position, the corresponding transformation matrix can be calculated, and then the entire QR code image can be corrected to eliminate problems such as perspective distortion and non-uniform scaling. However, the calculation of the transformation matrix depends on the accuracy of the vertex detection of the QR code image, and the accuracy of the vertices obtained by the traditional corner point detection method depends on the accuracy of the QR code boundary line detection. However, since the boundary of the QR code is not composed of the same type of pixels, the Hough line obtained by the traditional Hough line detection cannot accurately reflect the real boundary characteristics of the QR code. Summary of the invention
[0004] The present invention provides a fast decoding method, system and device for a scanner based on image technology to solve the existing problems.
[0005] The fast decoding method, system and device for scanner based on image technology of the present invention adopt the following technical solutions:
[0006] An embodiment of the present invention provides a fast decoding method for a scanner based on image technology, the method comprising the following steps:
[0007] Acquire a two-dimensional code image and several image-finding patterns of the two-dimensional code image, pre-process the two-dimensional code image, and acquire a two-dimensional code contour image;
[0008] Perform straight line detection on the two-dimensional code contour image to obtain a possible boundary line, and obtain the possibility that the possible boundary line is a real boundary line according to the position difference between the corresponding data point of the possible boundary line and other data points in the Hough space during the straight line detection process; calculate the possibility correction factor that the possible boundary line is a real boundary line according to the position relationship between the possible boundary line and the image-finding pattern and the number difference of pixel points on both sides of the possible boundary line; use the possibility correction factor that the possible boundary line is a real boundary line to adjust the possibility that the possible boundary line is a real boundary line, and obtain an evaluation index that the possible boundary line is a real boundary line;
[0009] The two-dimensional code image is subjected to distortion correction according to an evaluation index that a possible boundary line is a true boundary line, and a corrected two-dimensional code image is obtained;
[0010] Decode the corrected QR code image.
[0011] Furthermore, the method of performing straight line detection on the two-dimensional code contour image to obtain a possible boundary line and obtaining the possibility that the possible boundary line is a true boundary line according to the position difference between the corresponding data point of the possible boundary line and other data points in the Hough space during the straight line detection process includes the following specific methods:
[0012] Hough line detection is used to detect the possible boundary lines of the two-dimensional code contour image; any possible boundary line L is selected, and the data points corresponding to the possible boundary line L in the Hough space are obtained and recorded as target data points; a rectangular neighborhood of size A×B is constructed with the target data point as the center, and the i-th data point in the rectangular neighborhood of the target data point is recorded as the neighborhood data point of the target data point. Wherein A and B are the preset first parameter and the preset second parameter;
[0013] The coordinates of the data points in the Hough space are used as the line parameters of the data points;
[0014] The method to obtain the possibility that any possible boundary line is the true boundary line is:
[0015]
[0016] Among them, s(L) represents the possibility that the possible boundary line L is the true boundary line; SL i Represents the cumulative number of the i-th neighborhood data points of the target data point in Hough space; n L Represents the cumulative number of target data points corresponding to the possible boundary line L in the Hough space; N L represents the sum of the cumulative number of all neighboring data points of the target data point corresponding to the possible boundary line L in the Hough space; p represents the line parameter of the target data point, p′i represents the straight line parameter of the i-th neighborhood data point of the target data point; E() represents the mean function, and ‖ ‖ is the modulus operation.
[0017] Furthermore, the possibility correction factor of the possible boundary line being the true boundary line is calculated based on the positional relationship between the possible boundary line and the image-finding pattern and the difference in the number of pixels on both sides of the possible boundary line, including the specific method of:
[0018] Obtain the outer contour pixel points of the image-seeking pattern and the maximum number of overlapping pixel points of the possible boundary straight line L and the image-seeking pattern;
[0019] According to the difference in the number of pixels on both sides of the possible boundary line L, the difference in the number of black pixels of the possible boundary line L is obtained;
[0020] Project the two-dimensional code contour image onto the possible boundary line L to obtain the projection line segment corresponding to the two-dimensional code contour image;
[0021] The method for obtaining the possibility correction factor that any possible boundary line is a true boundary line is:
[0022]
[0023] Where t(L) represents the possibility correction factor that the possible boundary line L is the true boundary line; δB L represents the difference in the number of black pixels of the possible boundary line L; T L represents the length of the projected line segment of the two-dimensional code outline image on the possible boundary line L, CL represents the length of the possible boundary line L, and the length is the number of pixels included; NS L Indicates the maximum number of overlapping pixels between the possible boundary line L and the image search pattern; d L It represents the average shortest distance from the outer contour pixel points of the image-seeking figure to the possible boundary line L; norm() represents the normalization function.
[0024] Furthermore, the outer contour pixel points of the image-finding pattern and the maximum number of overlapping pixel points of the possible boundary line L and the image-finding pattern are obtained by:
[0025] For the possible boundary line L to be judged, obtain the set of pixels with gray value of 0 in each image-finding pattern, record it as the direction-finding pixel set, further obtain the pixels located at the edge of the image-finding pattern in the direction-finding pixel set, record it as the outer contour pixel points of the image-finding pattern, record the set formed by the outer contour pixel points of each image-finding pattern as the outer contour pixel point set of each image-finding pattern, obtain the pixels included in the possible boundary line L and the pixel points with the same coordinates as the pixel points in each outer contour pixel point set as the overlapping pixel points, and record the number of overlapping pixel points corresponding to the maximum number of overlapping pixel points between all outer contour pixel point sets as NS L .
[0026] Furthermore, the specific method for obtaining the difference in the number of black pixels of the possible boundary line L is:
[0027] The extension line of the possible boundary line L divides the two-dimensional code binary image into two areas, recorded as area 1 and area 2, and obtains the number of pixels with grayscale value 0 in the two areas, recorded as the number of black pixels in area 1 and the number of black pixels in area 2. The number of black pixels in area 1 is subtracted from the number of black pixels in area 2 and the absolute value is taken, which is recorded as the difference in the number of black pixels of the possible boundary line L, recorded as δB L .
[0028] Furthermore, the possibility correction factor of the possible boundary line being the true boundary line is used to adjust the possibility of the possible boundary line being the true boundary line to obtain an evaluation index of whether the possible boundary line is the true boundary line, including the specific method of:
[0029] The method for obtaining the evaluation index of any possible boundary line as the true boundary line is:
[0030] S(L)=t(L)×s(L)
[0031] Among them, S(L) represents the evaluation index of the possible boundary line L being the true boundary line, t(L) represents the possibility correction factor of the possible boundary line L being the true boundary line, and s(L) represents the possibility of the possible boundary line L being the true boundary line.
[0032] Furthermore, the distortion correction of the two-dimensional code image is performed according to the evaluation index of whether the possible boundary line is a true boundary line to obtain the corrected two-dimensional code image, including the specific method of:
[0033] Select the possible boundary lines in the two-dimensional code contour image as the M possible boundary lines with the largest evaluation index of the true boundary lines, perform K-means clustering with a K value of 4 on the line parameters of the M possible boundary lines to obtain four clusters, obtain the mean of the line parameters in each cluster, record it as the line parameters of the Hough lines of the four boundaries of the two-dimensional code, extend the Hough lines of the four boundaries to obtain four intersection points, record the four intersection points as the four vertices of the two-dimensional code, and record the coordinates of the four vertices, where M is a preset parameter and M≥K;
[0034] A square is constructed, the coordinates of the four corners of the square are obtained, the coordinates of the four vertices and the coordinates of the four corners of the square are combined, and the two-dimensional code image is processed using affine transformation to obtain a corrected two-dimensional code image.
[0035] Furthermore, the decoding of the corrected two-dimensional code image includes the following specific methods:
[0036] The position of the direction-finding image is determined again for the corrected QR code image to complete the positioning of the QR code, and the QRCodeDetector of OpenCV is used to decode the corrected QR code image; the error correction code and correction code generated by the QR code are used to complete the correction of the decoded information.
[0037] A fast decoding system for a scanner based on image technology adopts any one of the fast decoding methods for a scanner based on image technology, and the system comprises the following modules:
[0038] Image processing module: used to obtain the two-dimensional code image and several image-seeking patterns of the two-dimensional code image, pre-process the two-dimensional code image, and obtain the two-dimensional code contour image;
[0039] Boundary determination module: used to perform straight line detection on the two-dimensional code contour image to obtain possible boundary lines, and obtain the possibility that the possible boundary line is the real boundary line according to the position difference between the corresponding data point of the possible boundary line and other data points in the Hough space during the straight line detection process; calculate the possibility correction factor that the possible boundary line is the real boundary line according to the position relationship between the possible boundary line and the image-finding pattern and the number difference of pixel points on both sides of the possible boundary line; use the possibility correction factor that the possible boundary line is the real boundary line to adjust the possibility that the possible boundary line is the real boundary line, and obtain the evaluation index that the possible boundary line is the real boundary line;
[0040] Distortion correction module: used to perform distortion correction on the two-dimensional code image according to the evaluation index of whether the possible boundary line is the real boundary line, and obtain the corrected two-dimensional code image;
[0041] Image decoding module: used to decode the corrected QR code image.
[0042] A fast decoding device for a scanner based on image technology comprises a scanner and a memory and a processor contained in the scanner, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements any step of the fast decoding method for a scanner based on image technology.
[0043] The beneficial effects of the technical solution of the present invention are: using the features of Hough line detection in Hough space and the ability of Hough line to represent the boundary of a two-dimensional code to obtain the possibility of Hough line as the boundary of a two-dimensional code, using the possibility as the selection criterion of Hough line to complete the selection of the boundary line of the two-dimensional code, using the intersection of Hough line to represent the vertex of the two-dimensional code image, and mapping the vertex to the vertex of the square to complete the distortion correction of the two-dimensional code image. The ability of Hough line to represent the boundary of the real two-dimensional code is improved, thereby improving the accuracy of distortion correction. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 A flowchart of the steps of the fast decoding method for a scanner based on image technology of the present invention;
[0046] Figure 2 It is a structural block diagram of a fast decoding system for a scanner based on image technology of the present invention;
[0047] Figure 3 It is a structural block diagram of a fast decoding device for a scanner based on image technology of the present invention;
[0048] Figure 4 It is a schematic diagram of the position characteristics of the image-seeking pattern of the present invention;
[0049] Figure 5 It is a schematic diagram of the projection line segments of the two-dimensional code outline image of the present invention on possible boundary lines. DETAILED DESCRIPTION
[0050] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the fast decoding method, system and device for scanners based on image technology proposed by the present invention, its specific implementation, structure, features and effects, in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0051] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0052] The specific scheme of the fast decoding method, system and device for a scanner based on image technology provided by the present invention is described in detail below with reference to the accompanying drawings.
[0053] See also Figure 1 , which shows a flowchart of a fast decoding method for a scanner based on image technology provided by an embodiment of the present invention, the method comprising the following steps:
[0054] Step S001: Acquire a two-dimensional code image and a plurality of image-finding patterns of the two-dimensional code image, pre-process the two-dimensional code image, and acquire a two-dimensional code contour image.
[0055] Specifically, in order to implement the fast decoding method for a scanner based on image technology proposed in this embodiment, it is first necessary to collect an image for fast decoding. The specific process is as follows:
[0056] A two-dimensional code image is acquired through a scanner, and grayscale processing is performed on the acquired two-dimensional code image to obtain a two-dimensional code grayscale image; the OTSU algorithm is used on the two-dimensional code grayscale image to obtain a two-dimensional code binary image, and a semantic segmentation algorithm is used to obtain several image-seeking graphics in the two-dimensional code image; the two-dimensional code binary image is eroded, and the area with the most pixels with a grayscale value of 0 is selected, and the contour image of the area is recorded as the two-dimensional code contour image.
[0057] It should be noted that the semantic segmentation algorithm is an existing method for classifying image pixels, so it is not described in detail in this embodiment.
[0058] It should be noted that the OTSU algorithm is an existing method for image threshold segmentation, so it is not described in detail in this embodiment.
[0059] It should be noted that the two-dimensional code image has position detection graphics, namely, image search graphics, positioning graphics, and correction graphics. Figure 4 shown.
[0060] So far, the two-dimensional code image and the two-dimensional code outline image are obtained through the above method.
[0061] Step S002: Perform straight line detection on the two-dimensional code contour image to obtain a possible boundary line, and obtain the possibility that the possible boundary line is a real boundary line based on the position difference between the corresponding data point of the possible boundary line and other data points in the Hough space during the straight line detection process; calculate the possibility correction factor that the possible boundary line is a real boundary line based on the positional relationship between the possible boundary line and the image-finding pattern and the difference in the number of pixel points on both sides of the possible boundary line; use the possibility correction factor that the possible boundary line is a real boundary line to adjust the possibility that the possible boundary line is a real boundary line, and obtain an evaluation index that the possible boundary line is a real boundary line.
[0062] It should be noted that the possibility of Hough lines as the boundaries of two-dimensional codes is obtained by utilizing the characteristics of Hough lines in Hough space and the ability of Hough lines to represent the boundaries of two-dimensional codes. The possibility is used as the selection criterion of Hough lines to complete the selection of two-dimensional code boundary lines. The intersection points of Hough lines are used to represent the vertices of the two-dimensional code image. The distortion correction of the two-dimensional code image is completed by mapping the vertices to the vertices of a square.
[0063] Specifically, in step 2.1, straight line detection is performed on the two-dimensional code contour image to obtain possible boundary lines, and according to the position difference between the corresponding data points of the possible boundary lines and other data points in the Hough space during the straight line detection process, the possibility that the possible boundary lines are the real boundary lines is obtained.
[0064] It should be noted that a common method for distortion correction of a QR code is to convert the correction of feature points into the correction of the entire QR code. Since the vertices of a QR code are easier to judge, the four vertices of the QR code are often used as feature points. By mapping these four feature points to the four vertices of a square, the transformation parameters of the QR code are obtained to complete the distortion correction. Obviously, the accuracy of distortion correction depends on the accuracy of parameter acquisition, and the accuracy of parameter acquisition depends on the accuracy of the judgment of the four vertices. However, the contour of the QR code is not a straight line, so it is necessary to obtain a straight line representing the QR code through the contour information. If the straight line is not selected correctly, it will lead to inaccurate judgment of the position of the QR code vertices, which will affect the correction of the QR code.
[0065] It should be noted that since Hough line detection relies on the feature that the contour pixels are represented by the same Hough line, the corresponding Hough line is obtained. However, the obtained contour is not the real boundary of the QR code. The point with the highest overlap in the Hough space cannot accurately represent the boundary of the QR code. Therefore, we cannot rely solely on the Hough line with the highest overlap as the real boundary line of the QR code. We need to correct the selection conditions of the Hough line.
[0066] It should be noted that, although the straight line representing the boundary of the QR code may not be the straight line with the largest number of pixels, the boundary of the QR code is affected by the image-finding pattern in the QR code image; on the other hand, the presentation of the image-finding pattern has a certain regionality, so that the Hough straight line obtained when the contour is actually detected by Hough line detection may have a certain degree of deviation due to the interference of the image-finding pattern, resulting in a certain difference between the obtained straight line parameters and the straight line parameters of the real boundary of the image QR code.
[0067] It should be noted that Hough line detection is an existing algorithm for line detection, and thus it is not described in detail in this embodiment.
[0068] Hough line detection is used to obtain possible boundary lines for the two-dimensional code contour image; any possible boundary line L is selected, and the data point corresponding to the possible boundary line L in the Hough space is obtained, which is recorded as the target data point; a rectangular neighborhood of size A×B is constructed with the target data point as the center, and the i-th data point in the rectangular neighborhood of the target data point is recorded as the neighborhood data point P of the target data point. Li ; Wherein A and B are the preset first parameter and the preset second parameter.
[0069] It should be noted that, based on experience, the preset first parameter A is set to 100, and the preset second parameter B is set to 20, which can be adjusted according to actual conditions and are not specifically limited in this embodiment.
[0070] The coordinates of the data points in the Hough space are used as the line parameters of the data points.
[0071] As an embodiment, a method for obtaining the possibility that any possible boundary line is a true boundary line is as follows:
[0072]
[0073] Among them, s(L) represents the possibility that the possible boundary line L is the true boundary line; SL i Represents the cumulative number of the i-th neighborhood data points of the target data point in Hough space; n LRepresents the cumulative number of target data points corresponding to the possible boundary line L in the Hough space; N L represents the sum of the cumulative number of all neighboring data points of the target data point corresponding to the possible boundary line L in the Hough space; p represents the line parameter of the target data point, p′ i represents the straight line parameter of the i-th neighborhood data point of the target data point; E() represents the mean function, and ‖ ‖ is the modulus operation.
[0074] It should be noted that Indicates the proportion of the cumulative number of the i-th neighboring data points of the target data point in the rectangular neighborhood in the entire rectangular neighborhood. The larger the proportion, the more contour pixels fall on the possible boundary line compared with the surrounding straight line parameters, so the possible boundary line is more likely to be the real boundary line; Represents the similarity between the straight line parameters, and uses the similarity as a weight to correct the possibility that the above possible boundary line is the true boundary line; It reflects the possibility that the characteristics of the straight line L in the rectangular neighborhood are the true boundary line. If the corresponding possibilities of the straight line parameters in the neighborhood are all large, the possibility that the boundary line L is the true boundary line is greater.
[0075] Step 2.2, based on the positional relationship between the possible boundary line and the image-finding pattern and the difference in the number of pixels on both sides of the possible boundary line, calculate the possibility correction factor that the possible boundary line is the true boundary line.
[0076] It should be noted that since the image-finding pattern of the two-dimensional code is also located on the boundary of the two-dimensional code, the features of the image-finding pattern are consistent, and the features of the image-finding patterns of different two-dimensional codes are the same. Therefore, the image-finding pattern can be used as the feature of the two-dimensional code, and the position relationship of the image-finding pattern in the two-dimensional code can also reflect the boundary information of the two-dimensional code.
[0077] It should be noted that the greater the overlap between the Hough line and the boundary pixel points of the image-finding pattern, the greater the possibility of indicating the boundary of the two-dimensional code; however, the two-dimensional code image obtained by the scanner may be distorted, which may also cause the image-finding pattern to be distorted, and the image-finding pattern is relatively small relative to the entire two-dimensional code image, which makes it inaccurate to use the overlap to describe the Hough line as the boundary of the two-dimensional code. For example, the following situation may occur: if the obtained Hough line is exactly on the boundary of the image-finding pattern, it has a large overlap, but due to the distortion of the image-finding pattern, the shape changes and the area is small, indicating that the number of boundary pixel points of the image-finding pattern is small, so the overlapping pixel points cannot accurately reflect the boundary characteristics of the entire two-dimensional code, and the slight change of the boundary pixel points of the image-finding pattern will cause a large change in the overlap degree of the Hough line, resulting in low accuracy.
[0078] For the possible boundary line L to be judged, obtain the set of pixels with gray value of 0 in each image-finding pattern, record it as the direction-finding pixel set, further obtain the pixels located at the edge of the image-finding pattern in the direction-finding pixel set, record it as the outer contour pixel points of the image-finding pattern, record the set formed by the outer contour pixel points of each image-finding pattern as the outer contour pixel point set of each image-finding pattern, obtain the pixels included in the possible boundary line L and the pixel points with the same coordinates as the pixel points in each outer contour pixel point set as the overlapping pixel points, and record the number of overlapping pixel points corresponding to the maximum number of overlapping pixel points between all outer contour pixel point sets as NS L .
[0079] It should be noted that the greater the degree of overlap between the Hough line and the outer contour pixel points of the image-finding pattern, the greater the possibility that the Hough line is the true boundary of the QR code; the greater the category difference on both sides of the Hough line, the greater the possibility that the Hough line is the true boundary of the QR code; the smaller the distance between the contour of the image-finding pattern and the Hough line, the greater the possibility that the Hough line is the true boundary of the QR code.
[0080] The extension line of the possible boundary line L divides the two-dimensional code binary image into two areas, recorded as area 1 and area 2, and obtains the number of pixels with grayscale value 0 in the two areas, recorded as the number of black pixels in area 1 and the number of black pixels in area 2. The number of black pixels in area 1 is subtracted from the number of black pixels in area 2 and the absolute value is taken, which is recorded as the difference in the number of black pixels of the possible boundary line L, recorded as δB L .
[0081] As an embodiment, a method for obtaining a probability correction factor of any possible boundary line being a true boundary line is as follows:
[0082]
[0083] Where t(L) represents the possibility correction factor that the possible boundary line L is the true boundary line; δB L represents the difference in the number of black pixels of the possible boundary line L; T L represents the length of the projected line segment of the two-dimensional code outline image on the possible boundary line L, CL represents the length of the possible boundary line L, and the length is the number of pixels included; NS L Indicates the maximum number of overlapping pixels between the possible boundary line L and the image search pattern; d L It represents the average shortest distance from the outer contour pixel points of the image-seeking figure to the possible boundary line L; norm() represents the normalization function.
[0084] It should be noted that Figure 5 Schematic diagram of the projection line segments of the QR code contour image on possible boundary lines.
[0085] Step 2.3, using the possibility correction factor of the possible boundary line being the true boundary line to adjust the possibility of the possible boundary line being the true boundary line, to obtain an evaluation index of whether the possible boundary line is the true boundary line.
[0086] As an embodiment, a method for obtaining an evaluation index of whether any possible boundary line is a true boundary line is:
[0087] S(L)=t(L)×s(L)
[0088] Among them, S(L) represents the evaluation index of the possible boundary line L being the true boundary line, t(L) represents the possibility correction factor of the possible boundary line L being the true boundary line, and s(L) represents the possibility of the possible boundary line L being the true boundary line.
[0089] At this point, the evaluation index of whether the possible boundary line is the real boundary line is obtained through the above method.
[0090] Step S003: performing distortion correction on the two-dimensional code image according to an evaluation index of whether the possible boundary line is a true boundary line, and obtaining a corrected two-dimensional code image.
[0091] Specifically, possible boundary lines in the two-dimensional code contour image are selected as M possible boundary lines with the largest evaluation index of the true boundary lines, and the line parameters of the M possible boundary lines are clustered by K-means with a K value of 4 to obtain four clusters, and the mean of the line parameters in each cluster is obtained, which is recorded as the line parameters of the Hough lines of the four boundaries of the two-dimensional code, and the Hough lines of the four boundaries are extended to obtain four intersection points, and the four intersection points are recorded as four vertices of the two-dimensional code, and the coordinates of the four vertices are recorded, where M is a preset parameter and M≥K.
[0092] It should be noted that the preset parameter M is set to 50 based on experience, and can be adjusted according to actual conditions, and is not specifically limited in this embodiment.
[0093] It should be noted that the K-means clustering algorithm is an existing algorithm for clustering data, so it is not described in detail in this embodiment.
[0094] A square is constructed, the coordinates of the four corners of the square are obtained, the coordinates of the four vertices and the coordinates of the four corners of the square are combined, and the two-dimensional code image is processed using affine transformation to obtain a corrected two-dimensional code image.
[0095] It should be noted that affine transformation is an existing algorithm for vector space transformation, so it is not described in detail in this embodiment.
[0096] At this point, the distortion-corrected two-dimensional code image is obtained through the above method.
[0097] Step S004: Decode the corrected two-dimensional code image.
[0098] Specifically, the position of the direction-finding image is determined again for the corrected QR code image to complete the positioning of the QR code, and the QRCodeDetector of OpenCV is used to decode the corrected QR code image; the error correction code and correction code generated by the QR code are used to complete the correction of the decoded information.
[0099] Through the above steps, the QR code is calibrated and decoded.
[0100] Second, see Figure 2 , which shows a fast decoding system for a scanner based on image technology provided by an embodiment of the present invention, the system includes the following modules:
[0101] Image processing module: used to obtain the two-dimensional code image and several image-seeking patterns of the two-dimensional code image, pre-process the two-dimensional code image, and obtain the two-dimensional code contour image;
[0102] Boundary determination module: used to perform straight line detection on the two-dimensional code contour image to obtain possible boundary lines, and obtain the possibility that the possible boundary line is the real boundary line according to the position difference between the corresponding data point of the possible boundary line and other data points in the Hough space during the straight line detection process; calculate the possibility correction factor that the possible boundary line is the real boundary line according to the position relationship between the possible boundary line and the image-finding pattern and the number difference of pixel points on both sides of the possible boundary line; use the possibility correction factor that the possible boundary line is the real boundary line to adjust the possibility that the possible boundary line is the real boundary line, and obtain the evaluation index that the possible boundary line is the real boundary line;
[0103] Distortion correction module: used to perform distortion correction on the two-dimensional code image according to the evaluation index of whether the possible boundary line is the real boundary line, and obtain the corrected two-dimensional code image;
[0104] Image decoding module: used to decode the corrected QR code image.
[0105] Third, see Figure 3The present invention also proposes a fast decoding device for a scanner based on image technology, which includes a scanner and a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method described in steps S001 to S004 are implemented.
[0106] This embodiment uses the features of Hough line detection in Hough space and the ability of Hough line to represent the boundary of a two-dimensional code to obtain the possibility of the Hough line as the boundary of a two-dimensional code, uses the possibility as the selection criterion of the Hough line to complete the selection of the boundary line of the two-dimensional code, uses the intersection of the Hough line to represent the vertices of the two-dimensional code image, and maps the vertices to the vertices of the square to complete the distortion correction of the two-dimensional code image. The ability of Hough line to represent the boundary of the real two-dimensional code is improved, thereby improving the accuracy of distortion correction.
[0107] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A fast decoding method for a scanner based on image technology, characterized in that: The method comprises the following steps: Acquire a two-dimensional code image and several image-finding patterns of the two-dimensional code image, pre-process the two-dimensional code image, and acquire a two-dimensional code contour image; Perform straight line detection on the two-dimensional code contour image to obtain a possible boundary line, and obtain the possibility that the possible boundary line is a real boundary line according to the position difference between the corresponding data point of the possible boundary line and other data points in the Hough space during the straight line detection process; calculate the possibility correction factor that the possible boundary line is a real boundary line according to the position relationship between the possible boundary line and the image-finding pattern and the number difference of pixel points on both sides of the possible boundary line; use the possibility correction factor that the possible boundary line is a real boundary line to adjust the possibility that the possible boundary line is a real boundary line, and obtain an evaluation index that the possible boundary line is a real boundary line; The two-dimensional code image is subjected to distortion correction according to an evaluation index that a possible boundary line is a true boundary line, and a corrected two-dimensional code image is obtained; Decoding the corrected two-dimensional code image; The method of performing straight line detection on the two-dimensional code contour image to obtain a possible boundary line and obtaining the possibility that the possible boundary line is a real boundary line according to the position difference between the corresponding data point and other data points of the possible boundary line in the Hough space during the straight line detection process includes the following specific methods: Use Hough line detection to get possible boundary lines for the QR code contour image; select any possible boundary line , get possible boundary lines The corresponding data point in Hough space is recorded as the target data point; the target data point is used as the center to construct The i-th data point in the rectangular neighborhood of the target data point is recorded as the neighborhood data point of the target data point. ; Wherein A and B are the preset first parameter and the preset second parameter; The coordinates of the data points in the Hough space are used as the line parameters of the data points; The method to obtain the possibility that any possible boundary line is the true boundary line is: ; in, Represents possible boundary lines The possibility of being a true boundary line; Represents the first target data point in Hough space The cumulative number of neighborhood data points; Represents possible boundary lines The cumulative number of corresponding target data points in Hough space; Represents possible boundary lines The sum of the cumulative number of all neighboring data points corresponding to the target data point in Hough space; represents the straight line parameters of the target data point, The target data point The straight line parameters of the neighboring data points; represents the mean function, To find the modulo operation; The possibility correction factor of the possible boundary line being the true boundary line is calculated based on the positional relationship between the possible boundary line and the image-finding pattern and the difference in the number of pixels on both sides of the possible boundary line, including the specific method of: Get the outer contour pixels and possible boundary lines of the image search pattern The maximum number of pixels that overlap with the image-seeking pattern; According to the possible boundary line The difference in the number of pixels on both sides to obtain the possible boundary line The difference in the number of black pixels; Place the QR code contour image on the possible boundary straight line Projection is performed on the QR code to obtain the projection line segment corresponding to the QR code contour image; The method for obtaining the possibility correction factor that any possible boundary line is a true boundary line is: ; in, Represents possible boundary lines is the possibility correction factor for the true boundary line; Represents possible boundary lines The difference in the number of black pixels; Indicates that the QR code contour image is on the possible boundary line The length of the projected line segment on Represents possible boundary lines The length of is the number of pixels included; Represents possible boundary lines The maximum number of pixels that overlap with the image-seeking pattern; Represents the outer contour pixel points of the image-finding image to the possible boundary line The average shortest distance; Represents the normalization function.
2. The fast decoding method for scanner based on image technology according to claim 1, characterized in that: The outer contour pixel points and possible boundary lines of the image-finding pattern are obtained. The maximum number of pixels that overlap with the image-seeking pattern. The specific method for obtaining it is: For the possible boundary line to be judged , obtain the set of pixels with gray value of 0 in each image-finding pattern, record it as the direction-finding pixel set, further obtain the pixels located at the edge of the image-finding pattern in the direction-finding pixel set, record it as the outer contour pixel points of the image-finding pattern, record the set of outer contour pixel points of each image-finding pattern as the outer contour pixel point set of each image-finding pattern, and obtain the possible boundary line The pixels contained in the set have the same coordinates as the pixels in each outer contour pixel set as the overlapping pixels. The number of overlapping pixels corresponding to the maximum number of overlapping pixels between all outer contour pixel sets is recorded as .
3. The fast decoding method for scanner based on image technology according to claim 1, characterized in that: The possible boundary line The specific method for obtaining the difference in the number of black pixels is as follows: Possible boundary line The extended line of divides the two-dimensional code binary image into two areas, recorded as area 1 and area 2, obtains the number of pixels with grayscale value 0 in the two areas, recorded as the number of black pixels in area 1 and the number of black pixels in area 2, subtracts the number of black pixels in area 1 from the number of black pixels in area 2 and takes the absolute value, recorded as the possible boundary line The difference in the number of black pixels is denoted as .
4. The fast decoding method for scanner based on image technology according to claim 1, characterized in that: The possibility correction factor of the possible boundary line being the true boundary line is used to adjust the possibility of the possible boundary line being the true boundary line to obtain the evaluation index of the possible boundary line being the true boundary line, including the specific method of: The method for obtaining the evaluation index of any possible boundary line as the true boundary line is: ; in, Indicates the evaluation index of whether the possible boundary line L is the true boundary line, Represents possible boundary lines is the possibility correction factor for the true boundary line, Represents possible boundary lines is the probability of being the true boundary line.
5. The fast decoding method for scanner based on image technology according to claim 1, characterized in that: The method of performing distortion correction on the two-dimensional code image according to the evaluation index of whether the possible boundary line is a true boundary line to obtain the corrected two-dimensional code image includes the following specific methods: The possible boundary lines in the two-dimensional code contour image are selected as the M possible boundary lines with the largest evaluation index of the true boundary lines, and the line parameters of the M possible boundary lines are clustered by K-means with a K value of 4 to obtain four clusters, and the mean of the line parameters in each cluster is obtained, which is recorded as the line parameters of the Hough lines of the four boundaries of the two-dimensional code, and the Hough lines of the four boundaries are extended to obtain four intersection points, and the four intersection points are recorded as the four vertices of the two-dimensional code, and the coordinates of the four vertices are recorded, where M is a preset parameter and ; A square is constructed, the coordinates of the four corners of the square are obtained, the coordinates of the four vertices and the coordinates of the four corners of the square are combined, and the two-dimensional code image is processed using affine transformation to obtain a corrected two-dimensional code image.
6. The fast decoding method for scanner based on image technology according to claim 1, characterized in that: The specific method of decoding the corrected two-dimensional code image includes: The position of the direction-finding image is determined again for the corrected QR code image to complete the positioning of the QR code, and the QRCodeDetector of OpenCV is used to decode the corrected QR code image; the error correction code and correction code generated by the QR code are used to complete the correction of the decoded information.
7. A fast decoding system for a scanner based on image technology, using a fast decoding method for a scanner based on image technology as claimed in any one of claims 1 to 6, characterized in that: The system includes the following modules: Image processing module: used to obtain the two-dimensional code image and several image-seeking patterns of the two-dimensional code image, pre-process the two-dimensional code image, and obtain the two-dimensional code contour image; Boundary determination module: used to perform straight line detection on the two-dimensional code contour image to obtain possible boundary lines, and obtain the possibility that the possible boundary line is the real boundary line according to the position difference between the corresponding data point of the possible boundary line and other data points in the Hough space during the straight line detection process; calculate the possibility correction factor that the possible boundary line is the real boundary line according to the position relationship between the possible boundary line and the image-finding pattern and the number difference of pixel points on both sides of the possible boundary line; use the possibility correction factor that the possible boundary line is the real boundary line to adjust the possibility that the possible boundary line is the real boundary line, and obtain the evaluation index that the possible boundary line is the real boundary line; Distortion correction module: used to perform distortion correction on the two-dimensional code image according to the evaluation index of whether the possible boundary line is the real boundary line, and obtain the corrected two-dimensional code image; Image decoding module: used to decode the corrected QR code image; The method of performing straight line detection on the two-dimensional code contour image to obtain a possible boundary line and obtaining the possibility that the possible boundary line is a real boundary line according to the position difference between the corresponding data point and other data points of the possible boundary line in the Hough space during the straight line detection process includes the following specific methods: Use Hough line detection to get possible boundary lines for the QR code contour image; select any possible boundary line , get possible boundary lines The corresponding data point in Hough space is recorded as the target data point; Build around the target data point The i-th data point in the rectangular neighborhood of the target data point is recorded as the neighborhood data point of the target data point. ; Wherein A and B are the preset first parameter and the preset second parameter; The coordinates of the data points in the Hough space are used as the line parameters of the data points; The method to obtain the possibility that any possible boundary line is the true boundary line is: ; in, Represents possible boundary lines The possibility of being a true boundary line; Represents the first target data point in Hough space The cumulative number of neighborhood data points; Represents possible boundary lines The cumulative number of corresponding target data points in Hough space; Represents possible boundary lines The sum of the cumulative number of all neighboring data points corresponding to the target data point in Hough space; represents the straight line parameters of the target data point, The target data point The straight line parameters of the neighboring data points; represents the mean function, To find the modulo operation; The possibility correction factor of the possible boundary line being the true boundary line is calculated based on the positional relationship between the possible boundary line and the image-finding pattern and the difference in the number of pixels on both sides of the possible boundary line, including the specific method of: Get the outer contour pixels and possible boundary lines of the image search pattern The maximum number of pixels that overlap with the image-seeking pattern; According to the possible boundary line The difference in the number of pixels on both sides to obtain the possible boundary line The difference in the number of black pixels; Place the QR code contour image on the possible boundary straight line Projection is performed on the QR code to obtain the projection line segment corresponding to the QR code contour image; The method for obtaining the possibility correction factor that any possible boundary line is a true boundary line is: ; in, Represents possible boundary lines is the possibility correction factor for the true boundary line; Represents possible boundary lines The difference in the number of black pixels; Indicates that the QR code contour image is on the possible boundary line The length of the projected line segment on Represents possible boundary lines The length of is the number of pixels included; Represents possible boundary lines The maximum number of pixels that overlap with the image-seeking pattern; Represents the outer contour pixel points of the image-finding image to the possible boundary line The average shortest distance; Represents the normalization function.
8. A fast decoding device for a scanner based on image technology, comprising a scanner, a memory contained in the scanner, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
