CN111311497B - Bar code image angle correction method and device - Google Patents
Bar code image angle correction method and device Download PDFInfo
- Publication number
- CN111311497B CN111311497B CN202010088727.5A CN202010088727A CN111311497B CN 111311497 B CN111311497 B CN 111311497B CN 202010088727 A CN202010088727 A CN 202010088727A CN 111311497 B CN111311497 B CN 111311497B
- Authority
- CN
- China
- Prior art keywords
- contour
- bar code
- foreground region
- white foreground
- code image
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000012937 correction Methods 0.000 title claims abstract description 60
- 238000000034 method Methods 0.000 title claims abstract description 43
- 238000012545 processing Methods 0.000 claims abstract description 43
- 230000009466 transformation Effects 0.000 claims abstract description 12
- 230000008569 process Effects 0.000 claims description 7
- 238000009792 diffusion process Methods 0.000 claims description 5
- 230000000694 effects Effects 0.000 abstract description 9
- 238000001514 detection method Methods 0.000 description 14
- 238000010845 search algorithm Methods 0.000 description 8
- 238000001914 filtration Methods 0.000 description 5
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 238000004891 communication Methods 0.000 description 2
- 238000010586 diagram Methods 0.000 description 2
- 230000002411 adverse Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003203 everyday effect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T3/00—Geometric image transformations in the plane of the image
- G06T3/60—Rotation of whole images or parts thereof
- G06T3/608—Rotation of whole images or parts thereof by skew deformation, e.g. two-pass or three-pass rotation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/136—Segmentation; Edge detection involving thresholding
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/187—Segmentation; Edge detection involving region growing; involving region merging; involving connected component labelling
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/60—Analysis of geometric attributes
- G06T7/62—Analysis of geometric attributes of area, perimeter, diameter or volume
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02A—TECHNOLOGIES FOR ADAPTATION TO CLIMATE CHANGE
- Y02A10/00—TECHNOLOGIES FOR ADAPTATION TO CLIMATE CHANGE at coastal zones; at river basins
- Y02A10/40—Controlling or monitoring, e.g. of flood or hurricane; Forecasting, e.g. risk assessment or mapping
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Geometry (AREA)
- Image Analysis (AREA)
Abstract
The application discloses a bar code image angle correction method and device, which are used for carrying out gray level and binarization processing on an obtained bar code image to be corrected to obtain a first binary image; performing contour retrieval on a white foreground region in the first binary image based on a contour retrieval algorithm to obtain a first contour; performing black filling on the white foreground region with the area smaller than the preset threshold value, and performing contour searching again to obtain a second contour; calculating a center of a second contour of the white foreground region based on the second contour; performing straight line fitting on the obtained central point based on Hough transformation, and outputting an included angle; the correction angle is calculated based on the included angle, and then the bar code image to be corrected is rotated to obtain the bar code image after correction, so that the technical problems that the existing bar code correction method can only correct the one-dimensional bar code by a small angle, the correction effect is poor under the condition that the angle of the bar code is serious, and the recognition result of the bar code is poor are solved.
Description
Technical Field
The application relates to the technical field of image processing, in particular to a bar code image angle correction method and device.
Background
The bar code is a symbol formed by black lines and blank arrangements with different thickness according to a certain coding rule. Bar codes are widely used in everyday life, such as merchandise and express slips. The existing one-dimensional bar code can be used for storing information such as numbers and letters, and the one-dimensional bar code only expresses the information in a single direction, so that the existing machine vision technology has requirements on the placement angle of the bar code when the one-dimensional bar code is identified, the angle of the bar code is usually required to be adjusted so as to be convenient for bar code identification, the existing bar code correction method can only carry out small-angle correction on the one-dimensional bar code, the correction effect is poor under the condition that the angle inclination of the bar code is serious, and the bar code identification result is poor.
Disclosure of Invention
The application provides a bar code image angle correction method and device, which are used for solving the technical problems that the existing bar code correction method can only carry out small-angle correction on a one-dimensional bar code, the correction effect is poor under the condition that the angle of the bar code is serious, and the recognition result of the bar code is poor.
In view of this, a first aspect of the present application provides a barcode image angle correction method, including:
carrying out graying treatment on the obtained bar code image to be corrected;
performing binarization processing on the bar code image to be corrected after the graying processing to obtain a first binary image;
performing contour retrieval on a white foreground region in the first binary image based on a contour retrieval algorithm to obtain a first contour of the white foreground region;
black filling is carried out on the white foreground region with the area smaller than a preset threshold value, a second binary image is obtained, and the area of the white foreground region is calculated based on the number of pixel points in a first outline of the white foreground region;
performing contour retrieval on a white foreground region in the second binary image based on a contour retrieval algorithm to obtain a second contour of the white foreground region;
calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region to obtain a plurality of center points;
performing straight line fitting on the center point based on Hough transformation, and outputting an included angle;
and calculating a correction angle based on the included angle, and rotating the bar code image to be corrected based on the correction angle to obtain a corrected bar code image.
Preferably, the binarizing process is performed on the barcode image to be corrected after the gray-scale process, so as to obtain a first binary image, and the method further includes:
and denoising the bar code image to be corrected after the graying treatment.
Preferably, the black filling is performed on the white foreground area with the area smaller than a preset threshold value to obtain a second binary image, which includes:
and black filling is carried out on the white foreground region with the area smaller than a preset threshold value according to a water-diffusion filling algorithm, so that a second binary image is obtained.
Preferably, the calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region, to obtain a plurality of center points includes:
obtaining four boundary points of a second contour based on the second contour of the white foreground region, wherein the four boundary points are four points of the uppermost point, the lowermost point, the leftmost point and the rightmost point;
and obtaining an external rectangle of the second contour based on the four boundary points, calculating the center of the external rectangle based on the external rectangle, and taking the center of the external rectangle as the center of the second contour to obtain a plurality of center points.
Preferably, the gray processing is performed on the obtained barcode image to be corrected, and the method further includes:
and acquiring the bar code image to be corrected.
A second aspect of the present application provides a bar code image angle correction device comprising:
the grey processing module is used for carrying out grey processing on the acquired bar code image to be corrected;
the binarization processing module is used for carrying out binarization processing on the bar code image to be corrected after the gray level processing to obtain a first binary image;
the first contour retrieval module is used for carrying out contour retrieval on a white foreground region in the first binary image based on a contour retrieval algorithm to obtain a first contour of the white foreground region;
the filling module is used for carrying out black filling on the white foreground region with the area smaller than a preset threshold value to obtain a second binary image, and the area of the white foreground region is calculated based on the number of pixel points in a first contour of the white foreground region;
the second contour retrieval module is used for carrying out contour retrieval on the white foreground region in the second binary image based on a contour retrieval algorithm to obtain a second contour of the white foreground region;
the calculating module is used for calculating the center of the second outline of the white foreground area based on the second outline of the white foreground area to obtain a plurality of center points;
the straight line fitting module is used for carrying out straight line fitting on the center point based on Hough transformation and outputting an included angle;
and the correction module is used for calculating a correction angle based on the included angle, and rotating the bar code image to be corrected based on the correction angle to obtain a corrected bar code image.
Preferably, the method further comprises:
and the denoising module is used for denoising the bar code image to be corrected after the graying processing.
Preferably, the filling module is specifically configured to:
and black filling is carried out on the white foreground region with the area smaller than a preset threshold value according to a water-diffusion filling algorithm, so that a second binary image is obtained.
Preferably, the computing module is specifically configured to:
obtaining four boundary points of a second contour based on the second contour of the white foreground region, wherein the four boundary points are four points of the uppermost point, the lowermost point, the leftmost point and the rightmost point;
and obtaining an external rectangle of the second contour based on the four boundary points, calculating the center of the external rectangle based on the external rectangle, and taking the center of the external rectangle as the center of the second contour to obtain a plurality of center points.
Preferably, the method further comprises:
and the image acquisition module is used for acquiring the bar code image to be corrected.
From the above technical scheme, the application has the following advantages:
the application provides a bar code image angle correction method, which comprises the following steps: carrying out graying treatment on the obtained bar code image to be corrected; performing binarization processing on the bar code image to be corrected after the graying processing to obtain a first binary image; performing contour retrieval on a white foreground region in the first binary image based on a contour retrieval algorithm to obtain a first contour of the white foreground region; black filling is carried out on a white foreground region with the area smaller than a preset threshold value, a second binary image is obtained, and the area of the white foreground region is calculated based on the number of pixel points in a first outline of the white foreground region; performing contour retrieval on the white foreground region in the second binary image based on a contour retrieval algorithm to obtain a second contour of the white foreground region; calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region to obtain a plurality of center points; performing straight line fitting on the center point based on Hough transformation, and outputting an included angle; and calculating a correction angle based on the included angle, and rotating the bar code image to be corrected based on the correction angle to obtain a corrected bar code image.
According to the bar code image angle correction method, gray level and binary processing are carried out on an obtained bar code image to be corrected, so that a first binary image is obtained; considering that other white foreground areas except the bar code can influence the detection of the direction straight line of the bar code, particularly the dense small-area white foreground areas, performing contour retrieval on the white foreground in the first binary image, and further performing black filling on the white foreground areas with the area smaller than a preset threshold value to obtain a second binary image, thereby achieving the effect of deleting the small-area white foreground areas and improving the detection accuracy of the direction straight line of the bar code; the method comprises the steps of carrying out contour retrieval on a white foreground region in a second binary image based on a contour retrieval algorithm, calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region to obtain a plurality of center points, carrying out straight line fitting on the center points by adopting Hough transformation to obtain a direction straight line and an included angle of a bar code, calculating a correction angle through the included angle, and correcting a bar code image, thereby solving the technical problems that the existing bar code correction method can only carry out small-angle correction on a one-dimensional bar code, the correction effect is poor under the condition that the inclination of the bar code angle is serious, and the bar code recognition result is poor.
Drawings
Fig. 1 is a schematic flow chart of a method for correcting an angle of a barcode image according to an embodiment of the present application;
FIG. 2 is a schematic flow chart of a method for correcting an angle of a bar code image according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of a bar code image angle correction device according to an embodiment of the present application;
fig. 4 is a schematic diagram of parameters in a polar coordinate system according to an embodiment of the present application.
Detailed Description
In order to make the present application solution better understood by those skilled in the art, the following description will clearly and completely describe the technical solution in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
For ease of understanding, referring to fig. 1, an embodiment of a method for correcting an angle of a barcode image provided in the present application includes:
and 101, carrying out gray processing on the acquired bar code image to be corrected.
The obtained barcode image to be corrected is subjected to gray-scale processing so as to facilitate subsequent binarization processing.
And 103, performing contour search on the white foreground region in the first binary image based on a contour search algorithm to obtain a first contour of the white foreground region.
And 104, black filling is carried out on a white foreground region with the area smaller than a preset threshold value, a second binary image is obtained, and the area of the white foreground region is calculated based on the number of pixel points in a first contour of the white foreground region.
It should be noted that, there is a large amount of white foreground in the obtained first binary image, and other white foreground areas except the bar code may affect the detection of the straight line of the bar code, especially the dense small-area white foreground areas, which not only affect the efficiency of the program operation, but also easily cause the error of straight line detection, so that it is required to reduce the small-area white foreground areas. In the embodiment of the application, the contour search is performed on the white foreground region in the first binary image through the contour search algorithm, so that the first contour of the white foreground region is obtained, after the first contour is obtained, the area of the white foreground region corresponding to each first contour can be obtained by calculating the number of pixel points in each first contour, the white foreground region with the area smaller than the preset threshold value is black filled, and the second binary image is obtained, so that the purpose of deleting the small-area white foreground region is achieved, the detection accuracy of the direction straight line of the bar code is improved, the contour search is performed on the white foreground region in the first binary image based on the contour search algorithm, and a specific process of the contour search based on the contour search algorithm is not repeated.
And 105, performing contour search on the white foreground region in the second binary image based on a contour search algorithm to obtain a second contour of the white foreground region.
And 106, calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region to obtain a plurality of center points.
Since the bars of the bar code are all equal-height bars and are aligned in the same direction, the straight line formed by connecting the center points of the bars is the straight line of the bar code, so that the center of the second outline of the white foreground area needs to be calculated to obtain the center point of each bar of the bar code.
And 107, performing straight line fitting on the center point based on Hough transformation, and outputting an included angle.
After obtaining a plurality of center points, a straight line detection algorithm may be used to detect a straight line and return a straight line with the best fitting degree. The principle of hough transform is to transform an image function expression from euclidean distance to parameter space, so as to realize fitting detection of a shape, in a rectangular coordinate system, a straight line can be expressed as y=ax+b, in a polar coordinate, the straight line can be expressed as ρ=xcos θ+ysin θ, ρ is a vertical distance from an origin to the straight line, and θ is an angle between a vertical line of the straight line and a clockwise direction of a transverse axis, as shown in fig. 4. When ρ is greater than 0, the straight line is below the origin; when ρ is greater than 0, the straight line is above the origin, and the included angle θ is less than 180 ° regardless of whether the straight line is above or below the origin, and therefore, (ρ; θ) can be used to represent any straight line. Straight line fitting is carried out on the center point by adopting Hough transformation, and the method specifically comprises the following steps: firstly, creating a 2-dimensional array as an accumulator, wherein rows and columns of the array respectively represent rho and theta, initializing values in the array by setting 0, and substituting x values and y values of a central point into a polar coordinate equation of a straight line; then traversing the theta values according to the precision, substituting the values into an equation to obtain corresponding rho values, so as to obtain a plurality of numerical value pairs (rho; theta), comparing the numerical value pairs with an accumulator, and if the accumulator can find the corresponding position, executing the 1 adding operation on the value of the corresponding position; and then taking a second center point, repeating the steps and updating the values in the accumulator until all the center points are taken, and outputting a value pair (rho; theta) corresponding to the maximum value in the accumulator after all the operations are executed, thereby obtaining the included angle theta.
And step 108, calculating a correction angle based on the included angle, and rotating the bar code image to be corrected based on the correction angle to obtain a corrected bar code image.
The correction angle can be obtained by subtracting the included angle θ from 90 °, and the bar code image to be corrected is rotated based on the correction angle, so as to obtain the corrected bar code image.
According to the bar code image angle correction method, gray scale and binarization processing are carried out on an obtained bar code image to be corrected, so that a first binary image is obtained; considering that other white foreground areas except the bar code can influence the detection of the direction straight line of the bar code, particularly the dense small-area white foreground areas, performing contour retrieval on the white foreground in the first binary image, and further performing black filling on the white foreground areas with the area smaller than a preset threshold value to obtain a second binary image, thereby achieving the effect of deleting the small-area white foreground areas and improving the detection accuracy of the direction straight line of the bar code; the method comprises the steps of carrying out contour retrieval on a white foreground region in a second binary image based on a contour retrieval algorithm, calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region to obtain a plurality of center points, carrying out straight line fitting on the center points by adopting Hough transformation to obtain a direction straight line and an included angle of a bar code, calculating a correction angle through the included angle, and correcting a bar code image, thereby solving the technical problems that the existing bar code correction method can only carry out small-angle correction on a one-dimensional bar code, the correction effect is poor under the condition that the inclination of the bar code angle is serious, and the bar code recognition result is poor.
For ease of understanding, referring to fig. 2, another embodiment of a method for correcting an angle of a barcode image provided in the present application includes:
It should be noted that, the barcode image to be corrected may be obtained through a camera, and the barcode image to be corrected is a color image.
And 202, carrying out graying treatment on the acquired bar code image to be corrected.
It should be noted that, the obtained barcode image to be corrected is subjected to graying processing so as to facilitate subsequent binarization processing, and in this embodiment of the present application, the graying processing is preferably performed by a weighted average method, that is:
f(x,y)=0.30R(x,y)+0.59G(x,y)+0.11B(x,y);
wherein R, G, B is three channels of a color image, and f is a gray image after the graying process.
And 203, denoising the bar code image to be corrected after the graying treatment.
It should be noted that, because noise has an adverse effect on the subsequent binarization processing, in the embodiment of the present application, denoising is performed on the barcode image to be corrected after the grayscale processing, the image may be smoothed by a filtering algorithm to achieve the denoising effect, and the commonly used filtering algorithm includes mean filtering, median filtering, gaussian filtering, and the like.
And 204, performing binarization processing on the bar code image to be corrected after denoising processing to obtain a first binary image.
It should be noted that, in the embodiment of the present application, a global binarization method is used to perform binarization processing on the denoised barcode image to be corrected, a segmentation threshold of a foreground target and a background in the barcode image to be corrected is defined as T, the size of the image is mxn, and the proportion of the number of pixels belonging to the foreground to all pixels of the whole image is ω 0 Corresponding to an average gray level of mu 0 The proportion of the background pixel points to all the pixel points of the whole image is omega 1 Corresponding to an average gray level of mu 1 The total average gray level of the image is mu, the inter-class variance is g, and the number of pixels with gray level value smaller than the threshold value T in the defined image is N 0 The number of pixels with the gray value larger than the threshold value T of the corresponding pixels is recorded as N 1 At this time, the definition is as follows:
μ=ω 0 ×μ 0 +ω 1 ×μ 1 ;
g=ω 0 (μ 0 -μ) 2 +ω 1 (μ 1 -μ) 2 ;
T=argmax(g);
and (3) taking the corresponding T as the threshold value when the g is the maximum value, and performing binarization processing on the denoised bar code image to be corrected according to the obtained threshold value T to obtain a first binary image.
And 206, performing black filling on the white foreground region with the area smaller than the preset threshold according to a water-flooding filling algorithm to obtain a second binary image, wherein the area of the white foreground region is calculated based on the number of pixel points in the first contour of the white foreground region.
It should be noted that, there is a large amount of white foreground in the obtained first binary image, and other white foreground areas except the bar code may affect the detection of the straight line of the bar code, especially the dense small-area white foreground areas, which not only affect the efficiency of the program operation, but also easily cause the error of straight line detection, so that it is required to reduce the small-area white foreground areas. In the embodiment of the application, the outline search algorithm is used for carrying out outline search on the white foreground region in the first binary image, so that the first outline of the white foreground region is obtained, after the first outline is obtained, the area of the white foreground region corresponding to each first outline can be obtained by calculating the number of pixel points in each first outline, black filling is carried out on the white foreground region with the area smaller than the preset threshold value according to the water-flooding filling algorithm, the purpose of deleting the small-area white foreground region is achieved, the detection accuracy of the direction straight line of the bar code is improved, the preset threshold value in the embodiment of the application is set to be 30, black filling is carried out based on the water-flooding filling algorithm, and the specific process of black filling by the water-flooding filling algorithm is not repeated.
It should be noted that, because the bar blocks of the bar code are all equal-height bar blocks and are aligned in the same direction, the straight line formed by connecting the center points of the bar blocks is the direction straight line of the bar code, so that the center of the second outline of the white foreground area needs to be calculated to obtain the center point of each bar block of the bar code, and the specific steps are as follows:
obtaining four boundary points of a second contour based on the second contour of the white foreground region, wherein the four boundary points are the four points of the uppermost point, the lowermost point, the leftmost point and the rightmost point;
obtaining an external rectangle of the second contour based on the four boundary points, obtaining the center of the external rectangle based on the external rectangle, taking the center of the external rectangle as the center of the second contour to obtain a plurality of center points, and black filling the positions of non-center points to obtain a center point image, wherein the coordinates of the center points of the external rectangle can be obtained by taking half of the length and width of the external rectangle as the coordinates.
And 209, performing straight line fitting on the center point based on Hough transformation, and outputting an included angle.
After obtaining a plurality of center points, a straight line detection algorithm may be used to detect a straight line and return a straight line with the best fitting degree. The principle of hough transform is to transform an image function expression from euclidean distance to parameter space, so as to realize fitting detection of a shape, in a rectangular coordinate system, a straight line can be expressed as y=ax+b, in a polar coordinate, the straight line can be expressed as ρ=xcos θ+ysin θ, ρ is a vertical distance from an origin to the straight line, and θ is an angle between a vertical line of the straight line and a clockwise direction of a transverse axis, as shown in fig. 4. When ρ is greater than 0, the straight line is below the origin; when ρ is greater than 0, the straight line is above the origin, and the included angle θ is less than 180 ° regardless of whether the straight line is above or below the origin, and therefore, (ρ; θ) can be used to represent any straight line. Straight line fitting is carried out on the center point by adopting Hough transformation, and the method specifically comprises the following steps: firstly, creating a 2-dimensional array as an accumulator, wherein rows and columns of the array respectively represent rho and theta, initializing values in the array by setting 0, and substituting x values and y values of a central point into a polar coordinate equation of a straight line; then traversing the theta values according to the precision, substituting the values into an equation to obtain corresponding rho values, so as to obtain a plurality of numerical value pairs (rho; theta), comparing the numerical value pairs with an accumulator, and if the accumulator can find the corresponding position, executing the 1 adding operation on the value of the corresponding position; and then taking a second center point, repeating the steps and updating the values in the accumulator until all the center points are taken, and outputting a value pair (rho; theta) corresponding to the maximum value in the accumulator after all the operations are executed, thereby obtaining the included angle theta.
And 210, calculating a correction angle based on the included angle, and rotating the bar code image to be corrected based on the correction angle to obtain a corrected bar code image.
The correction angle can be obtained by subtracting the included angle θ from 90 °, and the bar code image to be corrected is rotated based on the correction angle, so as to obtain the corrected bar code image.
For ease of understanding, referring to fig. 3, an embodiment of a barcode image angle correction device provided in the present application includes:
the graying processing module 301 is configured to perform graying processing on the obtained barcode image to be corrected.
The binarization processing module 302 is configured to perform binarization processing on the barcode image to be corrected after the gray level processing, so as to obtain a first binary image.
The first contour searching module 303 is configured to perform contour searching on the white foreground region in the first binary image based on a contour searching algorithm, so as to obtain a first contour of the white foreground region.
And the filling module 304 is configured to perform black filling on a white foreground area with an area smaller than a preset threshold value to obtain a second binary image, where the area of the white foreground area is calculated based on the number of pixel points in the first contour of the white foreground area.
The second contour searching module 305 is configured to perform contour searching on the white foreground region in the second binary image based on a contour searching algorithm, so as to obtain a second contour of the white foreground region.
The calculating module 306 is configured to calculate a center of the second contour of the white foreground region based on the second contour of the white foreground region, so as to obtain a plurality of center points.
And the straight line fitting module 307 is configured to perform straight line fitting on the center point based on hough transform, and output an included angle.
The correction module 308 is configured to calculate a correction angle based on the included angle, and rotate the barcode image to be corrected based on the correction angle, so as to obtain a corrected barcode image.
Further, the method further comprises the following steps:
and the denoising module 309 is configured to denoise the bar code image to be corrected after the graying process.
Further, the filling module 304 is specifically configured to:
and (3) black filling is carried out on the white foreground region with the area smaller than the preset threshold value according to the water-diffusion filling algorithm, so that a second binary image is obtained.
Further, the computing module 306 is specifically configured to:
obtaining four boundary points of a second contour based on the second contour of the white foreground region, wherein the four boundary points are the four points of the uppermost point, the lowermost point, the leftmost point and the rightmost point;
and obtaining an external rectangle of the second contour based on the four boundary points, obtaining the center of the external rectangle based on the calculation of the external rectangle, and taking the center of the external rectangle as the center of the second contour to obtain a plurality of center points.
Further, the method further comprises the following steps:
an image acquisition module 310, configured to acquire a barcode image to be corrected.
In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a storage medium, including several instructions to execute all or part of the steps of the methods described in the embodiments of the present application by a computer device (which may be a personal computer, a server, or a network device, etc.). And the aforementioned storage medium includes: u disk, mobile hard disk, read-Only Memory (ROM), random access Memory (Random Access Memory, RAM), magnetic disk or optical disk, etc.
The above embodiments are merely for illustrating the technical solution of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the corresponding technical solutions.
Claims (8)
1. A method for angle correction of a bar code image, comprising:
carrying out graying treatment on the obtained bar code image to be corrected;
performing binarization processing on the bar code image to be corrected after the graying processing to obtain a first binary image;
performing contour retrieval on a white foreground region in the first binary image based on a contour retrieval algorithm to obtain a first contour of the white foreground region;
black filling is carried out on the white foreground region with the area smaller than a preset threshold value, a second binary image is obtained, and the area of the white foreground region is calculated based on the number of pixel points in a first outline of the white foreground region;
performing contour retrieval on a white foreground region in the second binary image based on a contour retrieval algorithm to obtain a second contour of the white foreground region;
calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region to obtain a plurality of center points;
performing straight line fitting on the center point based on Hough transformation, and outputting an included angle;
calculating a correction angle based on the included angle, and rotating the bar code image to be corrected based on the correction angle to obtain a corrected bar code image;
calculating the center of the second contour of the white foreground region based on the second contour of the white foreground region to obtain a plurality of center points, including:
obtaining four boundary points of a second contour based on the second contour of the white foreground region, wherein the four boundary points are four points of the uppermost point, the lowermost point, the leftmost point and the rightmost point;
and obtaining an external rectangle of the second contour based on the four boundary points, calculating the center of the external rectangle based on the external rectangle, and taking the center of the external rectangle as the center of the second contour to obtain a plurality of center points.
2. The method for angle correction of a bar code image according to claim 1, wherein said binarizing the bar code image to be corrected after the graying process, to obtain a first binary image, further comprises:
and denoising the bar code image to be corrected after the graying treatment.
3. The method for correcting the angle of the bar code image according to claim 1, wherein the black filling is performed on the white foreground region with the area smaller than a preset threshold value to obtain a second binary image, comprising:
and black filling is carried out on the white foreground region with the area smaller than a preset threshold value according to a water-diffusion filling algorithm, so that a second binary image is obtained.
4. The method for angle correction of a bar code image according to claim 1, wherein said subjecting the obtained bar code image to be corrected to graying processing further comprises, before:
and acquiring the bar code image to be corrected.
5. A bar code image angle correction device, comprising:
the grey processing module is used for carrying out grey processing on the acquired bar code image to be corrected;
the binarization processing module is used for carrying out binarization processing on the bar code image to be corrected after the gray level processing to obtain a first binary image;
the first contour retrieval module is used for carrying out contour retrieval on a white foreground region in the first binary image based on a contour retrieval algorithm to obtain a first contour of the white foreground region;
the filling module is used for carrying out black filling on the white foreground region with the area smaller than a preset threshold value to obtain a second binary image, and the area of the white foreground region is calculated based on the number of pixel points in a first contour of the white foreground region;
the second contour retrieval module is used for carrying out contour retrieval on the white foreground region in the second binary image based on a contour retrieval algorithm to obtain a second contour of the white foreground region;
the calculating module is used for calculating the center of the second outline of the white foreground area based on the second outline of the white foreground area to obtain a plurality of center points;
the straight line fitting module is used for carrying out straight line fitting on the center point based on Hough transformation and outputting an included angle;
the correction module is used for calculating a correction angle based on the included angle, and rotating the bar code image to be corrected based on the correction angle to obtain a corrected bar code image;
the computing module is specifically configured to:
obtaining four boundary points of a second contour based on the second contour of the white foreground region, wherein the four boundary points are four points of the uppermost point, the lowermost point, the leftmost point and the rightmost point;
and obtaining an external rectangle of the second contour based on the four boundary points, calculating the center of the external rectangle based on the external rectangle, and taking the center of the external rectangle as the center of the second contour to obtain a plurality of center points.
6. The bar code image angle correction device of claim 5, further comprising:
and the denoising module is used for denoising the bar code image to be corrected after the graying processing.
7. The bar code image angle correction device of claim 5, wherein the filling module is specifically configured to:
and black filling is carried out on the white foreground region with the area smaller than a preset threshold value according to a water-diffusion filling algorithm, so that a second binary image is obtained.
8. The bar code image angle correction device of claim 5, further comprising:
and the image acquisition module is used for acquiring the bar code image to be corrected.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010088727.5A CN111311497B (en) | 2020-02-12 | 2020-02-12 | Bar code image angle correction method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010088727.5A CN111311497B (en) | 2020-02-12 | 2020-02-12 | Bar code image angle correction method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111311497A CN111311497A (en) | 2020-06-19 |
CN111311497B true CN111311497B (en) | 2023-05-05 |
Family
ID=71152804
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010088727.5A Active CN111311497B (en) | 2020-02-12 | 2020-02-12 | Bar code image angle correction method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111311497B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111768378A (en) * | 2020-06-29 | 2020-10-13 | 广东电网有限责任公司 | Crimping hardware tool live-line detection method and device |
CN113449536B (en) * | 2021-07-16 | 2023-02-14 | 深圳思谋信息科技有限公司 | Bar code image repairing method and device, computer equipment and storage medium |
CN116225270A (en) * | 2023-02-27 | 2023-06-06 | 荣耀终端有限公司 | Bar code image acquisition method and related device |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110309687A (en) * | 2019-07-05 | 2019-10-08 | 华中科技大学 | A kind of bearing calibration of image in 2 D code and means for correcting |
CN110348264A (en) * | 2019-07-04 | 2019-10-18 | 北京电子工程总体研究所 | A kind of QR image in 2 D code bearing calibration and system |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104517089B (en) * | 2013-09-29 | 2017-09-26 | 北大方正集团有限公司 | A kind of Quick Response Code decodes system and method |
-
2020
- 2020-02-12 CN CN202010088727.5A patent/CN111311497B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110348264A (en) * | 2019-07-04 | 2019-10-18 | 北京电子工程总体研究所 | A kind of QR image in 2 D code bearing calibration and system |
CN110309687A (en) * | 2019-07-05 | 2019-10-08 | 华中科技大学 | A kind of bearing calibration of image in 2 D code and means for correcting |
Also Published As
Publication number | Publication date |
---|---|
CN111311497A (en) | 2020-06-19 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111311497B (en) | Bar code image angle correction method and device | |
CN110866924B (en) | Line structured light center line extraction method and storage medium | |
CN107633192B (en) | Bar code segmentation and reading method based on machine vision under complex background | |
CN110348264B (en) | QR two-dimensional code image correction method and system | |
CN111340109B (en) | Image matching method, device, equipment and storage medium | |
CN111680690B (en) | Character recognition method and device | |
CN113466232B (en) | Brittle fish meat rapid detection method and system based on computer image | |
CN110136069B (en) | Text image correction method and device and electronic equipment | |
CN108197644A (en) | A kind of image-recognizing method and device | |
CN110660072B (en) | Method and device for identifying straight line edge, storage medium and electronic equipment | |
CN113177915B (en) | Tibial plateau back dip angle measuring method and device and storage medium | |
CN112580383B (en) | Two-dimensional code identification method and device, electronic equipment and storage medium | |
CN112183517B (en) | Card edge detection method, device and storage medium | |
CN115759148B (en) | Image processing method, device, computer equipment and computer readable storage medium | |
CN111783493A (en) | Identification method and identification terminal for batch two-dimensional codes | |
CN109784328B (en) | Method for positioning bar code, terminal and computer readable storage medium | |
CN106709393B (en) | QR two-dimensional code binarization method and system | |
CN114241463A (en) | Signature verification method and device, computer equipment and storage medium | |
CN112200789B (en) | Image recognition method and device, electronic equipment and storage medium | |
CN112435283A (en) | Image registration method, electronic device and computer-readable storage medium | |
CN111898408A (en) | Rapid face recognition method and device | |
CN107358138B (en) | Correction method of nonlinear distortion EAN bar code, mobile terminal and storage device | |
CN113643290B (en) | Straw counting method and device based on image processing and storage medium | |
CN113239738B (en) | Image blurring detection method and blurring detection device | |
CN110263597B (en) | Quick and accurate QR (quick response) code correction method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |