An image processing method for one-dimensional code recognition
Through the object detection model based on yolov5 and light equalization, noise reduction processing and correction technology, the problem of inaccurate one-dimensional code recognition in the electricity meter image is solved, and accurate decoding is achieved under different lighting and angles is achieved.
Patent Information
- Application Number
- CN202211226175.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-09
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2042-10-09
AI Technical Summary
The prior art In the electricity meter image, the first-dimensional code recognition is inaccurate due to lighting and shooting angles, making it difficult to accurately find and decode the information in the one-dimensional code.
The target detection model based on yolov5 is used to accurately locate the one-dimensional code position, combined with light equalization, noise reduction processing and correction processing, and light equalization and Gaussian filtering and noise reduction are performed on the electricity meter image through the neural network model, and then geometric transformation and decoding are performed.
It realizes accurate identification and accurate decoding of one-dimensional codes in various situations, reducing the impact of noise and improving the accuracy of identification.
Smart Images

Figure CN115578550B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of artificial intelligence and image processing, and in particular to an image processing method for one-dimensional code recognition. Background Art
[0002] With the revision and implementation of the 2009 functional and type specifications for State Grid's data collection terminals, smart meters, and user-generated master stations, and subsequent optimization and upgrades to versions 13 and 20, on-site data collection terminals, metering devices, and auxiliary facilities have become relatively mature and comprehensive. Currently, State Grid requires an annual on-site operational survey of metering devices owned by power supply companies. To facilitate meter data collection, each meter includes a unique, identifiable one-dimensional code to assist surveyors in registering their information. Surveyors simply scan the code on-site or capture an image of the meter containing the one-dimensional code.
[0003] In actual scenarios, the location of each household's electricity meter is not fixed. When census workers collect electricity meter information, the conventional method of identifying one-dimensional code information may not be able to accurately identify the one-dimensional code due to lighting, shooting or scanning angles, and may be subject to certain interference, making it difficult to accurately obtain the information contained in the one-dimensional code. Summary of the Invention
[0004] The purpose of the present invention is to provide an image processing method for one-dimensional code recognition to solve the following technical problems:
[0005] How to accurately find the corresponding one-dimensional code from the image taken of the electricity meter and accurately decode and identify the information in the one-dimensional code.
[0006] The purpose of the present invention can be achieved through the following technical solutions:
[0007] An image processing method for one-dimensional code recognition, comprising:
[0008] S1, obtaining the electric meter image data containing the target one-dimensional code;
[0009] S2, inputting the electricity meter image into a target detection model; the target detection model outputs the coordinate area of the target one-dimensional code in the electricity meter image;
[0010] S3, performing light equalization on the target one-dimensional code according to the coordinate region to obtain a first-stage code;
[0011] S4, performing noise reduction processing on the first stage code to obtain a second stage code;
[0012] S5, correcting the second stage code to obtain a third stage code;
[0013] S6, decoding the third stage code;
[0014] Wherein, the target detection model is a trained neural network model.
[0015] Through the above technical solution, the present invention is based on artificial intelligence technology. Through the target detection model based on yolov5, the position of the target one-dimensional code in the meter image data can be accurately located. Then, the image of the target one-dimensional code after identification and positioning is subjected to light equalization and noise reduction processing based on the Gaussian filtering principle, which can effectively reduce the subsequent situation where decoding cannot be performed due to excessive noise points; in addition, through correction processing, the matrix of the area where the target one-dimensional code is located is geometrically transformed to address the situation where the one-dimensional code cannot be decoded due to different shooting angles or scanning angles, and finally, it is achieved that while the one-dimensional code can be accurately identified, the requirements for accurate decoding and identification of the target one-dimensional code can be met in various situations.
[0016] As a further solution of the present invention: the light equalization includes:
[0017] Normalizing the image of the location area of the target one-dimensional code;
[0018] Performing histogram equalization on the normalized target one-dimensional code;
[0019] Converting the pixel values after histogram equalization into pixel values of the same grayscale as the original image to obtain the first stage code;
[0020] Wherein, the normalization includes:
[0021] s=T(r)
[0022]
[0023]
[0024] Wherein, D is the location area of the target one-dimensional code, r is the normalized grayscale value of the original image, and s is the grayscale value of the image after histogram equalization;
[0025] Where T(r) is a monotonically increasing function, 0≤r≤1, 0≤s≤1, 0≤T(r)≤1, r and s have a one-to-one correspondence; the distribution function of the random variable s is F s (s), p s (s) is the derivative of the distribution function.
[0026] As a further solution of the present invention: for p s (s)ds=p r (r)dr, when the normalized p s (s) = 1, then ds = p r Integrating both sides of (r)dr yields:
[0027]
[0028] When the transformation function T(r) is the cumulative distribution probability of the original image histogram, the histogram equalization is completed.
[0029] As a further solution of the present invention: the noise reduction processing includes:
[0030] Performing weighted averaging on the pixel values in the first-stage code, and for each pixel point value, it is obtained by weighted averaging its own value and other pixel values in the neighborhood;
[0031] Scanning each pixel in the image by sliding window convolution with a discretization window, and replacing the value of the pixel at the window center with the weighted average gray value of the pixels in the determined neighborhood.
[0032] As a further solution of the present invention: the correction processing includes:
[0033] Performing a regularization geometric transformation on the region image R included in the position region D;
[0034] Defining the region image R as a two-dimensional matrix I o ;
[0035] Let x and y be both single variables, and the number of bases of the low-dimensional linear subspace of the two-dimensional matrix I o is r I ;
[0036] If r I < k, where k is a preset positive integer, then the two-dimensional matrix I o is a texture with rank r I and is represented by an m*n matrix;
[0037] If the rank r of the two-dimensional matrix I o << min{m, n}, the rank r of the two-dimensional matrix I I is invariant under scale change and translation change, and it can be obtained that: o The rank r of I is invariant under scale change and translation change, and it can be obtained that:
[0038] g(x, y) = cI o (ax + t1, by + t2)
[0039] where the matrix g and the two-dimensional matrix I o have the same rank; G is the matrix after the g transformation, and two low-rank texture equivalences are obtained through scale and transform, that is, I o (x, y) ~ cI o(ax+t1,by+t2) holds, and the elements of this equivalence group have the following form:
[0040]
[0041] For the two-dimensional matrix I o After transformation and optimization processing, the third stage code is obtained.
[0042] As a further solution of the present invention: the transformation process includes:
[0043] I(x,y)=I o Γ -1 (x,y)
[0044] Γ represents a transformation group of rotational deformation, affine deformation or projection deformation, I(x, y) represents the deformed texture, and the matrix at different positions is transformed by the transformation group Γ to obtain the corrected matrix.
[0045] As a further solution of the present invention: the optimization process includes:
[0046] I=I o +E
[0047] Wherein, E is an error matrix. If the error amount in the regional image R is lower than a preset threshold, E is a sparse matrix, and the distortion caused by the transformation process is removed by comparing the corresponding pixel positions with the original image.
[0048] As a further solution of the present invention: the decoding process includes:
[0049] Shooting red light toward the white and black bars on the third-stage code;
[0050] Using the different reflectivity of the white and black stripes to the red light, different reflection intensities are obtained through a photoelectric sensor, which is converted into corresponding analog electrical signals, and then converted into digital signals of 0 or 1 after filtering and amplification;
[0051] Each digital signal consists of 7 black or white bars of unit width;
[0052] Scan from left to right to obtain the 11 numbers on the left, deduce the first prefix code according to the parity given by the preset coding table, and then scan the 11 data on the right to obtain a total of 22 data symbols to obtain the identification information of the target one-dimensional code.
[0053] As a further solution of the present invention: the training method of the target detection model includes:
[0054] Collecting a large amount of electricity meter image data of different sizes and resolutions in different scenarios;
[0055] Manually labeling all objects in the electricity meter image data using the Labelme image labeling tool;
[0056] Convert the Json files generated by Labelme annotation in batches into a data format that can be read by the model to be trained to form a training data set;
[0057] Based on the existing manually annotated data set, the training data set is expanded using a data enhancement method;
[0058] The expanded training data set is divided into training set and test set in a ratio of 9:1;
[0059] Create the model to be trained based on yolov5;
[0060] Input the labeled images in the training set into the to-be-trained model, and train a model file with the highest recognition accuracy under the input of the test set as the target detection model;
[0061] The data enhancement method includes image flipping, saturation adjustment and chroma adjustment;
[0062] The input of the target detection model is a single image, and the output is the image of the one-dimensional code area in the image and the coordinates of the one-dimensional code area in the original image.
[0063] Beneficial effects of the present invention:
[0064] The present invention is based on artificial intelligence technology. Through a target detection model based on YOLOv5, the position of the target one-dimensional code in the meter image data can be accurately located. Then, the image of the identified and located target one-dimensional code is subjected to light equalization and noise reduction processing based on the Gaussian filtering principle, which can effectively reduce the situation where subsequent decoding cannot be performed due to excessive noise points. In addition, through correction processing, the matrix of the area where the target one-dimensional code is located is geometrically transformed to address the situation where the one-dimensional code cannot be decoded due to different shooting angles or scanning angles. Ultimately, the present invention can achieve the goal of accurately identifying the one-dimensional code while meeting the requirements for accurate decoding and identification of the target one-dimensional code in various situations. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] The present invention will be further described below with reference to the accompanying drawings.
[0066] Figure 1 Schematic diagram of the flow of the image processing method for one-dimensional code recognition in the present invention;
[0067] Figure 2 Schematic diagram of the one-dimensional code in the present invention. DETAILED DESCRIPTION
[0068] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.
[0069] In the prior art, image processing methods for one-dimensional code recognition of electric meter images are mainly divided into the following categories:
[0070] The first category: one-dimensional code recognition method based on halcon.
[0071] One-dimensional code recognition can be seen as an image processing problem, which is expressed as how to locate the one-dimensional code area in an image containing a one-dimensional code and obtain the information represented by the one-dimensional code based on the width of the black and white bars in the area. Halcon uses the ROI segmentation method to recognize barcodes in a fixed area. This strategy is too rigid and lacks good compatibility and scalability.
[0072] The second category involves 1D code recognition based on OpenCV and Zbar. Zbar is trained using OpenCV's Cascade library, enabling detection capabilities. Combined with Zbar's native decoding capabilities, it can handle 1D code recognition. However, after analyzing and testing Zbar, we found that it cannot fully recognize 1D codes in varying brightness levels or from different shooting angles.
[0073] See also Figure 1 As shown, the present invention is an image processing method for one-dimensional code recognition, comprising:
[0074] S1, obtaining the electric meter image data containing the target one-dimensional code;
[0075] S2, inputting the electricity meter image into a target detection model; the target detection model outputs the coordinate area of the target one-dimensional code in the electricity meter image;
[0076] S3, performing light equalization on the target one-dimensional code according to the coordinate region to obtain a first-stage code;
[0077] S4, performing noise reduction processing on the first stage code to obtain a second stage code;
[0078] S5, correcting the second stage code to obtain a third stage code;
[0079] S6, decoding the third stage code;
[0080] Wherein, the target detection model is a trained neural network model.
[0081] The present invention is based on artificial intelligence technology. Through a target detection model based on YOLOv5, the position of the target one-dimensional code in the meter image data can be accurately located. Then, the image of the identified and located target one-dimensional code is subjected to light equalization and noise reduction processing based on the Gaussian filtering principle, which can effectively reduce the situation where subsequent decoding cannot be performed due to excessive noise points. In addition, through correction processing, the matrix of the area where the target one-dimensional code is located is geometrically transformed to address the situation where the one-dimensional code cannot be decoded due to different shooting angles or scanning angles. Ultimately, the present invention can achieve the goal of accurately identifying the one-dimensional code while meeting the requirements for accurate decoding and identification of the target one-dimensional code in various situations.
[0082] In this embodiment of the present invention, the training method of the target detection model includes:
[0083] By shooting videos containing electricity meters in different scenes, each frame containing the electricity meter is extracted from the video using frame extraction technology, and a large amount of electricity meter image data of different sizes and resolutions is collected;
[0084] Manually labeling all objects in the electricity meter image data using the Labelme image labeling tool;
[0085] Convert the Json files generated by Labelme annotation in batches into a data format that can be read by the model to be trained to form a training data set;
[0086] Based on the existing manually annotated data set, the training data set is expanded using a data augmentation method; wherein the data augmentation method includes image flipping, saturation adjustment, and hue adjustment;
[0087] The expanded training data set is divided into training set and test set in a ratio of 9:1;
[0088] Create the model to be trained based on yolov5;
[0089] The labeled images in the training set are input into the model to be trained, and the loss functions are confidence loss, positioning loss, and classification loss respectively, to complete the training process;
[0090] During the training process, the model file with the highest recognition accuracy under the test set input is selected as the target detection model;
[0091] The input of the target detection model is a single image, and the output is the image of the one-dimensional code area in the image and the coordinates of the one-dimensional code area in the original image.
[0092] As a further solution of the present invention: the light equalization includes:
[0093] Normalizing the image of the location area of the target one-dimensional code;
[0094] Performing histogram equalization on the normalized target one-dimensional code;
[0095] Converting the pixel values after histogram equalization into pixel values of the same grayscale as the original image to obtain the first stage code;
[0096] Wherein, the normalization includes:
[0097] s=T(r)
[0098] According to probability theory, if the probability density of a random variable r is known to be p r (r), random variable s is a function of r, then the probability density of s can be expressed by p r (r) Find, let the distribution function of random variable s be F s (s), p s (s) is the derivative of the distribution function; the distribution function is:
[0099]
[0100] Because the probability density function p s (s) is the derivative of the distribution function F s (s), taking the derivative of both sides of the above equation, we can get:
[0101]
[0102] Wherein, D is the location area of the target one-dimensional code, r is the normalized grayscale value of the original image, and s is the grayscale value of the image after histogram equalization;
[0103] Among them, in order to ensure that the order of the grayscale of the image from black to white remains unchanged after equalization, T(r) is a monotonically increasing function, and to ensure that the pixel grayscale value of the equalized image is within the allowable range, under the premise of 0≤r≤1, 0≤s≤1, 0≤T(r)≤1, r and s correspond one to one.
[0104] As a further solution of the present invention: for p s (s)ds=p r (r)dr, when the normalized p s (s) = 1, then ds = p r Integrating both sides of (r)dr yields:
[0105]
[0106] When the transformation function T(r) is the cumulative distribution probability of the original image histogram, the histogram equalization is completed. Then, the equalized pixel values are converted into pixel values with the same gray level as the original image to obtain the image area of the equalized target one-dimensional code.
[0107] As a further solution of the present invention: in order to remove the possible noise in the meter image data, the noise reduction processing includes:
[0108] Perform weighted averaging on the pixel values in the first-stage code. For the value of each pixel point, it is obtained by weighted averaging its own value and other pixel values in the neighborhood.
[0109] Scan each pixel in the image by sliding window convolution with a discretized window, and replace the value of the pixel at the center of the window with the weighted average gray value of the pixels in the determined neighborhood.
[0110] As a further solution of the present invention: the correction processing includes:
[0111] Perform a regularized geometric transformation on the regional image R included in the position region D;
[0112] Define the regional image R as a two-dimensional matrix I o ;
[0113] Let both x and y be single variables, and the number of bases of the low-dimensional linear subspace of the two-dimensional matrix I o is r I ;
[0114] If r I <k, where k is a preset positive integer, then the two-dimensional matrix I o is a texture with rank r I and is represented by an m*n matrix;
[0115] If the rank r of the two-dimensional matrix I o << min{m, n}, when the rank r of the two-dimensional matrix I I is invariant under scale change and translation change, it can be obtained that: o The rank r of I g(x,y) = cI
[0116] (ax + t1, by + t2) o
[0117] where the matrix g and the two-dimensional matrix I o have the same rank; G is the matrix after the transformation of g, and two low-rank texture equivalences are obtained through scale and transform, that is, I o (x, y) ~ cI o(ax+t1,by+t2) holds, and the elements of this equivalence group have the following form:
[0118]
[0119] For the two-dimensional matrix I o After transformation and optimization processing, the third stage code is obtained.
[0120] As a further solution of the present invention: the transformation process includes:
[0121] I(x,y)=I o Γ -1 (x,y)
[0122] Γ represents a transformation group of rotational deformation, affine deformation or projection deformation, I(x, y) represents the deformed texture, and the matrix at different positions is transformed by the transformation group Γ to obtain the corrected matrix.
[0123] As a further solution of the present invention: the optimization process includes:
[0124] I=I o +E
[0125] Wherein, E is an error matrix. If the error amount in the regional image R is lower than a preset threshold, E is a sparse matrix, and the distortion caused by the transformation process is removed by comparing the corresponding pixel positions with the original image.
[0126] As a further solution of the present invention: the decoding process includes:
[0127] Shooting red light toward the white and black bars on the third-stage code;
[0128] Using the different reflectivity of the white and black stripes to the red light, different reflection intensities are obtained through a photoelectric sensor, which is converted into corresponding analog electrical signals, and then converted into digital signals of 0 or 1 after filtering and amplification;
[0129] Each digital signal consists of 7 black or white bars of unit width;
[0130] like Figure 2 As shown, 11 numbers on the left are scanned from left to right, the first preamble code is deduced according to the parity given by the preset coding table, and then 11 data on the right are scanned to obtain a total of 22 data symbols to obtain the identification information of the target one-dimensional code.
[0131] The above is a detailed description of an embodiment of the present invention. However, the content described is only a preferred embodiment of the present invention and should not be considered to limit the scope of the present invention. All equivalent changes and improvements made within the scope of the present invention should still fall within the scope of the patent coverage of the present invention.
Claims
1. An image processing method for one-dimensional code recognition, characterized in that: include: S1, obtaining the electric meter image data containing the target one-dimensional code; S2, inputting the electricity meter image data into a target detection model; the target detection model outputs the coordinate area of the target one-dimensional code in the electricity meter image; S3, performing light equalization on the target one-dimensional code according to the coordinate region to obtain a first-stage code; The light equalization includes: Normalizing the image of the location area of the target one-dimensional code; Performing histogram equalization on the normalized target one-dimensional code; Converting the pixel values after histogram equalization into pixel values of the same grayscale as the original image to obtain the first stage code; S4, performing noise reduction processing on the first stage code to obtain a second stage code; S5, correcting the second stage code to obtain a third stage code; The correction process includes: Performing a regularized geometric transformation on the regional image R included in the location region D; The region image R is defined as a two-dimensional matrix ; Assume that x and y are both single variables, two-dimensional matrix The number of bases of the low-dimensional linear subspace is ; like , is a preset positive integer, then the two-dimensional matrix For the order The texture of The matrix is represented by If the two-dimensional matrix Rank When the two-dimensional matrix Rank It remains unchanged under scale and translation changes, and we can get: ; Among them, the matrix and the two-dimensional matrix Have the same rank; G is the matrix after g transformation, and the two low-rank textures obtained by scale and transform are equivalent to each other, that is, The elements of this equivalence group have the following form: ; For the two-dimensional matrix After performing transformation and optimization processing, the third stage code is obtained; S6, decoding the third stage code; the decoding process includes: Shooting red light toward the white and black bars on the third-stage code; Using the different reflectivity of the white and black stripes to the red light, different reflection intensities are obtained through a photoelectric sensor, which is converted into corresponding analog electrical signals, and then converted into digital signals of 0 or 1 after filtering and amplification; Each digital signal consists of 7 black or white bars of unit width; Scan from left to right to obtain the 11 numbers on the left, deduce the first prefix code according to the parity given by the preset coding table, and then scan the 11 data on the right to obtain a total of 22 data symbols to obtain the identification information of the target one-dimensional code; Wherein, the target detection model is a trained neural network model.
2. The image processing method for one-dimensional code recognition according to claim 1, characterized in that: in, The normalization includes: ; ; ; Wherein, D is the location area of the target one-dimensional code, r is the normalized grayscale value of the original image, and s is the grayscale value of the image after histogram equalization; in, is a monotonically increasing function, , , , r and s correspond one to one; the distribution function of the random variable s is , is the derivative of the distribution function.
3. The image processing method for one-dimensional code recognition according to claim 2, characterized in that: for , when normalized , then Integrating on both sides of , we can get: ; When the transformation function When is the cumulative distribution probability of the original image histogram, the histogram equalization is completed.
4. The image processing method for one-dimensional code recognition according to claim 3, characterized in that: The noise reduction process includes: Perform weighted averaging on the pixel values in the first stage code. The value of each pixel is obtained by weighted averaging its own value and the values of other pixels in its neighborhood. By using a discretized window sliding convolution to scan each pixel in the image, the weighted average grayscale value of the pixels in the determined neighborhood is used to replace the value of the pixel in the center of the window.
5. The image processing method for one-dimensional code recognition according to claim 1, characterized in that: The transformation process includes: ; A group of transformations that represent rotational, affine, or projective deformations, Represents the deformed texture, through the transformation group Transform the matrices at different positions to obtain the corrected matrices.
6. The image processing method for one-dimensional code recognition according to claim 5, characterized in that: The optimization process includes: ; in, is the error matrix. If the error amount in the regional image R is lower than the preset threshold, then It is a sparse matrix that removes the distortion caused by the transformation process by comparing the corresponding pixel positions with the original image.
7. The image processing method for one-dimensional code recognition according to claim 1, characterized in that: The training method of the target detection model includes: Collecting a large amount of electricity meter image data of different sizes and resolutions in different scenarios; Manually labeling all objects in the electricity meter image data using the Labelme image labeling tool; Convert the Json files generated by Labelme annotation in batches into a data format that can be read by the model to be trained to form a training data set; Based on the existing manually annotated data set, the training data set is expanded using a data enhancement method; The expanded training data set is divided into training set and test set in a ratio of 9:1; Create the model to be trained based on yolov5; Input the labeled images in the training set into the to-be-trained model, and train a model file with the highest recognition accuracy under the input of the test set as the target detection model; The data enhancement method includes image flipping, saturation adjustment and chroma adjustment; The input of the target detection model is a single image, and the output is the image of the one-dimensional code area in the image and the coordinates of the one-dimensional code area in the original image.
Citation Information
Patent Citations
One-dimensional code recognition algorithm based on self-adaptive edge detection and mapping model
CN105975894A
High-speed dimension code positioning identification system based on full convolutional neural network
CN110941970A