A kind of multiple barcode localization method
Technical field
The present invention relates to the field of image processings such as the positioning of bar codes multiple in image, cutting, angle rotation, more particularly to
A kind of multiple barcode localization method.
Background technique
In today that logistic industry rapidly develops, the design of express delivery list has obtained different degrees of change according to various demands
Into but due to there is no national standard, causing the pattern of the express delivery list of every logistics company different, and specification has very big to go out
Enter, including the difference of barcode position, Aspect Ratio is different and Barcode Length is different.
Image processing techniques began to be applied from the 1950s, had been deep into daily life till now
Every aspect.Image technique content very abundant, including image acquisition, image compression, image storage and transmission, image
Transformation, image synthesis, image enhancement, image restoration and reconstruction, image segmentation, target detection, image indicate to match with description, image
Quasi-, image classification and identification, image understanding, scene analysis and understanding, the foundation of image data base, index and retrieval and synthesis
It utilizes.In field of image recognition, the orientation problem for target is always the emphasis in identification problem, and accurately positioning can
To effectively improve recognition efficiency.Framing algorithm is then the area for positioning bar code by all means in the picture at present
Domain, to cooperate subsequent algorithm to achieve the purpose that identify contained content in image.It must in almost all problem of image recognition
The problem of so encountering, the solution of the problem then need to divide identification object, and the wherein identification of text class is then
Recent big heat discusses object.It is studied according to the geometry of identified object or wave character, to obtain object
Feature, that is, the basic procedure of pattern-recognition.The completion of positioning is to have obtained the performance of target object feature, so positioning
Also it just needs to study target signature.
Detection for bar code, it is natural that positioning, which is that basis is also important step the most, to be realized to bar code, to bar shaped
The automatic detection of code is to realize the most important thing of bar code identification system.Research of the domestic many experts and scholars for bar code
It is more and more deep, many effective detection methods are proposed, for example carry out analyzing and positioning by the textural characteristics in image, again
The detection after frequency domain variation is either carried out, there are also Mathematical Morphology Method, gradient algorithm is used, is also had by dividing image
The method for being cut into boxed area to detect.Although there are many algorithms to be able to carry out a degree of detection and localization, or
Mostly or less still there are some problems.Substantially show following several aspects: algorithm first is easy under more complicated background
It is mixed with background generation, it is not easy to distinguish;Another is exactly that many algorithms can not complete multiple bar shapeds in a width picture
The detection of code.
Summary of the invention
The purpose of the present invention is to provide a kind of multiple barcode localization methods.The present invention to have the image of multiple bar codes into
Row edge detection, to obtain the region of rectangle by Edge Search, and the sequence of the edge data by judging rectangle obtains institute
The multiple the barcode size or text fields needed realize bar code positioning.The present invention is same by the carry out to multiple bar codes in an image
When identification come speed up processing.
The purpose of the present invention can be achieved through the following technical solutions:
A kind of multiple barcode localization method, specific steps include:
(1) image detected is pre-processed, obtains binary image;
(2) edge detection is carried out to the boundary rectangle in binary image, obtains the position of multiple rectangles;
(3) judged by bar code, choose qualified rectangle;
(4) angle is determined to the minimum circumscribed rectangle of selection and carries out angle modification, realize the upright of bar code;
(5) processing is ranked up to rectangle of the bar code after upright, under bar code symbologies unanimous circumstances, is sorted
Multiple rectangular areas containing bar code afterwards, complete the positioning of bar code.
Further, the pretreatment in the step (1), specific steps include:
1) image is become into grayscale image from cromogram using the color gamut conversion of weighted mean method;
2) denoising is carried out to resulting grayscale image by Wiener filtering;
3) method of Otsu method (big law) as threshold process is chosen, grayscale image is further converted into binary picture
Picture.
Specifically, the step of edge detection in step (2) is divided into four filtering, enhancing, detection and positioning parts.And
The cardinal principle of edge detection algorithm is single order and second dervative based on image intensity.
Further, before carrying out edge detection, it is necessary to Gradient Features extraction is carried out to image, specifically:
Possess the gradient vector with size and Orientation at the image function midpoint f (x, y) (x, y) of the invention, if
There are two gradient component G with tool on the direction y in the x direction for itxAnd Gy, then the gradient vector at this can indicate are as follows:
The value of gradient are as follows:
Deflection are as follows:
Processing to digital picture should be equivalent to and seek gradient to two-dimensional discrete function, so having:
Wherein:
It is calculated to simplify, the value of gradient is simplified are as follows:
When x-axis and y-axis rotate, right angled triangle is since the length of bevel edge will not change, so two right angles
The length on side will necessarily just change, that is,Value can change.
It preferably, is Sobel operator used in the edge detection of the step (2), Sobel operator is a kind of single order
The gradient value of pixel close region is utilized to calculate the gradient of everywhere pixel, then according to certain threshold value in differential operator
Further value is carried out, to realize edge detection;For the template (z of a 3x31-z9), calculation method is as follows:
Specifically, in the step (3), after detecting the edge of target shape, the wheel by tracking object is needed
Exterior feature carries out profile orderings to shape, is generally divided into the tracking of 4 directions according to the neighbouring relations of pixel and 8 directions track, main
Step are as follows:
1) select starting point: it is that the smallest point as start bit that row coordinate in sharp point and column, which are sat target value all,
It sets.Start position is searched by way of scanning to target image, is progressively scanned according to sequence from left to right from top to bottom, when
When looking for first position of minimum row train value, if the point does not track the label symbol of end, which can be determined
For the boundary starting point of profile, it is denoted as A0, and there are in profile list structure by its coordinate value.
2) profile is searched: from starting point A0It sets out, the order priority judgement in neighborhood direction is carried out along the point, according to from small
To big principle.Then judge whether the consecutive points are boundary points by edge judgment criterion, if meeting criterion, by secondary phase
A is denoted as in the coordinate deposit profile chained list of adjoint pointn(n=1,2,3 ...), then by AnAgain it is set as current outline point, then to look into
Look for An+1, it is deposited into profile chained list, continues next direction and search.And so on, find all profile points and structure
At profile.
Specifically, in the step (4), come to carry out angle really to minimum circumscribed rectangle by using hough transformation
It is fixed.
The present invention compared to the prior art, have it is below the utility model has the advantages that
1, the present invention can realize the positioning of multiple bar codes in a figure, can only once identify one compared to existing
Infrared laser scanning means, it is clear that have higher efficiency.
2, the camera that the present invention uses is that common camera is cheap, and required configuration level is lower.
3, the algorithm comparison that uses of the present invention is simple, so that recognition speed only within 1.5s, absolutely meets industrial requirements.
Detailed description of the invention
Fig. 1 is the bar code positioning flow figure in the present invention based on Image Edge-Detection feature;
Fig. 2 is the binary image obtained after pretreatment in the present invention;
Fig. 3 is the image in the present invention after rectangular area detection and bar code content detection.
Specific embodiment
Present invention will now be described in further detail with reference to the embodiments and the accompanying drawings, but embodiments of the present invention are unlimited
In this.
Embodiment
It is as shown in Figure 1 a kind of specific flow chart of bar code localization method based on Image Edge-Detection feature, it is described
The step of method includes:
(1) image detected is pre-processed, obtains binary image.
Pre-treatment step in the step (1), specifically includes:
1) image is become into grayscale image from cromogram using the color gamut conversion of weighted mean method;
2) denoising is carried out to resulting grayscale image by Wiener filtering;
3) method of Otsu method (big law) as threshold process is chosen, grayscale image is further converted into binary picture
Picture.
The black and white binary image that image obtains after pretreatment is as shown in Figure 2.
(2) edge detection is carried out to the boundary rectangle in binary image, obtains the position of multiple rectangles;
By carrying out edge detection to region in figure, detection identification is carried out to all edges.To obtain n rectangle region
Domain carries out the setting of length-width ratio and elongated range to n rectangular area, removes excessive and too small rectangle, filters out and meet
The rectangular area of bar code shape, number m.
Specifically, the step of edge detection in step (2) is divided into four filtering, enhancing, detection and positioning parts.And
The cardinal principle of edge detection algorithm is single order and second dervative based on image intensity.
Before carrying out edge detection, it is necessary to Gradient Features extraction is carried out to image, specifically:
Possess the gradient vector with size and Orientation at the image function midpoint f (x, y) (x, y) of the invention, if
There are two gradient component G with tool on the direction y in the x direction for itxAnd Gy, then the gradient vector at this can indicate are as follows:
The value of gradient are as follows:
Deflection are as follows:
Processing to digital picture should be equivalent to and seek gradient to two-dimensional discrete function, so having:
Wherein:
It is calculated to simplify, the value of gradient is simplified are as follows:
When x-axis and y-axis rotate, right angled triangle is since the length of bevel edge will not change, so two right angles
The length on side will necessarily just change, that is,Value can change.
It preferably, is Sobel operator used in the edge detection of the step (2), Sobel operator is a kind of single order
The gradient value of pixel close region is utilized to calculate the gradient of everywhere pixel, then according to certain threshold value in differential operator
Further value is carried out, to realize edge detection;For the template (z of a 3x31-Z9), calculation method is as follows:
After above-mentioned edge detection, acquisition is rectangular area, as shown in the region in the thick frame of grey in Fig. 3,
Wherein, 9 n, m 4.
(3) judged by bar code, choose qualified rectangle;
In the step (3), after detecting the edge of target shape, the profile by tracking object is needed, to shape
Shape carries out profile orderings, is generally divided into the tracking of 4 directions according to the neighbouring relations of pixel and 8 directions track, key step are as follows:
1) select starting point: it is that the smallest point as start bit that row coordinate in sharp point and column, which are sat target value all,
It sets.Start position is searched by way of scanning to target image, is progressively scanned according to sequence from left to right from top to bottom, when
When looking for first position of minimum row train value, if the point does not track the label symbol of end, which can be determined
For the boundary starting point of profile, it is denoted as A0, and there are in profile list structure by its coordinate value.
2) profile is searched: from starting point A0It sets out, the order priority judgement in neighborhood direction is carried out along the point, according to from small
To big principle.Then judge whether the consecutive points are boundary points by edge judgment criterion, if meeting criterion, by secondary phase
A is denoted as in the coordinate deposit profile chained list of adjoint pointn(n=1,2,3 ...), then by AnAgain it is set as current outline point, then to look into
Look for An+1, it is deposited into profile chained list, continues next direction and search.And so on, find all profile points and structure
At profile.
Contour detecting is carried out to the fringe region in figure by Freeman chain code edge in the present embodiment, what is obtained contains
There is the rectangular area of bar code as shown in the content in the thick frame of black in Fig. 3.
(4) angle is determined to the minimum circumscribed rectangle of selection and carries out angle modification, realize the upright of bar code;
There is certain angle tilts for bar code as shown in Figure 3, contain according in the image detected in step (3)
There is the rectangular area of bar code, obtains the tilt angle of image using hough angular transformation to m region, by angle change,
Obtain upright bar code rectangular image.Thus the foundation as judgement identification carries out content detection, to obtain containing upright
The rectangular area k of bar code.
(5) processing is ranked up to rectangle of the bar code after upright, under bar code symbologies unanimous circumstances, is sorted
Multiple rectangular areas containing bar code afterwards, complete the positioning of bar code.
According to the k rectangular area that step (4) obtains, to k region using the method that side length sorts can be obtained containing
The maximum area rectangular area of bar code necessarily has the maximum region of area to the detection of bar code situation in figure, by right
Area is compared, and is obtained the maximum preceding S of area, is further screened using length-width ratio, the barcode size or text field is obtained, thus complete
At the localization process of multiple barcode.
The above embodiment is a preferred embodiment of the present invention, but embodiments of the present invention are not by above-described embodiment
Limitation, other any changes, modifications, substitutions, combinations, simplifications made without departing from the spirit and principles of the present invention,
It should be equivalent substitute mode, be included within the scope of the present invention.