A DataMatrix QR code recognition method and system based on image coarse localization
By using image coarse localization preprocessing and adaptive grid partitioning methods, combined with local weighted regression and kernel density estimation algorithms, the problem of DM code recognition failure under wear, corrosion and background noise interference was solved, and effective recognition in complex scenes was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XIAMEN UNIV
- Filing Date
- 2023-06-27
- Publication Date
- 2026-05-26
AI Technical Summary
Existing technologies struggle to effectively identify DataMatrix QR codes affected by wear, corrosion, strong background noise, and geometric distortion, especially failing to identify them in industrial environments.
A coarse image localization method is adopted, which involves preprocessing, segmentation line acquisition, vertex coordinate calculation and grid gray value prediction, combined with local weighted regression and kernel density estimation algorithms, to adaptively divide the grid and perform binarization to extract barcode information.
This method effectively identifies DM codes in complex scenarios, solving the problems of recognition failure caused by wear, corrosion, background noise interference, and geometric distortion, and providing new ideas for subsequent DM code recognition methods.
Smart Images

Figure CN116842976B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and image recognition technology, and in particular to a DataMatrix QR code recognition method and system based on image coarse localization. Background Technology
[0002] DataMatrix QR codes (DM codes) are automatically readable barcodes based on combined coding principles and computer image processing technology (see Figure 1). They were invented by ID Matrix in 1989. Due to their advantages such as small size, large encoding capacity, strong error correction capability, and resistance to soiling, DM codes are particularly suitable for identifying small parts and are widely used in industrial components, circuits, pharmaceuticals, and other small items, as well as in manufacturing assembly line processes. However, due to limitations in practical application scenarios, the acquired DM code images often have the following problems (see Figures 2 and 3):
[0003] 1. The DM code has issues such as wear or corrosion;
[0004] 2. DM codes engraved on metal materials have strong background interference, such as pits and noise;
[0005] 3. The industrial production environment and photography conditions are poor, and the obtained DM code images often have problems such as geometric distortion.
[0006] Currently, Chinese patent document CN107301368A discloses a method for recognizing DM codes. This method involves calculating the coordinates of the virtual edges of the DM code, dividing it into a grid, and acquiring grid data by moving the obtained coordinates left and right and up and down. The resulting array of grid data is then decoded to obtain the final result. Furthermore, Chinese patent document CN113591506A discloses a robust DM code decoding method and system. This method proposes that for images captured under poor conditions, after determining the position of the virtual edge symbols, the center of the scanning grid is set as the center of the virtual edge symbols before performing the scanning decoding operation. However, these methods are difficult to apply to complex scenarios such as DM code edges being contaminated or damaged, DM code images exhibiting geometric distortion, strong background noise interference, and DM codes being blurred or worn.
[0007] Therefore, there is a need for an adaptive grid division method that, after coarsely locating the DM code image, determines the sampling grid without relying on virtual edges to cope with situations where the DM code edges are contaminated or damaged and the DM code image has geometric distortion; and a method that converts the barcode into a data matrix by analyzing the gray-level variation trend and gray-level distribution within the grid to cope with complex application scenarios where the DM code has strong background noise interference and is blurred or worn. Summary of the Invention
[0008] The main objective of this invention is to overcome the problems of existing technologies and propose a DataMatrix QR code recognition method and system based on image coarse localization. This method can effectively solve the problems of recognition failure in complex scenarios such as contaminated or damaged edges of DM code images, geometric distortion of DM code images, strong background noise interference of DM codes, and blurry or worn DM codes.
[0009] The present invention adopts the following technical solution:
[0010] On the one hand, a DataMatrix QR code recognition method based on image coarse localization is characterized by the following steps:
[0011] S1, preprocess the DM image of the DataMatrix QR code, and scale the image to a preset pixel space;
[0012] S2, Obtain the horizontal and vertical dividing lines of the DataMatrix QR code based on the preprocessed DM image;
[0013] S3, based on the horizontal and vertical dividing lines, calculate the coordinates of the four vertices of the grid formed by the intersection of the horizontal and vertical dividing lines of the DataMatrix QR code;
[0014] S4: Traverse the coordinates of the four vertices of each grid to obtain the grayscale change trend and grayscale distribution of each grid. Based on the grayscale change trend and grayscale distribution of each grid, predict the grayscale value of the grid. Binarize the grayscale value to obtain the predicted value.
[0015] S5 converts the predicted values into a data matrix, decodes it according to the encoding rules, and obtains the barcode information.
[0016] Preferably, S1 specifically includes:
[0017] Acquire DM images;
[0018] The pixel values of the three RGB channels in a DM color image are converted into grayscale values using a conversion formula.
[0019] Histogram equalization of grayscale values is performed using an adaptive histogram equalization algorithm that limits contrast.
[0020] Pixels that are close to each other and have similar gray values are filtered using a bilateral filtering method.
[0021] The OTSU algorithm automatically selects an optimal threshold based on the grayscale distribution characteristics of the image to binarize it.
[0022] The image is scaled to a preset pixel space using bilinear interpolation.
[0023] Preferably, S2 specifically includes:
[0024] The grayscale deviation values in the horizontal and vertical directions are calculated separately and accumulated in the vertical direction. The QR code is then converted into a one-dimensional waveform for analysis.
[0025] All peaks are identified using a second-order difference algorithm for peak and trough identification, and the existing horizontal and vertical dividing lines are obtained.
[0026] The predicted peak spacing is obtained by predicting the true peak spacing of the image based on the spacing of the obtained segmentation lines. The horizontal and vertical segmentation lines are grouped according to the predicted peak spacing, and the index corresponding to the maximum value in each group is used as the position of the segmentation line of the DataMatrix QR code.
[0027] Iterate through all the dividing lines and perform peak filling operations based on the predicted peak spacing.
[0028] Preferably, S3 specifically includes:
[0029] The number of horizontal and vertical dividing lines is determined separately.
[0030] If the number of dividing lines in the horizontal and vertical directions is even, the size of the bilateral filter function is increased by the preset value, and the dividing lines are re-acquired until the number of dividing lines in the horizontal and vertical directions is odd.
[0031] For a dividing line that meets the requirements, the coordinates of the left and right endpoints of each column grid and the coordinates of the top and bottom endpoints of each row grid are obtained through traversal operations. Then, the coordinates of the four vertices of the grid formed by the intersection of the horizontal and vertical dividing lines are calculated.
[0032] Preferably, S4 specifically includes:
[0033] Traverse the coordinates of the four vertices of each grid, and iteratively divide it by subtracting 2 from its length and width. Calculate the gray value of each unit pixel after each division until the length or width is less than or equal to 2 pixels, and obtain the gray value change trend of each grid from the outside to the center.
[0034] The gray values of the grid based on this gray value change trend are predicted by the local weighted regression algorithm, and then binarized, with 0 representing white and 1 representing black.
[0035] The gray values of individual pixels in the grid are analyzed using a kernel density estimation algorithm to predict the gray values of the grid and then binarize them.
[0036] If the gray values predicted by the local weighted regression algorithm and the kernel density estimation algorithm are the same, the prediction is considered correct; if they are different, the data point with the largest standard deviation is removed until the gray values predicted by the two algorithms are the same.
[0037] Preferably, after traversing the coordinates of the four vertices of each grid, the process further includes:
[0038] Iterate through the coordinates of the four vertices of each grid to obtain the length and width of that grid.
[0039] Create a zero matrix of the same size and data type as the preprocessed DM image as a mask array, and draw the current grid as white to fill the mask array;
[0040] The pixel values of the preprocessed DM image are sliced using a mask array, keeping only the pixels within the current grid, and the average value of the remaining pixels is calculated as the unit pixel gray value of the current grid.
[0041] Preferably, the grayscale value of the grid based on this grayscale change trend is predicted by a local weighted regression algorithm, and then binarized, specifically including:
[0042] For the list of unit pixel grayscale values segmented by each iteration of the grid, a nonparametric local weighted regression model is established to implement the local weighted regression algorithm, predict the grayscale value of the grid based on this grayscale change trend, and binarize it, with 0 representing white and 1 representing black.
[0043] Preferably, the grayscale value of each pixel in the grid is analyzed using a kernel density estimation algorithm to predict the grayscale value of the grid, and then binarized. Specifically, this includes:
[0044] For the list of unit pixel gray values segmented by each iteration of the grid, the grid gray values are predicted by the kernel density estimation algorithm based on the gray distribution of the grid. First, the list of unit pixel gray values segmented by each iteration of the grid is fitted with an appropriate bandwidth and Gaussian kernel function to generate a probability density function. Then, the probability density estimate of a given data point is calculated, and the data point corresponding to the maximum probability density estimate is found as the predicted gray value. The gray value is then binarized, with 0 representing white and 1 representing black.
[0045] On the other hand, a DataMatrix QR code recognition system based on image coarse localization includes:
[0046] The image preprocessing module is used to preprocess the DM image of the DataMatrix QR code, scaling the image to a preset pixel space.
[0047] The dividing line acquisition module is used to acquire the horizontal and vertical dividing lines of the DataMatrix QR code based on the preprocessed DM image;
[0048] The vertex coordinate calculation module is used to calculate the coordinates of the four vertices of the grid formed by the intersection of the horizontal and vertical dividing lines of the DataMatrix QR code, based on the horizontal and vertical dividing lines.
[0049] The prediction value acquisition module is used to traverse the coordinates of the four vertices of each grid, obtain the gray-level change trend and gray-level distribution of each grid, predict the gray-level value of each grid based on the gray-level change trend and gray-level distribution of each grid, and binarize the gray-level value to obtain the prediction value.
[0050] The barcode information acquisition module is used to convert the predicted values into a data matrix, decode it according to the encoding rules, and obtain the barcode information.
[0051] As can be seen from the above description of the present invention, compared with the prior art, the present invention has the following beneficial effects:
[0052] A DataMatrix QR code recognition method and system based on image coarse localization can effectively solve the problem of recognition failure in complex scenarios such as contaminated or damaged edges of DM code images, geometric distortion of DM code images, strong background noise interference of DM codes, and blurry or worn DM codes, providing new ideas for subsequent research on DM code recognition methods. Attached Figure Description
[0053] Figure 1 shows the DM code identifier; where (a) is the DM code identifier of a certain chip, (b) is the DM code cryopreservation tube of a certain biotechnology company, and (c) is the DM code identifier of Embodiment 1 of the present invention.
[0054] Figure 2 shows the DM code and contamination diagram of Embodiment 2 of the present invention; wherein, (a) represents the DM code, (b) represents manually adding contamination to the data area, and (c) represents manually adding contamination to the edge;
[0055] Figure 3 shows the DM code of Embodiment 3 of the present invention;
[0056] Figure 4 is a flowchart of the DataMatrix QR code recognition method based on image coarse localization according to an embodiment of the present invention;
[0057] Figure 5 shows the horizontal distribution of the DM code in Embodiment 2 of the present invention; wherein, (a) represents the horizontal grayscale distribution, (b) represents the horizontal grayscale distribution after binarization and baseline removal, and (c) represents the horizontal grayscale gradient.
[0058] Figure 6 is a vertical distribution diagram of the DM code in Embodiment 2 of the present invention; wherein, (a) represents the vertical grayscale distribution diagram, (b) represents the vertical grayscale distribution diagram after binarization and baseline removal, and (c) represents the vertical grayscale gradient diagram.
[0059] Figure 7 is a sampling grid division diagram of the DM code in Embodiment 2 of the present invention; wherein, (a) represents the sampling grid division of the original image in Embodiment 2, (b) represents the sampling grid division of the original image in Embodiment 2 (data area contamination), and (c) represents the sampling grid division of the original image in Embodiment 2 (edge contamination);
[0060] Figure 8 is a diagram of the sampling grid division after binarization according to an embodiment of the present invention; wherein, (a) represents the sampling grid division after binarization in Embodiment 1; (b) represents the sampling grid division after binarization in Embodiment 2; and (c) represents the sampling grid division after binarization in Embodiment 3.
[0061] Figure 9 shows the dotted DM code of Embodiment 4 of the present invention;
[0062] Figure 10 shows the trend of the average gray value of the grid under ideal conditions;
[0063] Figure 11 shows the trend of grayscale mean value change of some grids in the original image of Embodiment 1 of the present invention;
[0064] Figure 12 shows the trend of grayscale mean value change of some grids in the original image of Embodiment 2 of the present invention;
[0065] Figure 13 shows the trend of grayscale mean value change of some grids after binarization of the original image in Embodiment 2 of the present invention;
[0066] Figure 14 shows the trend of the average gray value of the grid after adding noise to the middle area of part of the grid in Embodiment 1 of the present invention.
[0067] Figure 15 shows data matrix visualization images according to embodiments of the present invention; wherein, (a) represents the data matrix visualization image of embodiment 1; (b) represents the data matrix visualization image of embodiment 2; (c) represents the data matrix visualization image of embodiment 3; and (d) represents the data matrix visualization image of embodiment 4.
[0068] Figure 16 is a structural block diagram of the DataMatrix QR code recognition system based on image coarse localization according to an embodiment of the present invention. Detailed Implementation
[0069] The present invention will be further illustrated below with reference to specific embodiments. It should be understood that these embodiments are for illustrative purposes only and are not intended to limit the scope of the invention. Furthermore, it should be understood that after reading the teachings of this invention, those skilled in the art can make various alterations or modifications to the invention, and these equivalent forms also fall within the scope defined by the appended claims.
[0070] Referring to Figure 4, this embodiment of a DataMatrix QR code recognition method based on image coarse localization includes the following steps.
[0071] S1 preprocesses the DM image of the DataMatrix QR code, scaling the image to a preset pixel space.
[0072] The specific implementation is as follows:
[0073] The process involves acquiring an image, converting the pixel values of the RGB channels in the color image to grayscale values using a conversion formula, performing histogram equalization in small local areas (e.g., dividing the image into 64 small regions of 8*8) using an adaptive histogram equalization algorithm with limited contrast, filtering only pixels that are close to each other and have similar grayscale values using a bilateral filtering method, binarizing the image by automatically selecting an optimal threshold based on the image's grayscale distribution characteristics using the OTSU algorithm, and scaling the image to a 1000*1000 pixel space using bilinear interpolation.
[0074] In this step, "close distance" can be understood as the spatial distance between pixels being close. The spatial distance between pixels is controlled by the spatial domain variance, which can be set to 75. "Similar grayscale values" can be understood as the difference in grayscale values between pixels in the image. The grayscale values between pixels in the image are controlled by the pixel value domain variance, which can be set to 75.
[0075] S2, obtain the horizontal and vertical dividing lines of the DataMatrix QR code based on the preprocessed DM image.
[0076] Specifically, the grayscale deviation values in the horizontal and vertical directions are calculated separately and accumulated in the vertical direction, converting the 2D barcode into a 1D waveform for analysis. A second-order difference algorithm for peak and trough identification is used to find all peaks and their corresponding possible dividing lines. Then, the actual peak spacing in the image is predicted based on the spacing of the obtained dividing lines. The dividing lines are grouped according to the predicted peak spacing, and the index corresponding to the maximum value in each group is used as the position of the dividing line in the DM code. Finally, all dividing lines are traversed, and peak filling is performed based on the predicted peak spacing to eliminate the influence of wear and contamination on the DM code. The specific implementation is as follows.
[0077] Step 2.1: Convert the preprocessed image into a grayscale matrix (GreyMatrix), which is 1000 rows and 1000 columns in size. Each element in the matrix represents the grayscale value of the corresponding pixel. Calculate the absolute value of the grayscale difference between each pixel and the pixel to its right. The rightmost pixel is then subtracted from 0 to obtain the grayscale difference matrix. Calculate the sum of each column of the grayscale difference matrix, denoted as ColumnSum, and use it as the vertical axis of the waveform. Analyze the two-dimensional barcode into a one-dimensional waveform to obtain the grayscale distribution of the DM code in the horizontal direction. Refer to Figure 5 for the horizontal grayscale distribution of the original image in Example 2. Calculate the absolute value of the grayscale difference between each pixel and the pixel below it. The bottommost pixel is then subtracted from 0 to obtain the grayscale difference matrix. Calculate the sum of each row of the grayscale difference matrix, denoted as RowSum, and use it as the vertical axis of the waveform. Analyze the two-dimensional barcode into a one-dimensional waveform to obtain the grayscale distribution of the DM code in the vertical direction. See Figure 6 for the vertical grayscale distribution of the original image of Example 2.
[0078] Step 2.2: For ColumnSum and RowSum, a baseline removal operation is first performed to remove meaningless noise and improve the accuracy of finding the segmentation line. Since the image has been scaled to a fixed pixel space of 1000*1000, the minimum module side length can be determined based on the maximum code system, and then a threshold can be set to remove the baseline. See Figure 5 for the horizontal grayscale distribution (after binarization and baseline removal) of Example 2 and Figure 6 for the vertical grayscale distribution (after binarization and baseline removal) of Example 2. Then, according to the peak-valley second-order difference recognition algorithm, the baseline-removed ColumnSum and RowSum are differentially analyzed, their signs are calculated, and then differentially analyzed again. The results are denoted as ColumnSumDiff2 and RowSumDiff2. The single peak in the waveform corresponds to a value of -2 for ColumnSumDiff2 and RowSumDiff2, and the trapezoidal peak in the waveform corresponds to a value of -1 for ColumnSumDiff2 and RowSumDiff2. See Figure 5 for the horizontal grayscale gradient diagram of Example 2 and Figure 6 for the vertical grayscale gradient diagram of Example 2.
[0079] Step 2.3: Predict the true peak spacing based on the peak spacing obtained in Step 2.2. Due to geometric distortion and wear blurring, many invalid peak spacings exist in the obtained peak spacings. To accurately predict a more realistic peak spacing, the following steps were taken: First, the peak spacings obtained in Step 2.2 were differentially analyzed to obtain the spacing between adjacent peaks. Then, the spacings between adjacent peaks were sorted from smallest to largest; smaller values are more likely to be error values caused by poor image quality, and the reliability of the peak spacing gradually increases from smallest to largest. Finally, based on the data characteristics of adjacent peak spacings, an exponentially weighted moving average model was used to predict the true peak spacing, thus obtaining the predicted peak spacing.
[0080] Step 2.4: Group the peak spacings obtained in Step 2.2 according to the predicted peak spacings. Because the original peak list may contain broken peaks due to noise and distortion, it's necessary to determine which peaks belong to the same group, and then select the peak with the largest peak value from each group to represent that group. The peak spacings obtained in Step 2.2 are subtracted to obtain the actual peak spacing. If the peak spacing is less than half of the predicted peak spacing, it is considered to be in the same group. If a group contains only one peak, it is directly taken as the true peak of that group; if a group contains multiple peaks with only one maximum peak value, the peak corresponding to this maximum peak value is the true peak of that group; if multiple peaks have the same maximum value, their average value is taken as the true peak of that group.
[0081] Step 2.5: Perform peak filling operation on the peak list obtained in Step 2.4 to eliminate the influence of DM code wear and contamination. Perform a difference operation on the peak list obtained in Step 2.4 to obtain the peak spacing. If the peak spacing is greater than twice the predicted peak spacing, a new peak needs to be inserted until the peak spacing is less than twice the predicted peak spacing. Due to a large amount of noise, the predicted peak spacing may actually be too small. Therefore, a certain weight is applied to compensate when inserting the peak spacing. In this embodiment, the insertion value is 1.2 times the predicted peak spacing.
[0082] S3, based on the horizontal and vertical dividing lines, calculate the coordinates of the four vertices of the grid formed by the intersection of the horizontal and vertical dividing lines of the DataMatrix QR code.
[0083] Specifically, the horizontal and vertical dividing lines of the DM code were obtained through S2. The number of dividing lines was assessed. If the number of horizontal and vertical dividing lines was even, the size of the bilateral filter function was increased, and the dividing lines were re-acquired. This process continued until the number of horizontal and vertical dividing lines was odd, at which point the next step was continued, or the filter size limit was exceeded, resulting in significant loss of edge and image detail information and recognition failure. For dividing lines that met the requirements, the coordinates of the left and right endpoints of each column and the top and bottom endpoints of each row were obtained through traversal operations, and the coordinates of the four vertices of each grid were calculated. This included:
[0084] Step 3.1: Determine the number of dividing lines. As the DM code structure indicates, the size of a QR code is always an even number of modules; therefore, the number of dividing lines should be odd. When the number of dividing lines is even, it indicates insufficient image preprocessing and significant noise in the image. In this case, the size of the bilateral filter (i.e., the neighborhood diameter of the pixels) will be increased to achieve better smoothing. The process continues until the number of dividing lines becomes odd, or the filter size limit is exceeded, resulting in significant loss of edge and image detail information and recognition failure. In this embodiment, the filter size is limited to a minimum of 5 and a maximum of 25.
[0085] Step 3.2: Traverse the horizontal and vertical dividing lines of the DM code to obtain the coordinates of the left and right endpoints of each column grid and store them in ColumnList; obtain the coordinates of the top and bottom endpoints of each row grid and store them in RowList; finally, traverse the top and bottom endpoint coordinates of each row grid and the left and right endpoint coordinates of each column grid to calculate the coordinates of the four vertices of each grid:
[0086] 2. The coordinates of the top-left vertex are LeftTop = (ColumnList[j][0], RowList[i][0]);
[0087] 3. The coordinates of the top right corner vertex are RightTop = (ColumnList[j][1], RowList[i][0]);
[0088] 3. The coordinates of the bottom left vertex are LeftBottom = (ColumnList[j][0], RowList[i][1]);
[0089] 4. The coordinates of the bottom right vertex are RightBottom = (GolumnList[j][1], RowList[i][1]);
[0090] Where i is the index of RowList and j is the index of ColumnList.
[0091] The effect of dividing the sampling grid using the above methods is shown in Figures 7 and 8.
[0092] Furthermore, as shown in Figure 9, by observing the characteristics of the dotted DM code dividing lines, it can be found that for dotted DM code images with good image quality, as long as the even-numbered rows and even-numbered columns of the grid are removed, the intervals formed by the dots can be removed, and the new sampling area formed by the remaining part is no different from the square module DM code.
[0093] S4: Traverse the coordinates of the four vertices of each grid to obtain the grayscale change trend and grayscale distribution of each grid. Based on the grayscale change trend and grayscale distribution of each grid, predict the grayscale value of the grid. Binarize the grayscale value to obtain the predicted value.
[0094] Specifically, the coordinates of the four vertices of each grid obtained by S3 are iterated, and the grid is divided by subtracting 2 from its length and width sequentially. The gray value of each unit pixel after each division is calculated until the length or width is less than or equal to 2 pixels, thus obtaining the gray value change trend of each grid from the outside to the center. The gray value of the grid based on this gray value change trend is predicted by the local weighted regression algorithm and binarized, with 0 representing white and 1 representing black. The gray value predicted by the local weighted regression algorithm is generally accurate, but to avoid large errors caused by noise points in the center of the grid, the gray value distribution of the grid is analyzed. The gray value of each unit pixel of the grid is analyzed by the kernel density estimation algorithm, and the gray value of the grid is predicted and binarized, with 0 representing white and 1 representing black. If the values obtained by the local weighted regression algorithm and the kernel density estimation algorithm are the same, the prediction is considered correct; if they are different, it is considered that there is large noise in the grid. The data points with the largest standard deviation are removed to eliminate the possible noise influence until the prediction values of the two algorithms are the same. Specifically, this includes:
[0095] Step 4.1: Traverse each grid obtained in S3, denoted as GridPoints for each grid, and obtain the coordinates of the four vertices of the grid to obtain the length and width of the grid, respectively:
[0096] GridLength = GridPoints[1][0] - GridPoints[0][0];
[0097] Grid width GridWidth = GridPoints[2][1] - GridPoints[0][1].
[0098] Next, a zero-matrix of the same size and data type as the preprocessed image is created as a mask array. The current grid points are drawn white and filled into the mask array. Then, the pixel values of the preprocessed image are sliced using the mask array, keeping only the pixels within the current grid. The average value of the remaining pixels is calculated, which is the grayscale value per unit pixel of the current grid. Finally, the grid is iteratively divided by decreasing its length and width by 2, resulting in a new grid. The length and width of the new grid are: GridLength -= 2; GridWidth -= 2. The coordinates of the four vertices of the new grid are:
[0099] 1.LeftTop=(GridPoints[0][0]+1,GridPoints[0][1]+1);
[0100] 2.RightTop=(GridPoints[1][0]-1,GridPoints[1][1]+1);
[0101] 3.LeftBottom=(GridPoints[2][0]+1,GridPoints[2][1]-1);
[0102] 4.RightBottom=(GridPoints[3][0]-1,GridPoints[3][1]-1);
[0103] The segmentation process continues until the length or width is less than or equal to 2, calculating the grayscale value per unit pixel of the new grid. This yields the grayscale variation trend of each grid from the periphery to the center, as shown in Figures 10 to 13. Figure 10 shows the average grayscale value variation trend of the grid under ideal conditions; Figure 11 shows the average grayscale value variation trend of some grids in the original image of Example 1; Figure 12 shows the average grayscale value variation trend of some grids in the original image of Example 2; and Figure 13 shows the average grayscale value variation trend of some grids after binarization of the original image of Example 2. Ideally, the grayscale value of black grids tends towards 0, and the grayscale value of white grids tends towards 255. If the original image is used to calculate the grayscale value, as shown in Figures 11 and 12, the grayscale trend is not obvious and is affected by noise. Therefore, the grayscale value per unit pixel is taken from the binarized image, as shown in Figure 13, where the variation trend is more obvious.
[0104] Step 4.2: For the list of unit pixel grayscale values from each grid iteration, the grayscale change trend of each grid from the periphery to the center is contracting. The closer the data points are, the higher their confidence level, i.e., the greater their weight. Therefore, the characteristic of the data model should be to assign higher weights to closer data points and lower weights to farther data points. This feature is consistent with the characteristics of the local weighted regression algorithm, which can be used for prediction. A nonparametric local weighted regression model is established to implement the local weighted regression algorithm, predicting the grayscale values of the grid based on this grayscale change trend, and binarizing them, where 0 represents white and 1 represents black. In the regression analysis, the independent variable is the number of grid divisions, and the dependent variable is the corresponding unit pixel grayscale value. The independent variable is specified as ordered discrete data, the least squares cross-validation method is specified for bandwidth selection, the Wang-Ryzin kernel function is specified for smoothing the input data, and the regression type is specified as local linear regression.
[0105] Step 4.3: The gray values predicted by the local weighted regression algorithm are generally accurate, but when noise appears in the center of the grid, a large error will occur. See Figure 14, which is a trend chart of the average gray value of the grid after adding noise to the middle area of part of the grid in Example 1.
[0106] Due to noise, data distribution can become irregular. Therefore, a kernel density estimation algorithm is proposed to analyze the grayscale distribution of the grid. Kernel density estimation does not require prior assumptions about the probability density function and does not restrict its shape, making it suitable for data without obvious distribution patterns. Furthermore, it uses the density of sample data to approximate the density distribution of unknown data, offering significant advantages for data that cannot be described by known probability distributions. Therefore, based on the grayscale distribution of the grid, the kernel density estimation algorithm is used to predict the grayscale values. First, a suitable bandwidth and Gaussian kernel function are used to fit the list of unit pixel grayscale values from each iteration of grid segmentation, generating a probability density function. Then, the probability density estimate for a given data point is calculated, and the data point corresponding to the maximum probability density estimate is found, which is the most likely grayscale value. This value is then binarized, with 0 representing white and 1 representing black.
[0107] Step 4.4: Compare the gray values predicted by the local weighted regression algorithm with those predicted by the kernel density estimation algorithm for each grid. If the predicted values are equal, the predictions are considered accurate; if the predicted values are not equal, the predictions are considered inaccurate, and the grid contains significant noise. The grid needs to be removed from the list of unit pixel gray values obtained after each iteration of segmentation, as the points most likely to be noise, before re-evaluation. The specific steps for noise removal are as follows:
[0108] Step 4.4.1: Calculate the mean and standard deviation of the list of unit pixel gray values obtained after each iteration of grid segmentation, and denote the mean as GreyMean and the standard deviation as GreyStd. Standardize the list of unit pixel gray values. The standardized value represents the position of the data point relative to the entire list of unit pixel gray values, also known as the standard score. The standard score represents the relative position of the data point with respect to the entire dataset. Its value can be used to determine whether the data point deviates from the center of the dataset. The calculation formula is as follows:
[0109]
[0110] Where GreyScores is the standard score of the gray value per unit pixel, Grey i GreyMean is the grayscale value of the current unit pixel, GreyMean is the average value of the list of grayscale values of the current unit pixel, and GreyStd is the standard deviation of the list of grayscale values of the current unit pixel.
[0111] Step 4.4.2: Delete the point with the largest standard score from the list of unit pixel gray values, then recalculate the predicted value of the grid using steps 4.2 and 4.3 and compare them. If they are different, repeat the above steps until the predicted values are equal.
[0112] S5 converts the predicted values into a data matrix, decodes it according to the encoding rules, and obtains the barcode information.
[0113] The identification results of Embodiment 1 and Embodiment 2 using this identification method are “F0010011” and “F0010150”, respectively.
[0114] The data matrix visualization images of Examples 1, 2, 3, and 4 are shown in Figure 15.
[0115] Referring to Figure 16, according to another aspect of the present invention, this embodiment also provides a DataMatrix QR code recognition system based on image coarse localization, comprising:
[0116] The image preprocessing module 1601 is used to preprocess the DM image of the DataMatrix QR code and scale the image to a preset size pixel space.
[0117] The dividing line acquisition module 1602 is used to acquire the horizontal and vertical dividing lines of the DataMatrix QR code based on the preprocessed DM image;
[0118] The vertex coordinate calculation module 1603 is used to calculate the coordinates of the four vertices of the grid formed by the intersection of the horizontal and vertical dividing lines of the DataMatrix QR code, based on the horizontal and vertical dividing lines.
[0119] The prediction value acquisition module 1604 is used to traverse the coordinates of the four vertices of each grid, obtain the gray-scale change trend and gray-scale distribution of each grid, predict the gray-scale value of each grid based on the gray-scale change trend and gray-scale distribution of each grid, and binarize the gray-scale value to obtain the prediction value.
[0120] The barcode information acquisition module 1605 is used to convert the predicted value into a data matrix, decode it according to the encoding rules, and obtain barcode information.
[0121] The specific details of each module of the DataMatrix QR code recognition system based on image coarse localization are the same as the DataMatrix QR code recognition method based on image coarse localization, and will not be repeated in this embodiment.
[0122] The above are merely specific embodiments of the present invention, but the design concept of the present invention is not limited thereto. Any non-substantial modifications made to the present invention using this concept shall be considered as infringing upon the protection scope of the present invention.
Claims
1. A method for recognizing QR codes based on DataMatrix after coarse image localization, characterized in that, Includes the following steps: S1, preprocess the DM image of the DataMatrix QR code, and scale the image to a preset pixel space; S2, Obtain the horizontal and vertical dividing lines of the DataMatrix QR code based on the preprocessed DM image; S3, based on the horizontal and vertical dividing lines, calculate the coordinates of the four vertices of the grid formed by the intersection of the horizontal and vertical dividing lines of the DataMatrix QR code; S4: Traverse the coordinates of the four vertices of each grid to obtain the grayscale change trend and grayscale distribution of each grid. Based on the grayscale change trend and grayscale distribution of each grid, predict the grayscale value of the grid. Binarize the grayscale value to obtain the predicted value. S5, convert the predicted values into a data matrix, decode it according to the encoding rules, and obtain the barcode information; S3 specifically includes: The number of horizontal and vertical dividing lines is determined separately. If the number of dividing lines in the horizontal and vertical directions is even, the size of the bilateral filter function is increased by the preset value, and the dividing lines are re-acquired until the number of dividing lines in the horizontal and vertical directions is odd. For a dividing line that meets the requirements, the coordinates of the left and right endpoints of each column grid and the coordinates of the top and bottom endpoints of each row grid are obtained through traversal operations. Then, the coordinates of the four vertices of the grid formed by the intersection of the horizontal dividing line and the vertical dividing line are calculated. S4 specifically includes: Traverse the coordinates of the four vertices of each grid, and iteratively divide it by subtracting 2 from its length and width. Calculate the gray value of each unit pixel after each division until the length or width is less than or equal to 2 pixels, and obtain the gray value change trend of each grid from the outside to the center. The gray values of the grid based on this gray value change trend are predicted by the local weighted regression algorithm, and then binarized, with 0 representing white and 1 representing black. The gray values of individual pixels in the grid are analyzed using a kernel density estimation algorithm to predict the gray values of the grid and then binarize them. If the gray values predicted by the local weighted regression algorithm and the kernel density estimation algorithm are the same, the prediction is considered correct; if they are different, the data point with the largest standard deviation is removed until the gray values predicted by the two algorithms are the same.
2. The DataMatrix QR code recognition method based on image coarse localization as described in claim 1, characterized in that, S1 specifically includes: Acquire DM images; The pixel values of the three RGB channels in a DM color image are converted into grayscale values using a conversion formula. Histogram equalization of grayscale values is performed using an adaptive histogram equalization algorithm that limits contrast. Pixels that are close to each other and have similar gray values are filtered using a bilateral filtering method. The OTSU algorithm automatically selects an optimal threshold based on the grayscale distribution characteristics of the image to binarize it. The image is scaled to a preset pixel space using bilinear interpolation.
3. The DataMatrix QR code recognition method based on image coarse localization according to claim 1, characterized in that, S2 specifically includes: The grayscale deviation values in the horizontal and vertical directions are calculated separately and accumulated in the vertical direction. The QR code is then converted into a one-dimensional waveform for analysis. All peaks are identified using a second-order difference algorithm for peak and trough identification, and the existing horizontal and vertical dividing lines are obtained. The predicted peak spacing is obtained by predicting the true peak spacing of the image based on the spacing of the obtained segmentation lines. The horizontal and vertical segmentation lines are grouped according to the predicted peak spacing, and the index corresponding to the maximum value in each group is used as the position of the segmentation line of the DataMatrix QR code. Iterate through all the dividing lines and perform peak filling operations based on the predicted peak spacing.
4. The DataMatrix QR code recognition method based on coarse image localization according to claim 1, characterized in that, After traversing the coordinates of the four vertices of each grid, the process also includes: Iterate through the coordinates of the four vertices of each grid to obtain the length and width of that grid. Create a zero matrix of the same size and data type as the preprocessed DM image as a mask array, and draw the current grid as white to fill the mask array; The pixel values of the preprocessed DM image are sliced using a mask array, keeping only the pixels within the current grid, and the average value of the remaining pixels is calculated as the unit pixel gray value of the current grid.
5. The DataMatrix QR code recognition method based on image coarse localization according to claim 1, characterized in that, The local weighted regression algorithm is used to predict the grayscale value of the grid based on this grayscale change trend, and then binarize it. Specifically, this includes: For the list of unit pixel grayscale values segmented by each iteration of the grid, a nonparametric local weighted regression model is established to implement the local weighted regression algorithm, predict the grayscale value of the grid based on this grayscale change trend, and binarize it, with 0 representing white and 1 representing black.
6. The DataMatrix QR code recognition method based on image coarse localization according to claim 1, characterized in that, The grayscale values of individual pixels in the grid are analyzed using a kernel density estimation algorithm to predict the grayscale values of the grid cells, and then binarized. Specifically, this includes: For the list of unit pixel gray values segmented by each iteration of the grid, the grid gray values are predicted by the kernel density estimation algorithm based on the gray distribution of the grid. First, the list of unit pixel gray values segmented by each iteration of the grid is fitted with an appropriate bandwidth and Gaussian kernel function to generate a probability density function. Then, the probability density estimate of a given data point is calculated, and the data point corresponding to the maximum probability density estimate is found as the predicted gray value. The gray value is then binarized, with 0 representing white and 1 representing black.
7. A DataMatrix QR code recognition system based on image coarse localization, characterized in that, For implementing the method as described in any one of claims 1 to 6, comprising: The image preprocessing module is used to preprocess the DM image of the DataMatrix QR code, scaling the image to a preset pixel space. The dividing line acquisition module is used to acquire the horizontal and vertical dividing lines of the DataMatrix QR code based on the preprocessed DM image; The vertex coordinate calculation module is used to calculate the coordinates of the four vertices of the grid formed by the intersection of the horizontal and vertical dividing lines of the DataMatrix QR code, based on the horizontal and vertical dividing lines. The prediction value acquisition module is used to traverse the coordinates of the four vertices of each grid, obtain the gray-level change trend and gray-level distribution of each grid, predict the gray-level value of each grid based on the gray-level change trend and gray-level distribution of each grid, and binarize the gray-level value to obtain the prediction value. The barcode information acquisition module is used to convert the predicted values into a data matrix, decode it according to the encoding rules, and obtain the barcode information.