Summary of the invention
With a large amount of investments of monitoring device, applies number of shots, the type in embedded system more and more, how to look for
The image correction method for meeting monitoring image requirement in monitoring system is applied to one kind with can be convenient, be that the present invention to be solved
Certainly the problem of.
In order to solve the above technical problems, the technical solution adopted by the present invention is that: a kind of pattern distortion based on conic section
Antidote is distorted using oval or Hyperbolic Equation formula analog image, and the pixel quantity for the camera lens that distorts is H*W, including following
Step:
Step 1: one there is the picture of rectangular or square lattice, before being placed on distortion camera lens, picture and camera lens
Keeping parallelism, shoots the photo of the picture, and photo center is a crosspoint of grid, the horizontal direction across crosspoint
Grid lines be in the horizontal position in photo center;
Step 2: on photo, using above-mentioned grid intersection as origin, two grid lines across crosspoint are X-axis and Y
Axis, the distance in X-axis between two neighboring pixel is length unit, establishes plane right-angle coordinate;
Step 3: according to photo, judging pattern distortion type;
Step 4: the approximate conic for the hook that grid lines is distorted in horizontal and vertical direction is obtained according to photo
The equation of line;
Step 5: according to equation, obtaining the corresponding relationship of fault image and correcting image pixel.
A kind of real-time apparatus for correcting of pattern distortion is closed including embedded system and the video camera for being equipped with distortion camera lens
Key is: the corresponding relationship of fault image and correcting image pixel is stored in the CPU of embedded system;Apparatus for correcting work
When, CPU reads the Pixel Information of each frame distortion image, and according to corresponding relationship, translation bit postpones write-in correcting image file.
The camera lens that monitoring device uses is generally tight shot, with perfect, the skill of each batch camera lens of manufacture craft
Art index is essentially identical, and therefore, a selected camera lens is demarcated, and obtained parameter can be used for monitoring device by the gross.
In addition, monitoring image requirement is not particularly severe, as long as being able to satisfy the requirement of subsequent processing, such as the identification of license plate, fault image
The effect of correction can receive.
The resolution ratio of camera lens is H*W, such as 1280*960, then photo can regard 1280 row of horizontal direction, vertical direction as
960 column compositions, the intersection point of row, column is exactly pixel.
The distortion of image can be divided into barrel distortion and pincushion distortion, as depicted in figs. 1 and 2, Fig. 1 according to the difference of camera lens
It is the schematic diagram of barrel distortion, Fig. 2 is the schematic diagram of pincushion distortion.In figure, solid line is the line in actual picture, and dotted line is basis
In the photo that picture obtains, solid line generates the hook after distortion.That is, individually solid line is original picture, individually
Dotted line be according to picture obtain photo, Fig. 1 and Fig. 2 are the images for being formed by stacking original image and photo.In figure, P2,
P4 is the intersection point of two lines in original image, and P1, P3 are the friendships of the deformation lines of two lines in corresponding original image in photo
Point.
Distortion correction restores original image exactly on the basis of the photo of acquisition being distorted.By taking diagram as an example, just
It is the numerical value obtained in photo on P1 or P3 pixel, is written in correcting image, on P2 or P4 pixel.
Problem to be solved by this invention is obtained between fault image and correcting image, the corresponding relationship of each pixel,
And in subsequent processes, according to corresponding relationship, each pixel is handled.
The present invention includes two processes: the 1, calibration of camera lens, 2, the real-time correction of image.
The calibration of camera lens:
The distortion of image, can be with conic section come approximate fits: barrel distortion, can be with ellipse come approximate fits deformation
Line, pincushion distortion can be with hyperbola come approximate fits hook.
For convenience of description, the photo that we will be obtained by camera lens, center are set as coordinate origin, across the water of origin
Horizontal line and vertical line are that X-axis and Y-axis form coordinate system.In X-axis and Y-axis, it is believed that be not pattern distortion, other portions
Position, according to the difference of camera lens, can generate barrel distortion and pincushion distortion, further away from coordinate origin, distort more serious.Such as Fig. 3 institute
Show, is the schematic diagram carried out to barrel distortion after ellipse fitting, the photo that intermediate interdigitated part is.Fig. 3 is one and shows
It is intended to, in actual fitted figure, elliptical long axis is very long.It can be seen that being deformed in the whole sub-picture of a series of ellipse fitting
The distortion of line such as upwards and to the right from origin, is done an ellipse every a pixel, is calculated oval by intensively selecting ellipse
The coordinate value of upper each point, the coordinate value of available whole secondary fault image each point.
Each point on fault image, can regard two elliptical intersection points as, fault image and correcting image it
Between, the corresponding relationship of this point, as shown in Figure 1, P1 point corresponds to P2.The coordinate of P2 is exactly two ellipses by P1, with X
The value of axis and the intersection point of Y-axis away from origin.
The real-time correction of image:
CPU is written into above-mentioned corresponding relationship, when work, CPU obtains a pixel on fault image, finds this point
Two ellipses, pixel of this on correction image is obtained according to ellipse, the data of corresponding fault image pixel are write
The new pixel position on correcting image forms media file, completes the real-time correction of fault image.
The above is the processing for barrel distortion image, and for pincushion distortion, principle is identical, only changes ellipse into hyperbolic
Line, it is no longer redundant later here.
In addition, since anamorphose causes overlapping, the missing of pixel, it can be using prior arts means such as bilinear interpolations
It is handled.
The method have the benefit that: the pattern distortion correction algorithm based on circular cone line of present disclosure, is one
The completely new pattern distortion correction algorithm of kind.It selects hyperbola or elliptic equation from the shape of morphological analysis lens distortion
Distortion is simulated, relevant parameter is calculated according to distortion degree automatically, and by the corresponding relationship of distortion front and back, according to pixel
It calculates one by one, generates corresponding relationship.Compared with traditional correction algorithm, either principle or operation is all extremely simple, can be certainly
The camera lens of dynamic adaptation different distort shapes and aberration rate.For a collection of camera lens, a progress calibrated and calculated is chosen, calculated result can
It is embedded into various hardware devices, in actual operation, the CPU of embedded equipment reads the image obtained, according to pair of write-in
It should be related to, acquisition of being tabled look-up corrects pixel address and completes to replace, and realizes the correction of image.Using the present invention, CPU can be reduced
Configuration requirement, while image is corrected to the maximum extent, obtains acceptable correcting image.
The present invention is described in detail with reference to the accompanying drawing.
Specific embodiment
The present invention includes two parts: 1, the calibration process of camera lens and 2, real-time correcting process.
As shown in Figure 10, the calibration process of camera lens is to obtain the photo with grid picture first, according to what is distorted on photo
Hook judges distortion type, and then obtains equation of conic section, and the coordinate of each point on hook is calculated further according to curvilinear equation
Value, is finally calculated the corresponding relationship between fault image and correcting image pixel.
The CPU of obtained corresponding relationship write-in embedded system is subjected to real-time correcting process when embedded system works,
As shown in figure 11, fault image is obtained first, corresponding relationship is then read, according to corresponding relationship, by the pixel in fault image
Information, conversion position are written in correcting image file, complete the real-time correction of image.
Concrete implementation is described as follows:
The calibration process of camera lens:
A kind of pattern distortion antidote based on conic section, it is abnormal using oval or Hyperbolic Equation formula analog image
Become, the pixel quantity for the camera lens that distorts is H*W, comprising the following steps:
Step 1: one there is the picture of rectangular or square lattice, before being placed on distortion camera lens, picture and camera lens
Keeping parallelism, shoots the photo of the picture, and photo center is a crosspoint of grid, the horizontal direction across crosspoint
Grid lines be in the horizontal position in photo center;
Fig. 1 is the schematic diagram of barrel distortion, and Fig. 2 is the schematic diagram of pincushion distortion.In figure, solid line is the net in actual picture
Lattice, dotted line are in the photo obtained according to picture, and solid line generates the hook after distortion.That is, individually solid line is former
The picture of beginning, individual dotted line are the photos obtained according to picture, and Fig. 1 and Fig. 2 are to be formed by stacking original image and photo
Image.When selecting picture, when guaranteeing lines and intersection point clearly, hachure pattern is selected as far as possible.
Step 2: on photo, using above-mentioned grid intersection as origin, two grid lines across crosspoint are X-axis and Y
Axis, the distance in X-axis between two neighboring pixel is length unit, establishes plane right-angle coordinate;
As shown in Figure 4 and Figure 5, coordinate system is established.The pixel coordinate (Ox, Oy) of origin o is read, other pixels are being sat
Position in mark system can be calculated according to the location of pixels of the point and the location of pixels of origin.Due to the lines ratio in picture
Relatively thick, the crosspoint on photo may include that multiple pixels take the average value of each pixel coordinate position in a little in this case
Coordinate position as intersection point.
Step 3: according to photo, judging pattern distortion type;
Step 4: the approximate conic for the hook that grid lines is distorted in horizontal and vertical direction is obtained according to photo
The equation of line;
Picture is put into computer, above-mentioned two step is completed.
Above-mentioned two step can have been manually done, and can also be automatically performed with computer.
It has been manually done:
Photo is shown to the metamorphosis for visually observing hook on a display screen, determines pattern distortion type;According to abnormal
Become type, selection is oval by hand or hyperbola, modification parameter of curve are fitted the hook of a horizontal direction in photo, record
The parameter of conic section after fitting obtains the equation of the approximate conic section of the horizontal direction hook:
When barrel distortion, conic section is ellipse, elliptic equation are as follows: X2/a12+Y2/b12=1, a1 > b1 > 0,
When pincushion distortion, conic section is hyperbola, Hyperbolic Equation formula are as follows: Y2/a22-X2/b22=1, a2 > 0, b2 > 0;
As shown in figure 3, L1-x is the elliptic curve of hook.
For a camera lens, can be simply considered that, the distortion of horizontal direction and vertical direction is consistent, therefore, from
The hook fit equation that above-mentioned steps obtain, the approximate circular cone of available pattern distortion vertical direction corresponding position hook
The equation of curve:
When barrel distortion, conic section is ellipse, elliptic equation are as follows: Y2/a12+X2/b12=1, a1 > b1 > 0,
When pincushion distortion, conic section is hyperbola, Hyperbolic Equation formula are as follows: X2/a22-Y2/b22=1, a2 > 0, b2 > 0;
The corresponding position are as follows: vertical direction hook is with X-axis intersection point away from the horizontal direction for being equal to fitting at a distance from origin
Hook and Y-axis intersection point away from origin at a distance from, referring to Fig. 3, L1-y is L1-x in vertical direction corresponding position hook.
In order to more accurately, individually be fitted: photo be shown on a display screen, according to abnormal to the hook of vertical direction
Become type, select conic section by hand, modify parameter of curve, is fitted the hook of a vertical direction in photo, record fitting
The parameter of conic section afterwards obtains the equation of the approximate conic section of the vertical direction hook:
When barrel distortion, conic section is ellipse, elliptic equation are as follows: Y2/a32+X2/b32=1, a3 > b3 > 0,
When pincushion distortion, conic section is hyperbola, Hyperbolic Equation formula are as follows: X2/a42-Y2/b42=1, a4 > 0, b4 > 0.
Computer is automatically performed judgement distortion type:
In the horizontal direction on a hook, the intersection point D1 and D2 of two with vertical direction hook are chosen, two points
Coordinate is D1 (x1, y1), and D2 (x2, y2), the condition of selection is abs (x1) ≠ abs (x2) or abs (y1) ≠ abs (y2), if
The absolute value of x coordinate and the absolute value of y-coordinate of one of point are both greater than another point, then pattern distortion type is that pincushion is abnormal
Become, otherwise, pattern distortion type is barrel distortion;
Alternatively, on one hook of vertical direction, two intersection point D3 and D4 with horizontal direction hook are chosen, two
The coordinate of point is D3 (x3, y3), and D4 (x4, y4), the condition of selection is abs (x3) ≠ abs (x4) or abs (y3) ≠ abs (y4),
If the absolute value of x coordinate and the absolute value of y-coordinate of one of point are both greater than another point, pattern distortion type is pillow
Shape distortion, otherwise, pattern distortion type are barrel distortion.
As shown in figure 4, selection two points of D1, D2, the X-coordinate value of D1 is less than the X-coordinate value of D2, and the Y-coordinate value of D1 is greater than
The Y-coordinate value of D2, therefore Fig. 4 is barrel distortion;Or selection two points of D3, D4, the Y-coordinate value of D3 are greater than the Y-coordinate value of D4,
The X-coordinate value of D3 is less than the X-coordinate value of D4, therefore Fig. 4 is barrel distortion;
As shown in figure 5, selection two points of d1, d2, the absolute value of the X-coordinate of d2 and the absolute value of Y coordinate are both greater than d1's
X-coordinate absolute value and Y coordinate absolute value, therefore Fig. 5 be pincushion distortion;Or selection two points of d3, d4, it can also obtain
Above-mentioned conclusion out.
Computer automatically generates equation of conic section:
If it is barrel distortion, conic section is ellipse, and the coordinate value of D1, D2 are substituted into formula X by such as Fig. 42/a2+Y2/b2
=1, it solves equation to obtain the elliptic equation of the horizontal direction hook L2-x where D1, D2: X2/a12+Y2/b12=1, a1 > b1 >
0;
If it is pincushion distortion, conic section is hyperbola, such as Fig. 5, and the coordinate value of d1, d2 are substituted into formula Y2/a2-X2/
b2=1, it solves equation to obtain the Hyperbolic Equation formula of the horizontal direction hook L3-x where d1, d2: Y2/a22-X2/b22=1, a2 >
0, b2 > 0;
The almost the same reason of distortion based on horizontal direction and vertical direction, obtains pattern distortion vertical direction and corresponds to position
Set the equation of the approximate conic section of hook:
When barrel distortion, conic section is ellipse, elliptic equation are as follows: Y2/a12+X2/b12=1, a1 > b1 > 0,
When pincushion distortion, conic section is hyperbola, Hyperbolic Equation formula are as follows: X2/a22-Y2/b22=1, a2 > 0, b2 > 0;
The corresponding position are as follows: vertical direction hook is with X-axis intersection point away from the level where being equal to D1, D2 at a distance from origin
Direction distortion line and Y-axis intersection point away from origin at a distance from, in Fig. 4 and Fig. 5, L2-x and L2-y, L3-x and L3-y are corresponding position
Hook.
In order to more accurately, be individually fitted to the hook of vertical direction: if it is barrel distortion, as shown in figure 4, circle
Boring curve is ellipse, and the coordinate value of D3, D4 are substituted into formula Y2/a2+X2/b2=1, it solves equation to obtain the vertical side where D3, D4
To the elliptic equation of hook: Y2/a32+X2/b32=1, a3 > b3 > 0;
If it is pincushion distortion, as shown in figure 5, conic section is hyperbola, the coordinate value of d3, d4 are substituted into formula X2/
a2-Y2/b2=1, it solves equation to obtain the Hyperbolic Equation formula of the vertical direction hook where d3, d4: X2/a42-Y2/b42=1, a4
> 0, b4 > 0.
Above-mentioned steps have obtained the circular cone equation of horizontal direction and each hook of vertical direction.
Step 5: according to equation, obtaining the corresponding relationship of fault image and correcting image pixel;
Initially set up two fault image concordance lists, in concordance list 1, content is y-axis coordinate in index key and table
Value;In concordance list 2, content is x-axis coordinate value in index key and table.The initial configuration of concordance list is as follows:
Concordance list 1
Concordance list 2
Step 5.1, concordance list 1 is initially set up:
Step 5.1.1, the horizontal direction hook obtained according to step 4 equation of conic section f (x, y)=1, x value [-
W/2, W/2], corresponding y value is successively calculated in x ∈ N, and the difference of two neighboring x is 1;If it is barrel distortion, f (x, y)=
X2/a12+Y2/b12, if it is pincushion distortion, f (x, y)=Y2/a22-X2/b22。
Store above-mentioned coordinate value, and y value when using x=0 is as index key;
It records p0=abs (y), y is above-mentioned index key;
The concordance list that the first step generates is as follows:
Concordance list 1
Increase by two rows in concordance list, index key is that the xxxx for p0 and-p0, in table is corresponding X value respectively, with ellipse
For circle, according to formula y=± b1 (1-x2/a12)1/2The y value calculated.In this way, by the ellipse of p0 point in Y-axis and-p0 point
Circle, both the coordinate of all the points had been found out on two hooks.
In experimenting, we find out that, the hook in same direction, can be such as barrel-shaped abnormal with a general formula come approximate representation
The general formula of change are as follows: K* (x2/a2+y2/b2)=1, a > b > 0, the general formula of pincushion distortion are as follows: K* (x2/a2-y2/b2)=1, a > 0, b >
0。
In the following, by taking barrel distortion as an example, using known elliptic equation and above-mentioned principle, using following methods find out by
The coordinate of each point on the hook of each integral point of Y-axis.
Step 5.1.2, finds out each ellipse formula first: p value [1, p0) ∪ (p0, H/2], the difference of two neighboring p is 1,
For each p, coordinate value (0, p) is updated to equation K*f (x, y)=1, obtains K value:
K*(0/a12+p2/b12)=1, K=b12/p2,
And then the ellipse formula b1 of p point is obtained2/p2*( x2/a12+ y2/b12)=1。
Step 5.1.3, according to formula derived above, x value [- W/2, W/2], corresponding y value is calculated in x ∈ N,
The difference of two neighboring x is 1;
Store above-mentioned coordinate value, and y value when using x=0 is as index key.
It, can using the coordinate and K value by all the points on the ovalizing deflection line of p0 point in Y-axis and-p0 point found out
With the alternatively approximate y value for finding out each point on other hooks:
Referring to Figure 12, it is known that the elliptic equation for crossing P0 point is X2/a12+Y2/b12=1,
The elliptic equation for crossing P point is K* (X2/a12+Y2/b12)=1,
By the straight line of X=x0, y value with above-mentioned two elliptical intersection point:
P0y2=(1-x02/a12)*b12
Py2=(1/K-x02/a12)*b12
P0y2/Py2= K* ( a12-x02)/(a12-K*x02)
Since elliptical focus is far away from coordinate origin, a1 is much larger than x0, therefore, P0y2/Py2Approximation be K, have Py=
±P0y/K1/2。
According to relation above, design factor is the Y value of each point coordinate on the ellipse of K:
py=±p0y/K1/2,
Wherein, p0y is the Y coordinate of each point on the ellipse found out, and py is the Y coordinate on the ellipse to be calculated, p0y and py
Corresponding identical x value, the value range of x is [- W/2, W/2], x ∈ N.
Store above-mentioned coordinate value, and py value when using x=0 is as index key;
Now, complete concordance list 1 has been obtained.In concordance list 1, storage is horizontally oriented each point on straight line, generates abnormal
Position coordinates of the hook on photo after change.Shared H+1 item, distance of the adjacent deformations line in Y-axis between intersection point is 1 picture
Element, the distance of consecutive points horizontal direction are 1 pixels, and index key is the intersecting point coordinate of the hook and Y-axis.
Index key in concordance list 1 is the coordinate value of hook and y-axis intersection point, and the content in table is y-axis coordinate value.
Some data in concordance list 1 form coordinate data with corresponding X value.
Concordance list 2 is established using similar method:
Step 5.2.1, the conic for the vertical direction hook that the distortion type and step 4 obtained according to step 3 obtains
Line equation g (x, y)=1, y value [- H/2, H/2], y ∈ N, are calculated corresponding x value, and the difference of two neighboring y is 1;With ellipse
For, g (x, y)=Y2/a12+X2/b12Or g (x, y)=Y2/a32+X2/b32。
Store above-mentioned coordinate value, and x value when using y=0 is as index key;
It records q0=abs (x), x is above-mentioned index key;
Step 5.2.2, q value [1, q0) and ∪ (q0, W/2], the difference of two neighboring q is 1, for each q, by coordinate value
(q, 0) is updated to equation M*f (x, y)=1, obtains M value;
Step 5.2.3, according to above-mentioned formula, y value [- H/2, H/2], y ∈ N is calculated corresponding x value, and adjacent two
The difference of a y is 1;
Store above-mentioned coordinate value, and x value when using y=0 is as index key;
Equally, the coordinate and M by all the points on the ovalizing deflection line of q0 point in Y-axis and-q0 point found out is utilized
Value, can alternatively the approximate x value for finding out each point on other hooks, method be consistent with the above.
Concordance list 2 is established according to above-mentioned steps;
In concordance list 2, storage is each point on vertical direction straight line, position of the hook after generating distortion on photo
Coordinate.Shared W+1 item, distance of the adjacent deformations line in Y-axis between intersection point is 1 pixel, and the distance of consecutive points vertical direction is 1
A pixel, index key are the intersecting point coordinates of the hook and X-axis.
Index key in concordance list 2 is the coordinate value of hook and x-axis intersection point, and the content in table is x-axis coordinate value.
Some data in concordance list 2 form coordinate data with corresponding Y value.
In above-described embodiment, elliptic equation is used.When handling pincushion distortion, using Hyperbolic Equation, the two it
Between difference be to use the difference of function, the principle of calculating is the same, no longer describes.
Step 5.3, according to two concordance lists, the corresponding relationship of fault image and correcting image pixel is established:
In this example, corresponding relationship is a bivariate table, and the size of table is H*W, and the content in table is coordinate value.The structure of table
It is as follows:
Corresponding relationship bivariate table
Referring to Fig. 1, position of the P1 point in correcting image in fault image is P2 point, acquires bivariate table according to this principle
In content.
The data of the position [i, j] are expressed as P (i, j) in table, wherein and i, j are integer ,-W/2≤i≤W/2 ,-H/2≤j≤
H/2。
The value of P (i, j) determines as follows:
Using i as the index key of concordance list 2, j is the index key of concordance list 1;
In two concordance lists, find identical under two index keys, jointly owned coordinate value, both sat in other words
Data are marked, the coordinate data found is (x, y), in bivariate table, P (i, j)=(x, y).
The practical significance of the above process is the intersection point for looking for two curves, and in the ideal case, intersection point can pass through above-mentioned mistake
Journey is found.But a line is described here by a series of coordinate, be it is discrete, in calculating process, due to error
Presence, it is possible to can not find common coordinate data.If can not find identical coordinate value, find under two index keys
Immediate coordinate value, by position [i, j] in the average write-in bivariate table of two coordinate values.
By above step, the corresponding relationship of fault image and correcting image pixel is obtained, corresponding relationship is completed
Bivariate table;
Pixel is all integer, in calculating process, will appear decimal certainly.A kind of scheme is to generate corresponding relationship two
When dimension table, (x, y) round numbers partial write corresponding relationship bivariate table.In order to improve the quality of correcting image, can also protect always
Decimal is stayed, in real time when correction, after reading (x, y), x, y are rounded, and are obtained the information of central pixel point, further according to fractional part, are obtained
To the information of peripheral image vegetarian refreshments, the information of obtained pixel is weighted processing, information write-in correction is schemed by treated
As (i, j) location of pixels.
In above-described embodiment, corresponding relationship bivariate table is using camera lens center as coordinate origin, and general camera lens is with lower-left
Angle is pixel counts starting point.It, can be by corresponding relationship bivariate table by coordinate translation, by coordinate original in order to be more convenient when in use
Point is set in the lower left corner.It is as follows:
Corresponding relationship bivariate table
Real-time correcting process:
A kind of real-time apparatus for correcting of pattern distortion, it is embedding including embedded system and the video camera for being equipped with distortion camera lens
The corresponding relationship of fault image and correcting image pixel is stored in the CPU of embedded system;When apparatus for correcting works, CPU is read
The Pixel Information of each frame distortion image, according to corresponding relationship, translation bit postpones write-in correcting image file.
When equipment making, by corresponding relationship, both in the CPU of above-mentioned corresponding relationship bivariate table write-in embedded system.
When embedded system works, video camera obtains distortion in real time image by camera lens, and for each frame, CPU reads abnormal
Become the Pixel Information of image;For each pixel (i, j) ,-W/2≤i≤W/2 ,-H/2≤j≤H/2 read corresponding relationship
The data (x, y) of corresponding position in bivariate table;By the information of (x, y) pixel in fault image, be written correcting image (i, j) as
Plain position, correcting image form new media file, complete real-time correction.
If the value of (x, y) is integer, handled according to the method described above, if it is decimal, x, y are rounded, and obtain center
The information of pixel obtains the information of peripheral image vegetarian refreshments further according to fractional part, and the information of obtained pixel is weighted
Processing, by treated, correcting image (i, j) location of pixels is written in information.
By Fig. 6-9 as can be seen that can effectively correct barrel distortion and pincushion distortion using the present invention.
It detects card (ISO12233 resolution card) using image definition to test image, the figure of this method correction
Picture, horizontal and vertical direction loss of sharpness 2% or so, on picture quality influence less, can satisfy Car license recognition,
The monitoring requirements such as recognition of face.