The content of the invention
In view of above-mentioned the deficiencies in the prior art, it is an object of the invention to provide a kind of optical axis real-time calibration method and being
System, it is intended to solve the problems such as existing calibration steps efficiency is low, precision is not high, concordance is poor.
Technical scheme is as follows:
A kind of optical axis real-time calibration method, wherein, including:
Step A, initialization collecting device;
Step B, the piece image for obtaining target sheet, include square and rectangle pattern on the target sheet;
Step C, space conversion is carried out to described image;
Step D, binary conversion treatment is carried out to described image;
The square in image and rectangle pattern after step E, acquisition process;
The center abscissa of step F, the centre coordinate of statistics square pattern and rectangle pattern;
The center abscissa of step G, the centre coordinate according to the square pattern and rectangle pattern calculates offset
Angle and vertical off setting angle;
Step H, real time calibration is carried out according to the offset angle and vertical off setting angle.
Described optical axis real-time calibration method, wherein, step G is specifically included:
G1, it is calculated as follows out horizontal deviation angle:
(p2.x-p1.x)/2=(p1.x-pstarndard.x)/angx, wherein, pstandard.x is standard point
Abscissa,(P1.x, p1.y)For foursquare centre coordinate, p2.x is rectangular center abscissa;
G2, it is calculated as follows out vertical off setting angle:
(p2.x-p1.x)/2=(p1.y-pstarndard.y)/angy, wherein, pstandard.y is the vertical of standard point
Coordinate.
Described optical axis real-time calibration method, wherein, step D is specifically included:
D1, medium filtering is carried out to image first;
D2, binary conversion treatment is carried out to image again.
Described optical axis real-time calibration method, wherein, step E is specifically included:
The profile of the closed pattern in image after E1, acquisition binary conversion treatment;
E2, according to the ratio of width to height and area threshold of the profile, obtain the square and rectangle pattern in image.
Described optical axis real-time calibration method, wherein, in step H, meet after calibration:abs(p2.y - p1.y) <
60 and abs (p2.x-p1.x)>125 and abs (p2.x-p1.x)<145,(P1.x, p1.y)For foursquare
Centre coordinate,(P2.x, p2.y)For rectangular centre coordinate.
A kind of optical axis real-time calibration system, wherein, including:
Initialization module, for initializing collecting device;
Image collection module, for obtaining the piece image of target sheet, includes square and rectangle pattern on the target sheet;
Space conversion module, for carrying out space conversion to described image;
Binary conversion treatment module, for carrying out binary conversion treatment to described image;
Pattern acquisition module, the square in image and rectangle pattern after processing for acquisition;
Coordinate statistical module, for counting the center abscissa of the centre coordinate and rectangle pattern of square pattern;
Deviate computing module, the center abscissa for the centre coordinate according to the square pattern and rectangle pattern is calculated
Go out horizontal deviation angle and vertical off setting angle;
Calibration module, for carrying out real time calibration according to the offset angle and vertical off setting angle.
Described optical axis real-time calibration system, wherein, the deviation computing module is specifically included:
Offset computing unit, for being calculated as follows out horizontal deviation angle:
(p2.x-p1.x)/2=(p1.x-pstarndard.x)/angx, wherein, pstandard.x is standard point
Abscissa,(P1.x, p1.y)For foursquare centre coordinate, p2.x is rectangular center abscissa;
Vertical off setting computing unit, for being calculated as follows out vertical off setting angle:
(p2.x-p1.x)/2=(p1.y-pstarndard.y)/angy, wherein, pstandard.y is the vertical of standard point
Coordinate.
Described optical axis real-time calibration system, wherein, the binary conversion treatment module is specifically included:
Median filter unit, for first carrying out medium filtering to image;
Binarization unit, for carrying out binary conversion treatment to image again.
Described optical axis real-time calibration system, wherein, the pattern acquisition module is specifically included:
Profile acquiring unit, for obtaining the profile of the closed pattern in the image after binary conversion treatment;
Pattern acquiring unit, for the ratio of width to height and area threshold according to the profile, obtains square in image and rectangular
Shape pattern.
Described optical axis real-time calibration system, wherein, in the calibration module, meet after calibration:abs(p2.y -
p1.y) <60 and abs (p2.x-p1.x)>125 and abs (p2.x-p1.x)<145,(P1.x, p1.y)For
Foursquare centre coordinate,(P2.x, p2.y)For rectangular centre coordinate.
Beneficial effect:The present invention passes through target sheet(Optics target sheet), and be analyzed using pattern algorithm real-time image acquisition,
The horizontal and vertical deviation angle of optical axis is obtained, precision can reach 0.05 degree.Drastically increase the light of production efficiency and product
Learn the concordance of systematic optical axis.The calibration steps high precision of the present invention, it is simple to operate, and not against external auxiliary device, use
It is convenient.
Specific embodiment
The present invention provides a kind of optical axis real-time calibration method and system, to make the purpose of the present invention, technical scheme and effect
Clearer, clear and definite, the present invention is described in more detail below.It should be appreciated that specific embodiment described herein is only
To explain the present invention, it is not intended to limit the present invention.
Fig. 1 is referred to, Fig. 1 is a kind of flow chart of optical axis real-time calibration method preferred embodiment of the invention, as illustrated,
Which includes:
Step S1, initialization collecting device;
Step S2, the piece image for obtaining target sheet, include square and rectangle pattern on the target sheet;
Step S3, space conversion is carried out to described image;
Step S4, binary conversion treatment is carried out to described image;
The square in image and rectangle pattern after step S5, acquisition process;
The center abscissa of step S6, the centre coordinate of statistics square pattern and rectangle pattern;
The center abscissa of step S7, the centre coordinate according to the square pattern and rectangle pattern calculates offset
Angle and vertical off setting angle;
Step S8, real time calibration is carried out according to the offset angle and vertical off setting angle.
The present invention provides a set of tool calibrated and optics chart figures with a scale(I.e. optics target sheet, of the invention
Claim target sheet), the target sheet include one for identify center square pattern and one with this center deviation certain angle
Rectangle pattern, may also set up the pattern of other convenient identifications certainly.Present invention identify that the square of central area, and return
This foursquare centre coordinate, and the center abscissa with the rectangle of this center deviation special angle, unit is pixel.Assume
It is 2 degree of deviation angle, the pixel being then back to is 60.If present invention identify that centre coordinate it is inclined with the level of standard coordinate
It is 30 from value(Pixel), then offset angle is exactly 1 degree.
Specifically, in step S1, collecting device can be the video frequency collection card of a usb3.0 interface, and this regards
Frequency capture card provides the driver under windows environment, calls VFW frameworks on upper strata(Video generates framework)API, i.e.,
The initialization that video frequency collection card can be completed and the work for starting image acquisition.
In step S2, a buffering is opened up in a program, the API for calling OpenCV to provide, such as
The grab interfaces of VideoCapture classes, or VideoCapture& operator>> (CV_OUT Mat& image);
Image can be got, the image for getting in the present embodiment is 3 Channel Colors of BGR888 of 640 *, 480 sizes
Image.
In step S3, coloured image is exactly changed into the single channel image of single color, example for image space conversion
As 3 Channel Color images of BGR888 can be transformed into the single channel image of single color by the present embodiment.The formula of conversion is as follows
Gray=0.299f * B+0.587f*G+0.114f*R, gray is gray value, and gray-scale maps are so obtained.
In step S4, which specifically includes:
S41, medium filtering is carried out to image first;
S42, binary conversion treatment is carried out to image again.
Specifically, first gray-scale maps are carried out with median filter process, for example, first does the medium filtering of 3 × 3.Carry out in
Value filtering process is, in order to reduce noise, mean filter process to may also be employed certainly, but which can retain more than mean filter
Details.After median filter process, binary conversion treatment can be carried out, binary conversion treatment is by the gray value of the pixel on image
0 or 255 is set to, that is, whole image is presented into obvious black and white effect.
In step S5, which specifically includes:
The profile of the closed pattern in image after S51, acquisition binary conversion treatment;
S52, according to the ratio of width to height and area threshold of the profile, obtain the square and rectangle pattern in image.
Specifically, first find out the profile of each high brightness closed pattern from the later image of binaryzation, this profile by
The x that number differs, y coordinate pair is reached into, at least 3 coordinate pairs, to constitute closed pattern.Rectangle(Including square and length
It is square)Profile have individual feature, if being multiplied by height with the width of profile obtains the area of this profile boundary rectangle, use this face
Product deducts the area of profile encirclement, then its difference can very little, if profile parcel is an irregular pattern, this difference
Can be than larger.So according to the ratio of width to height and area threshold of profile, obtaining the square and rectangle pattern in image, such as Fig. 2
It is shown.Described area threshold refers to that the width of profile is multiplied by the upper limit that the value for highly obtaining deducts the area of profile encirclement, i.e.,
The width of profile is multiplied by the value that obtains of height and deducts the area of profile encirclement and needs, less than or equal to the area threshold, can just sentence
The fixed profile is square or rectangular.In addition, the profile should have certain size, the width and height of such as profile should
At least 100 pixels, and it is at most 1500 pixels.In the present invention, heart position is square pattern in the picture, and side has
There is a rectangle pattern, rectangle pattern is vertical bar shape.
In step S6, foursquare centre coordinate and rectangular center abscissa are counted;According to aforesaid profile
Position, foursquare centre coordinate can be calculated(P1.x, p1.y)With rectangular centre coordinate(P2.x, p2.y), its
Middle p2.x is rectangular center abscissa.
In step S7, which specifically includes:
S71, it is calculated as follows out horizontal deviation angle:
(p2.x-p1.x)/2=(p1.x-pstarndard.x)/angx, wherein, pstandard.x is standard point
Abscissa;Wherein, angx is the offset number of degrees that will be shown, that is, the offset number of degrees for wanting to ask for, separately
The outer number of degrees that vertically deviate can be indicated with angy.Standard point therein is the product calibrated by traditional optical, is passed through
After image acquisition, the square center coordinate for getting, this coordinate can be by software records in file, after software starts, meeting
Read this coordinate figure.
S72, it is calculated as follows out vertical off setting angle:
(p2.x-p1.x)/2=(p1.y-pstarndard.y)/angy, wherein, pstandard.y is the vertical of standard point
Coordinate.
In step S8, learnt by the image debugging result at scene, the rectangle and central square of vertical bar
Coordinate must is fulfilled for following condition:
abs(p2.y - p1.y) <60 and abs (p2.x-p1.x)>125 and abs (p2.x-p1.x)<
145;In above-mentioned formula, unit is pixel, and image size is 640*480.
Wherein,(P1.x, p1.y)For foursquare centre coordinate,(P2.x, p2.y)For rectangular centre coordinate.According to
This condition, it is possible to obtain the centre coordinate of the big vertical bar rectangle on the high coordinate figure of accuracy, central square and side.
Illustrate, it is assumed that L for picture centre square A central point to elongated rectangle B in side centrage it
Between distance, the computing formula of L is, wherein=2, r=8.7 m, thus calculates L=0.30368728m, if handle
This 20 decile of distance, and draw high scale line, then it is 0.1 degree visually to read the precision that can be got, by Algorithm Analysis
Image, L corresponding number of pixels in the graphic are 135, but during actual production, the bounce amplitude of pixel is 4, that
The precision that conversion comes is 0.05 degree.By way of naked eyes read and record, the optical axis of manual setting product during this period,
Probably need to process within 4 minutes a product, and after using the method for the present invention, one can be processed within about 1 minute, and it is right
The pressure of workman is substantially reduced.Workman only needs manual setting optical axis to be changed into blue dot i.e. until the foursquare central point for recognizing
Can, bar code is then scanned, information can be recorded automatically.
The present invention also provides a kind of optical axis real-time calibration system, and which includes:
Initialization module, for initializing collecting device;
Image collection module, for obtaining the piece image of target sheet, includes square and rectangle pattern on the target sheet;
Space conversion module, for carrying out space conversion to described image;
Binary conversion treatment module, for carrying out binary conversion treatment to described image;
Pattern acquisition module, the square in image and rectangle pattern after processing for acquisition;
Coordinate statistical module, for counting the center abscissa of the centre coordinate and rectangle pattern of square pattern;
Deviate computing module, the center abscissa for the centre coordinate according to the square pattern and rectangle pattern is calculated
Go out horizontal deviation angle and vertical off setting angle;
Calibration module, for carrying out real time calibration according to the offset angle and vertical off setting angle.
Further, the deviation computing module is specifically included:
Offset computing unit, for being calculated as follows out horizontal deviation angle:
(p2.x-p1.x)/2=(p1.x-pstarndard.x)/angx, wherein, pstandard.x is standard point
Abscissa,(P1.x, p1.y)For foursquare centre coordinate, p2.x is rectangular center abscissa;
Vertical off setting computing unit, for being calculated as follows out vertical off setting angle:
(p2.x-p1.x)/2=(p1.y-pstarndard.y)/angy, wherein, pstandard.y is the vertical of standard point
Coordinate.
Further, the binary conversion treatment module is specifically included:
Median filter unit, for first carrying out medium filtering to image;
Binarization unit, for carrying out binary conversion treatment to image again.
Further, the pattern acquisition module is specifically included:
Profile acquiring unit, for obtaining the profile of the closed pattern in the image after binary conversion treatment;
Pattern acquiring unit, for the ratio of width to height and area threshold according to the profile, obtains square in image and rectangular
Shape pattern.
Further, in the calibration module, meet after calibration:abs(p2.y - p1.y) <60 and abs (p2.x-
p1.x) >125 and abs (p2.x-p1.x)<145,(P1.x, p1.y)For foursquare centre coordinate,(P2.x,
p2.y)For rectangular centre coordinate.
It is described in detail in method above with regard to the ins and outs of above-mentioned modular unit, therefore is repeated no more.
In sum, the present invention passes through target sheet(Optics target sheet), and be analyzed using pattern algorithm real-time image acquisition,
The horizontal and vertical deviation angle of optical axis is obtained, precision can reach 0.05 degree.Drastically increase the light of production efficiency and product
Learn the concordance of systematic optical axis.
It should be appreciated that the application of the present invention is not limited to above-mentioned citing, and for those of ordinary skills, can
To be improved according to the above description or be converted, all these modifications and variations should all belong to the guarantor of claims of the present invention
Shield scope.