Background technology
Along with the intensification of bar code application, also, to the development that develops simultaneously of miniaturization, safe and reliable, multi-functional, economic and practical, remote, software and hardware, there is a lot of novel equipment in the equipment of bar-code identification.Bar code acquiring terminal is towards the future development of integrated multiple mechanics of communication and network technology integration apparatus, portability and multifunctional comprehensive at present; The generation equipment of bar code is towards short run and specificity development.Concrete manifestation has the multifunctional integrated mobile phone reading bar codes such as bar code communication based on CDMA, GPRS identification bar code and collection data sampling and processing, mutual, demonstration, certification.External a lot of companies, organically combine barcode technology and machine vision well, are applied in the measurement of commercial production streamline, quite high in the use popularity rate of the state such as America and Europe and Japan and Korea S machine vision.Within 2007, the global machine vision total market size is about 9,000,000,000 dollars, and increases rapidly with the speed of annual 10.9% left and right, will exceed 15,000,000,000 dollars by 2012.Machine vision technique development area the most ripe and that use amount is maximum mainly concentrates on America and Europe and Japan, and there are PPTVision, Siemens, NI, Banner, Cognex etc. in well-known manufacturer.
In actual application, machine vision is general little as an independent system, but occurs as a part for an automated system, with data acquisition, motion control, logic control and communication network incompatible its unique advantage that realizes that matches.
At present, barcode technology has been applied to a lot of field of China, has thousands of enterprises and Research Center to be engaged in the research of bar code aspect, application work.Wherein, Chinese letter co has been invented by Article Numbering Center of China, and GM code and CM code have been invented by Shenzhen Xi Gan company, and the commercial monopoly of Scientific And Technical company on two-dimensional bar code generation technique broken in the research of the two-dimensional bar code of these independent intellectual property rights.Although made significant headway aspect the recognition algorithm of the domestic generation in bar code and bar code, some companies carry out secondary development and application in conjunction with offshore company's product of the future and recognition technology, also independent research there is the recognizing apparatus of intellecture property, but compare with developed country, still have very large gap, the core recognition technology of applying in the world more two-dimensional bar code still rests in external science-and-technology enterprise hand.
The people such as Chen Yuanyuan propose to utilize perspective view that bar code region is positioned, extracted.First image is carried out to rim detection, again the image that passes through edge treated is carried out to the projection of horizontal direction and vertical direction, join together to determine the general location of bar code according to horizontal direction in perspective view and the larger region of vertical direction projection value, out by bar code extracted region finally.This method is edge very dense and the complexity in hypothesis bar code region, and meanwhile, other edges of regions point is fairly simple and gray scale is more smooth.This method is simple to background, bar code region is more applicable without the image ratio of too many interference pattern around, but image to complex background, effect can reduce greatly.
Certain methods is all carried out piecemeal by image at present, to every calculate Grad a little obtain image border, determine whether possible bar code region by direction and the quantity etc. of each marginal point, then Probability Area is communicated with to the region that bar code is extracted in the processing such as merging.The method is to utilize the textural characteristics of bar code itself to remove the pseudo-region of bar code.But the method is very crucial to the size of setting piece, and in the time that piece setting is too large, the region obtaining can be very large, and the object that comprises a part of bar code surrounding, the more difficult selection of carrying out potential region; When piece setting too hour, be difficult to embody the textural characteristics of bar code.
Wu Jiapeng etc. propose the Data Matrix two-dimensional bar code method for extracting region based on Gabor filtering and BP neural network, and it utilizes BP neural network that the image texture characteristic obtaining through Gabor filtering is installed pixel is classified, thereby extracts bar code region.In the time of background more complicated, this method can together extract the region similar to bar code region of gray scale in image, forms a large amount of pseudo-regions, produces higher false alarm rate.But adopt neural network to need a lot of training samples, and working time is long, is not too applicable to general daily identification needs.
2D bar code technology is a kind of brand-new information storage and Transfer Technology, is subject to paying close attention to of international community always.Because it can improve the collecting efficiency of information and the processing speed of data is widely used in information-based industry.At present, two-dimensional bar code is almost comparative maturity abroad, and domestic still in conceptual phase.Although the generation in bar code makes a lot of progress with recognition technical elements, still there is larger gap with external barcode technology level.
Restriction China development 2D bar code technology mainly contains three aspects: reason:
(1) although, the two-dimensional bar code of independent research broken the commercial monopoly of offshore company on two-dimensional bar code generation technique, the two-dimensional bar code range of application of independent research is very little, is not accepted by international standard.At present general two-dimensional bar code is all still the two-dimensional bar code with international standard in the world.
(2), at present conventional two-dimensional bar code recognition core technology is not grasped completely.The research of recognizer is not very thorough, is much the recognition software development kit of buying offshore company, does not form the recognition algorithm with independent intellectual property right.
(3), the recognizing apparatus of two-dimensional bar code is more expensive.Although more domestic enterprises also design the recognizing apparatus with generating two-dimension bar-code, its product is the secondary development based on Sybol company of U.S. product mostly, and price is also relatively high; The recognizing apparatus of independent research is difficult to again the effect that reaches satisfied in recognition effect.
Therefore the recognizing apparatus that, recognition technology, the cost of development of study two-dimensional bar code are low has very important realistic meaning and far-reaching significance to promoting 2D bar code technology in development, propelling China process of IT application of China.
Summary of the invention
The object of the invention is to overcome the deficiencies in the prior art, the method for quickly identifying of the Data Matrix two-dimensional bar code under a kind of simple operating mode background is provided, its method is simple, and calculated amount is few, improves recognition efficiency and accuracy of identification, quick and convenient, safe and reliable.
According to technical scheme provided by the invention, the Data Matrix two-dimensional bar code method for quickly identifying under a kind of simple operating mode background, described Data Matrix two-dimensional bar code method for quickly identifying comprises the steps:
A, collection include the gray level image of Data Matrix, and set up coordinate system taking the described gray level image upper left corner as initial point; Utilize Roberts edge detection operator to carry out rim detection to described gray level image, and utilize maximum variance between clusters (OTSU) to carry out binaryzation to the gray level image carrying out after rim detection;
B, adopt recursion marking method to carry out zone marker to image obtained above;
C, be rectangle according to Data Matrix bar code exterior contour, and image after utilizing region area to above-mentioned mark zone marker carries out preliminary screening, remove after interference region the preliminary image that comprises Data Matrix bar code region that obtains;
D, be " L " type straight line according to Data Matrix Bar code positioning image, carry out postsearch screening according to form factor and spherical property, screening obtains the image in Data Matrix bar code region;
E, the image that above-mentioned postsearch screening is obtained to Data Matrix bar code region carry out bar code border mark, and the labeling function curve obtaining is carried out to differentiate, obtain corresponding derivative curve; Determine the required anglec of rotation in Data Matrix bar code region according to derivative curve, Data Matrix bar code region being rotated to the square position of level according to the anglec of rotation.
Adopt gridding method to carry out data extraction to the above-mentioned Data Matrix bar code region that rotates to the square position of level.
Described step a comprises the steps:
When a1, employing Roberts edge detection operator carry out rim detection, two convolution kernels of Roberts edge detection operator are respectively
Adopt 1 norm gradient to weigh amplitude
A2, image after above-mentioned rim detection is adopted to maximum variance between clusters Threshold segmentation, reject the less marginal point of part gradient, to delete background information, retain foreground target information.
Described step b comprises the steps:
B1, to the image after binaryzation from top to bottom, from left to right scan line by line, if search out and there is no marked some H in the time of scanning, distributes a new mark to described some H;
If the neighborhood of b2 point H has the same mark of recurrence frequency division of object pixel;
B3, interconnective pixel is all carried out to mark, the region of each connection adopts same mark mark, and different connected regions adopts different mark marks;
B4, repeat the step of above-mentioned b1~b3, to in image, unlabelled impact point being shifted to an earlier date and the impact point in the corresponding field of unmarked impact point being distributed to same mark mark according to recurrence, until in image all impact point all mark or searching less than unlabelled impact point.
In described step c, the respective area of marked region in calculation procedure b, and the region that calculates area and be less than 80 pixels is screened out to the preliminary image that comprises Data Matrix bar code region that obtains.
Described steps d comprises the steps:
D1, the image calculation form parameter F that preliminary acquisition is comprised to Data Matrix bar code region, to obtain some regions that are similar to rectangle;
D2, screening form parameter F be in the region of [4/ π, 7.2/ π], and calculate spherical property parameter S in region after screening;
D3, screen spherical property parameter S and exist
region, to obtain the image in Data Matrix bar code region.
Described form parameter F is F=‖ B ‖
2/ (4 π A), B is the girth in correspondence markings region, A is the area in correspondence markings region; Area A is
f (x, y) is the pixel value of (x, y) in correspondence markings region, and J is the size of marked region horizontal direction, and K is the size of marked region vertical direction; Spherical property parameter S is S=r
i/ r
c, r
i, r
cthe corresponding incircle in expressive notation region, external radius of a circle respectively; The center of circle of described incircle and circumscribed circle is all positioned in the center of gravity of marked region.
Described step e comprises the steps:
The function that e1, employing distance are angle carries out mark to zone boundary, and labeling function is λ=Wsec θ; Wherein, W represents the distance of center of gravity to the distance on horizontal dotted line limit or center of gravity to solid horizontal line limit, straight line after θ represents to be connected between point on bar code solid line limit and center of gravity and the angle of horizontal direction, λ represents point on the bar code solid line limit Euclidean distance to center of gravity;
E2, to after the labeling function differentiate of described zone boundary, the point that searching derivative function is 0, and judge whether derivative function is at 0 is continuity point, to obtain the angle on two solid line limits in Data Matrix bar code, and obtain according to the angle on two solid line limits the angle that Data Matrix bar code region need to rotate.
Also comprise step e3, justify search along the solid line limit of Data Matrix bar code, to obtain the end points of Data Matrix bar code solid line, and according to the intersection point on Data Matrix bar code dotted line limit, Data Matrix bar code is accurately located.
Adopt the recursion marking method of 8 neighborhoods to carry out zone marker.
Advantage of the present invention: for bar code image under simple industrial environment, according to the feature of Data Matrix positioning pattern, adopt the difference in orthogonal directions to carry out rim detection as the Roberts operator of gradient principle, have very strong specific aim; After the image pre-service such as binaryzation, by 8 neighborhood recurrence methods, mark is carried out in the region in image, obtain behind a lot of zonules the feature that is then rectangle in conjunction with the profile of Data Matrix again, utilize region area, form parameter and spherical property to carry out region screening to region, obtain the approximate region of bar code, have good real-time." L " shape border of bar code 2-D is expressed with the function that the distance of 1-D is angle, in boundary function, seek out the straight-line equation on border and the angle of rotation according to Data Matrix bar code border characteristic; And weaken the impact of fracture straight line on bar code border location with justifying the method for searching for; Simultaneous dotted line limit straight-line equation is determined the intersection point on dotted line limit, reaches the accurately object of location of bar code region.This boundary marker algorithm is to be first applied on the location of bar code at present, has jumped out traditional Bar code positioning thinking, only according to the mark curve on border, bar code is accurately located, and not only calculated amount is little, has also improved the recognition efficiency of Data Matrix.
Embodiment
Below in conjunction with concrete drawings and Examples, the invention will be further described.
The object of the invention is to rely on and " L " shape positioning pattern for the location of Data Matrix bar-code identification is in the past undue, and large, the consuming time shortcoming such as serious of straight-line detection calculated amount, proposes in embedded system, to realize two-dimensional bar code and fast, accurately knows method for distinguishing.
As shown in Figure 4: under simple operating mode background, Data Matrix two-dimensional bar code is known fast method for distinguishing and comprised the steps:
A, collection include the gray level image of Data Matrix, and set up coordinate system taking the described gray level image upper left corner as initial point; Utilize Roberts edge detection operator to carry out rim detection to described gray level image, and utilize maximum variance between clusters (OTSU) to carry out binaryzation to the gray level image carrying out after rim detection;
As shown in Figure 1: image-region to be identified of the present invention is rectangle OXZY, and taking O point as initial point, OX direction is X-axis, and OY direction is Y-axis, sets up coordinate system, and image pixel coordinate represents with this coordinate system, and bar code image is in this region; And regulation, aftermentioned image and point coordinate are all as the criterion with this coordinate system.Initial point O is the upper left corner of gray level image; The binaryzation of image, the gray-scale value of the pixel on image is set to 0 or 255 exactly, namely whole image is presented and significantly only has black and white visual effect.
Detailed process is:
A1, Roberts edge detection operator have good treatment effect to precipitous low noise image, and can meet simple and agility requirement, and Roberts edge detection operator utilizes local difference operator to find edge; While adopting Roberts edge detection operator to carry out rim detection, two convolution kernels of Roberts edge detection operator are respectively
Adopt 1 norm gradient to weigh amplitude
A2, image after above-mentioned rim detection is adopted to maximum variance between clusters Threshold segmentation, reject the less marginal point of part gradient, to delete background information, retain foreground target information.
B, adopt recursion marking method to carry out zone marker to image obtained above;
Adopt 8 neighborhood recursion marking methods to carry out zone marker to image, can mark preferably continuum, reduce the part of fracture, particularly:
B1, to the image after binaryzation from top to bottom, from left to right scan line by line, if search out and there is no marked some H in the time of scanning, distributes a new mark to described some H;
If the neighborhood of b2 point H has the same mark of recurrence frequency division of object pixel;
B3, interconnective pixel is all carried out to mark, the region of each connection adopts same mark mark, and different connected regions adopts different mark marks;
B4, repeat the step of above-mentioned b1~b3, to in image, unlabelled impact point being shifted to an earlier date and the impact point in the corresponding field of unmarked impact point being distributed to same mark mark according to recurrence, until in image all impact point all mark or searching less than unlabelled impact point.
C, be rectangle according to Data Matrix bar code exterior contour, and image after utilizing region area to above-mentioned mark zone marker carries out preliminary screening, remove after interference region the preliminary image that comprises Data Matrix bar code region that obtains;
When adopting after 8 neighborhood recursion marking method marks, calculate the area of each marked region, because be two-value picture, area calculates the counting being just reduced to pixel in marked region; The minimum gauge of Data Matrix bar code is 10*10, a normal data module is 3 pixels, may not exclusively wait factor for ensureing that reliability and border are followed the tracks of, calculate according to 2 pixels of a data module, and the region that area is less than 80 pixels is screened out to the preliminary image that comprises Data Matrix bar code region that obtains.
D, be " L " type straight line according to Data Matrix Bar code positioning image, carry out postsearch screening according to form factor and spherical property, screening obtains the image in Data Matrix bar code region;
Because Data Matrix bar code has altogether 30 kinds of specifications, Data Matrix bar code seek the straight line that bit pattern is " L " shape, consider it is that edge pixel to Data Matrix bar code calculates, adopt form parameter F to screen, again due to Data Matrix bar code to seek bit pattern Aspect Ratio scope be [1,4], adopt spherical property parameter S to filter out bar code region in the region of mark; Because form parameter F calculates simply, fast operation, can preliminary screening go out target area, more accurately filters out bar code region by spherical property parameter S.
Be " L " type straight line according to Data Matrix Bar code positioning image, and the ratio value scope of positioning pattern in all versions of Data Matrix, the marked region after step c screening is carried out to postsearch screening according to form factor and spherical property again, particularly:
D1, the image calculation form parameter F that preliminary acquisition is comprised to Data Matrix bar code region, to obtain some regions that are similar to rectangle;
Described form parameter F is F=‖ B ‖
2/ (4 π A), B is the girth in correspondence markings region, A is the area in correspondence markings region; Area A is
f (x, y) is the pixel value of (x, y) in correspondence markings region, and J is the size of marked region horizontal direction, and K is the size of marked region vertical direction; When marked region is bowlder, form parameter F equals 1; And in the time that marked region is other shapes, form parameter F is greater than 1;
D2, screening form parameter F be in the region of [4/ π, 7.2/ π], and calculate spherical property parameter S in region after screening;
Spherical property parameter S is S=r
i/ r
c, r
i, r
cthe corresponding incircle in expressive notation region, external radius of a circle respectively; The center of circle of described incircle and circumscribed circle is all positioned in the center of gravity of marked region.No matter how how the center of circle is selected, and the value of spherical property parameter S, when marked region is bowlder, all reaches maximum (S=1); In the time that being other shapes, region has S < 1.Spherical property parameter S is relatively applicable to also having when the variation of the existing elongation of the variation aspect of target the variation of scrambling aspect, can reduce because of slight bar code distortion or cause the impacts of reason on bar code Primary Location such as bar code distortion due to shooting angle, improving the stability of bar code Primary Location.
D3, screen spherical property parameter S and exist
region, to obtain the image in Data Matrix bar code region.
E, the image that above-mentioned postsearch screening is obtained to Data Matrix bar code region carry out bar code border mark, and the labeling function curve obtaining is carried out to differentiate, obtain corresponding derivative curve; Determine the required anglec of rotation in DataMatrix bar code region according to derivative curve, Data Matrix bar code region being rotated to the square position of level according to the anglec of rotation;
Described step e is specially:
The function that e1, employing distance are angle carries out mark to zone boundary, and labeling function is λ=Wsec θ; Wherein, W represents the distance of center of gravity to the distance on horizontal dotted line limit or center of gravity to solid horizontal line limit, straight line after θ represents to be connected between point on bar code solid line limit and center of gravity and the angle of horizontal direction, λ represents point on the bar code solid line limit Euclidean distance to center of gravity; As shown in Figure 2;
Because Data Matrix bar code region comprises two solid line limits, for the border feature of Data Matrix bar code, adopt apart from the function for angle mark is carried out in border.Labeling function requires first to obtain the center of gravity to obtaining Data Matrix bar code region in steps d, the function that the distance of then obtaining two solid line coboundary points and center of gravity is angle.
This mark is not subject to the impact of Data Matrix bar code region translation, but can be subject to the region rotation of Data Matrix bar code or scaling and convert; The impact that scaling causes is that the range value of mark can change, and this problem can solve by amplitude peak value is normalized to unit value, but the impact that utilizes this mark to be rotated obtains the border angle of bar code;
E2, to after the labeling function differentiate of described zone boundary, the point that searching derivative function is 0, and judge whether derivative function is at 0 is continuity point, to obtain the angle on two solid line limits in Data Matrix bar code, and obtain according to the angle on two solid line limits the angle that Data Matrix bar code region need to rotate;
Because there are two real limits in the sprocket bit of Data Matrix bar code, two other dotted line limit, carries out a differentiate, the derivative curve obtaining to the labeling function curve obtaining; After differentiate, solid line limit is continuous, be 0 point therefore find derivative in the function after differentiate, and then judge whether this point is that continuity point just can obtain the angle on 2 solid line limits, then the mean value of getting these two angles just can obtain that bar code need to rotate angle.When obtaining after the required anglec of rotation, acquisition Data Matrix bar code region can be rotated to the position of level pros, so that to reading of Data Matrix bar code region, and adopt gridding method to carry out data extraction to the above-mentioned DataMatrix bar code region that rotates to the square position of level.
Consider in the time of rim detection, while may there is the fracture of straight line and screen in region in the solid line limit of bar code screened fall, so the position of only asking for the end points on bar code solid line limit according to " L " shape boundary marker function is insecure.Thereby justify search along the direction on bar code solid line limit in edge detection graph, when guaranteeing solid line limit complete, reach the object of the accurate location to barcode position.Be in particular:
The generalized case of considering Fig. 3, there is certain angle in " L " shape border and transverse axis, and O (x sets up an office
o, y
o), M (x
m, y
m), N (x
n, y
n), P (x
p, y
p), wherein M, N, angle that P is corresponding are θ
1, θ
2, θ
3, correspond to ρ with the distance of an O
1, ρ
2, ρ
3.
By known focus point O (x
o, y
o) and | MO|=ρ
1, MO angle θ
1.Can obtain equation:
Separate the coordinate of invocation point M:
In like manner can obtain N (x
n, y
n), P (x
p, y
p):
The equation of straight line MP, PN is:
(x
m-x
p)y-(y
m-y
p)x+x
my
m-2x
my
p+x
py
p=0
(x
n-x
p)y-(y
n-y
p)x+x
ny
n-2x
ny
o+x
py
p=0
Because the minimum data template of Data Matrix is 3 pixels, thus build a r=3, the circle of the center of circle on straight line PM, and the line search that marches forward in one end of PM.When there is more than 5 frontier points in circle time, the center of circle just moves forward search along straight line PM taking diameter 2r as unit.In order to ensure not lose the line segment of fracture, in the time that in the scope of circle, non-boundary point or frontier point number are less than 5, stop search, taking final search to another end points Q (x of frontier point to the point of the intersection point of straight line MP as solid line limit PM
q, y
q), in like manner can obtain another end points S (x of solid line limit PN
s, y
s).
Can obtain the equation of straight line QR at the slope of Q point substitution straight line PN, can obtain the equation of RS at the slope of R point substitution straight line PM, the equation of straight line QR, RS is:
(x
n-x
p)y-(y
n-y
p)x-(x
n-x
p)y
q+(y
n-y
p)x
q=0
(x
m-x
p)y-(y
m-y
p)x-(x
m-x
p)y
s+(y
m-y
p)x
s=0
The above-mentioned straight line QR of simultaneous, RS equation can obtain dotted line limit intersection point R (x
r, y
r):
Specific implementation:
1., taking straight line PM as deferent, bar code region in radius r=3 search edge detection graph.In order to ensure operation, 2 dimension groups are set, one dimension is used for storing home position, and another Wesy stores the frontier point number in this circle.Carry out frontier point search according to the European disk of rounding of radius r=3 along straight line PM, and the frontier point number searching is deposited in row corresponding to the center of circle in two-dimensional array, till searching new round internal boundary points number always and not meeting the demands;
In the position in the center of circle 2., in the end meeting the demands, calculate each frontier point in circle and, to the intersection point position of straight line PM, get intersection point and be worth farthest another end points Q for this solid line limit of bar code at straight line PM, and record Q point coordinate;
3., adopt same method to obtain the end points S coordinate on another solid line limit of bar code;
4., the equation of simultaneous straight line RS, RQ, obtain intersection point R;
5., according to the position of P, Q, R, 4 definite bar codes of S, complete the accurate location in bar code region.
The present invention is directed to bar code image under simple industrial environment, according to the feature of Data Matrix positioning pattern, adopt the difference in orthogonal directions to carry out rim detection as the Roberts operator of gradient principle, have very strong specific aim; After the image pre-service such as binaryzation, by 8 neighborhood recurrence methods, mark is carried out in the region in image, obtain behind a lot of zonules the feature that is then rectangle in conjunction with the profile of Data Matrix again, utilize region area, form parameter and spherical property to carry out region screening to region, obtain the approximate region of bar code, have good real-time." L " shape border of bar code 2-D is expressed with the function that the distance of 1-D is angle, in boundary function, seek out the straight-line equation on border and the angle of rotation according to Data Matrix bar code border characteristic; And weaken the impact of fracture straight line on bar code border location with justifying the method for searching for; Simultaneous dotted line limit straight-line equation is determined the intersection point on dotted line limit, reaches the accurately object of location of bar code region.This boundary marker algorithm is to be first applied on the location of bar code at present, has jumped out traditional Bar code positioning thinking, only according to the mark curve on border, bar code is accurately located, and not only calculated amount is little, has also improved the recognition efficiency of Data Matrix.