Summary of the invention
The objective of the invention is: at the deficiencies in the prior art, provide a kind of simple and reasonable, need not external motion sensor and the device of the video electronic flutter-proof that can reduce cost.
In order to solve the problems of the technologies described above, the technical solution used in the present invention is: a kind of device of video electronic flutter-proof, the motion vector computation module and the jitter compensation module that comprise estimation computing module, overall relative motion vectors computing module, overall relative motion vectors memory module, compensate for jitter, wherein
Described estimation computing module is imported the image of present frame and reference frame, and calculates the relative motion vectors of the relative reference frame of search block in the present frame according to motion estimation algorithm;
Described overall relative motion vectors computing module is imported the relative motion vectors from the search block of the present frame of described estimation computing module, thereby obtains the overall relative motion vectors of present frame according to the relative motion vectors of each search block;
Described overall relative motion vectors memory module is used to store the overall relative motion vectors of present frame some two field pictures before;
The motion vector computation module of described compensate for jitter is according to the overall relative motion vectors of predicting present frame from the overall relative motion vectors of some frames before the present frame of storing in the overall relative motion vectors memory module, and quite motion vector and the motion vector computation module of described compensate for jitter are predicted the difference of the overall relative motion vectors of the present frame that obtains to calculate the overall situation of present frame of overall relative motion vectors computing module output, thereby judge whether to exist shake according to this difference, when having shake, the motion vector of shaking by way of compensation with described difference, when not having shake, the motion vector that makes compensate for jitter is 0; And whether the motion vector of judging described compensate for jitter is in the determined maximum compensation range of predefined maximum compensating motion vector value, if exceed this scope, then with the motion vector of described maximum compensating motion vector value as described compensate for jitter; The last motion vector of compensate for jitter of exporting again is to described jitter compensation module;
Total pixel image of described jitter compensation module input present frame, and according to the motion vector and the predefined valid pixel image size of described compensate for jitter, cutting obtains the effective image after the anti-shake compensation of present frame from total pixel image of present frame.
Further, can also comprise the pre-cut module, be used to import the overall relative motion vectors of each frame before total pixel image of present frame and the present frame, thereby obtain the absolute displacement value of the former frame image of present frame with respect to total pixel image center according to the overall relative motion vectors of each frame; And with this absolute displacement value definite center, clipping region on total pixel image of present frame, again according to the image size of predefined valid pixel, determine the clipping region with the center, clipping region, total pixel image to present frame carries out cutting at last, thereby the output size is the current frame video image of described valid pixel image size.
Further, can also comprise overall relative motion vectors correcting module, be used to import the overall relative motion vectors of the present frame of the motion vector of compensate for jitter of present frame and estimation gained, thereby, and export described overall relative motion vectors memory module to and store with the motion vector of described overall relative motion vectors and compensate for jitter overall relative motion vectors as revised present frame.
Further, also can comprise the reference frame storing module, be used for effective image of the present frame after the input jiffer compensation, reference frame when calculating as the next frame estimation.
Preferably, after described overall relative motion vectors computing module is imported the relative motion vectors of each search block, thereby the frequency of the relative motion vectors amplitude of described each search block of statistics obtains the relative motion vectors value that wherein frequency is the highest, and calculates the variance of described relative motion vectors; Judge then whether the highest relative motion vectors value of described frequency has surpassed the variance of the relative motion vectors of search block and the product of given threshold value in the image, if do not surpass, the overall relative motion vectors that then shows current frame image is not obvious, and the overall relative motion vectors of putting present frame is 0; Otherwise, with the overall relative motion vectors of the highest relative motion vectors value of described frequency as present frame.
Preferably, the motion vector computation module of described compensate for jitter can adopt the overall relative motion vectors of the method prediction present frame of curve fit, is specifically as follows:
At first, according to the overall relative motion vectors of preceding some frames of present frame, determine a multinomial of p time:
P(x)=w
px
p+w
p-1x
p-1+...+w
0
Wherein, x is relative frame number, and P (x) is that relative frame number is the overall relative motion vectors of the picture frame of x, and p is determined by the global motion pattern for describing the exponent number of overall relative motion vectors track;
Then, adopt described polynomial computation to obtain the overall relative motion vectors of present frame, be the overall relative motion vectors that forecasting institute gets.
Preferably, the motion vector computation module of described compensate for jitter judges whether to exist the method for shake specifically to can be according to the difference of the overall relative motion vectors of estimation and two kinds of method gained of prediction: at first, and the variance of the overall relative motion vectors of preceding some frames of calculating present frame; If: | the overall relative motion vectors of the present frame that overall relative motion vectors one estimation of the present frame that prediction obtains obtains | the variance of the overall relative motion vectors of preceding some frames of>K* present frame, represent that then there is shake in present frame, otherwise think not have shake, wherein 1≤K≤2.
Preferably, described jitter compensation module is on total pixel image of present frame, and according to the motion vector and the predefined valid pixel image size of compensate for jitter, the step of the effective image after the anti-shake compensation of cutting acquisition present frame specifically can comprise:
At first, be central point with the center of total pixel image of present frame, obtain the compensation central point according to the motion vector of compensate for jitter;
Then, be the center with described compensation central point, according to described valid pixel image size, on total pixel image of present frame, determine the clipping region;
At last, exporting image pixel in the described clipping region is effective image after the anti-shake compensation.
Preferably, processing to overall relative motion vectors in described each module all can be carried out from horizontal direction and vertical direction respectively, thereby the overall relative motion vectors of the final present frame that obtains is horizontal component and the vertical component by overall relative motion vectors to be constituted, the motion vector of the jitter compensation that is obtained also is made of its horizontal component and vertical component, and then to obtain effective image also be to carry out from horizontal direction and vertical direction respectively to the judgement of shake and cutting.
Preferably, described search block can be all macro blocks or the piece in the two field picture.
Preferably, described search block can be the data block of the pre-sizing in the two field picture, and described data block keeps at a certain distance away each other.
In technique scheme, a kind of video electronic flutter-proof device proposed by the invention is by image sequence being carried out estimation, analyze the motion conditions of photographed, eliminating shake thereby carry out motion compensation.The relative prior art of the present invention, need not external motion sensor, realize the estimation of motion, the compensation of dither image by digital image processing method fully, and have realize simple, effectively, the characteristics of low cost etc., can be applied in Digital Video, the first-class video acquisition device of shooting.
Embodiment
Below in conjunction with Figure of description and specific embodiment the present invention is described in further detail.
The electronic flutter-proof method that present embodiment proposes need not to add the motion compensation transducer and obtains motion state, but introduced the method for estimating of video coding technique, calculate the overall relative motion vectors of every frame by method for estimating, thereby obtain the overall relative motion vectors MV of present frame
NEstimated value, and the overall relative motion vectors MV by previous some frames
1, MV
2..., MV
N-1The overall relative motion vectors MV of prediction present frame
NIf MV
NAnd MV
NBetween the difference that exists greater than a certain given threshold value T, then think shake taken place, need carry out motion compensation; Otherwise keep original image and do not compensate.Its principle as shown in Figure 1.
Present embodiment can not utilize the collection pixel value of the CCD of all videos harvester in order to realize electronic flutter-proof, and therefore effectively pixel count is less than the total pixel number of CCD, and this is the situation that realizes that electronic flutter-proof must occur.And the ratio of the relative total pixel number of valid pixel number is related by the anti-shake jitter amplitude of supporting.Suppose maximum jitter that present embodiment supports by relative shifting range as index, the effective pixel area of given CCD is the center of the total pixel region of CCD, then the compensation range of Zui Da shake can not exceed the zone of the total pixel of CCD, therefore preestablishing the maximum compensating motion vector value of going up in the horizontal direction in the present embodiment is XMAX, maximum compensating motion vector value on the vertical direction is YMAX, then maximum compensation range in the horizontal direction is [XMAX, XMAX], maximum compensation range in vertical direction is [YMAX, YMAX].If the shake total size is positioned at this scope, then can compensate the realization electronic flutter-proof; If surpass this scope, then do not carry out electronic flutter-proof.The total pixel of CCD, the relation of the valid pixel after valid pixel and the anti-shake compensation as shown in Figure 2.
With reference to figure 3, the idiographic flow that present embodiment carries out video electronic flutter-proof is:
The overall relative motion vectors of some frame video images before step 1, employing method for estimating calculating present frame and the present frame;
Step 2, according to the overall relative motion vectors of the overall relative motion vectors prediction present frame of some frames before the present frame;
The difference of the overall relative motion vectors of the present frame that obtains in step 3, calculation procedure 1 and the step 2, and judge whether to exist shake according to this difference, and when having shake, the motion vector of shaking by way of compensation with described difference, when not having shake, the motion vector that makes compensate for jitter is 0;
Step 4, judge that the motion vector of described compensate for jitter is whether in the determined maximum compensation range of predefined maximum compensating motion vector value, if exceed this scope, then with the motion vector of described maximum compensating motion vector value as described compensate for jitter;
Step 5, on total pixel image of present frame, according to the motion vector and the predefined valid pixel image size of described compensate for jitter, cutting obtains the effective image after the anti-shake compensation of present frame.
In above-mentioned steps, the order of step 1 and step 2 can be changed.For the overall relative motion vectors that makes present frame estimate with prediction accurately but amount of calculation is relative less, adopt the F two field picture before the present frame in the present embodiment.
In above-mentioned steps, the video image that is used to carry out estimation can be total pixel image, also can be effective image of the valid pixel size after the compensate for jitter.Adopt effective image in the present embodiment.
Based on above-mentioned flow process, present embodiment provides a kind of device of video electronic flutter-proof, comprise the motion vector computation module and the jitter compensation module of estimation computing module, overall relative motion vectors computing module, overall relative motion vectors memory module, compensate for jitter, also comprise pre-cut module, overall relative motion vectors correcting module and reference frame storing module in addition.
Below in conjunction with the device of present embodiment shown in the accompanying drawing 4, describe the principle of present embodiment device in detail.
(1) pre-cut module
This module is input as the overall relative motion vectors of each frame before total pixel image of the present frame that the video acquisition module (as CCD) of video acquisition and output device gathers and the selected present frame, is output as the image of the image size (being the valid pixel size) of actual displayed.
Suppose that total pixel image size that CCD gathers is M * N, the image size of valid pixel is M ' * N '.We use MV
X(i) and MV
Y(i) expression i two field picture is with respect to the relative motion vectors of i-1 two field picture.When i=1, the valid pixel image is positioned at the center of total pixel image, first two field picture in the expression video sequence, and at this moment initial value is respectively MV
X(1)=0, MV
Y(1)=0.We also need the absolute displacement (the just relative motion vectors of 1st frame) of i frame with respect to total pixel center position, use SMV respectively
X(i) and SMV
Y(i) expression.This value is obtained by following formula:
Absolute displacement has important effect in the anti-shake computing of every two field picture, absolute displacement can not surmount the restriction relation between total pixel and the valid pixel image, can be expressed as:
-XMAX≤SMV
X(i)≤XMAX
-YMAX≤SMV
Y(i)≤YMAX
When input i frame M * N sized images, according to the SMV of i-1
X(i) and SMV
Y(i) on total pixel image of present frame, determine the center, clipping region, according to the image size of predefined valid pixel current i two field picture is carried out cutting then, form the image of M ' * N '.For first frame data because SMV
XAnd SMV (1)=0
Y(1)=0, therefore the zone of actual cutting is the image of the M ' * N ' of the center of image.Figure 5 shows that three two field pictures after the cutting concern schematic diagram with respect to the position of total pixel image.Wherein, image A is total pixel image size that CCD gathers, and its center is the o point; Image B is the 1st two field picture after the cutting, and its center overlaps with the center of image A; Image C is (i-1) two field picture after the cutting, and its center is o ', and absolute the relative displacement of the 1st frame (just with respect to) displacement of its relative image B is SMV
x(i-1) and SMV
y(i-1); Image D is i frame (the being present frame) image after the cutting, and its center is o ", the absolute displacement of its relative image B is SMV
xI and SMV
yI, the relative motion vectors of its relative image C is MV
X(i) and MV
Y(i).
(2) estimation computing module
The estimation computing module is input as the i two field picture of the M ' * N ' after the cutting and i-1 two field picture as the reference two field picture.Be output as the relative motion vectors of i two field picture with respect to the i-1 two field picture.
Method for estimating can adopt based on the method for estimating in the video-frequency compression method, is that search block is carried out estimation with piece and macro block.At this moment can obtain the relative motion vectors of each macro block in the image or piece by estimation, as the input of overall relative motion vectors computing module.
Present embodiment recommend to adopt MPEG and H.26X waits motion estimation module in the video encoding standard to be applied directly to the motion estimation module of present embodiment.These methods can be easy to realize that directly use, shortcoming is that the method for estimating operand in the common video encoder is bigger.
Adopt a kind of method for estimating of simplification in the present embodiment, this method need not that the data block of all images is carried out estimation can significantly reduce operand, improves actual application value.
With reference to the accompanying drawings shown in 6, in this method for estimating, search block does not adopt the macro block described in the video encoder and the mode of piece, search block in this method is can be self-defining, usually select 8 * 8, the data block of 16 * 16 sizes, and the selection of search block is not entire image, but with certain partial data piece at interval.Search for the best match position in given zone of these data blocks.Be motion vector with the relative position of reference position.The motion match method still can adopt searching algorithm and matching criterior commonly used in the video encoder, for known technology is not described further here.
(3) overall relative motion vectors computing module
What this module was imported is the relative motion vectors of a plurality of search block of motion estimation module acquisition, is output as the overall relative motion vectors of the present frame that obtains by method for estimating.
The result who supposes the motion estimation module search is a L relative motion vectors.Add up the frequency of level and vertical motion vector amplitude respectively, suppose that the highest relative motion vectors value of frequency is respectively mvx
F, mvy
FRelative motion vectors is carried out statistical analysis, calculate variance and be respectively D
xAnd D
y
The principle that obtains overall relative motion vectors by method for estimating in the present embodiment is: judge whether current overall relative motion has surpassed the variance of the relative motion vectors of piece and the product of given threshold value in the image, if variance ratio is bigger, motion state in the key diagram picture is comparatively complicated, and the consistent relatively motion of the overall situation is not obvious, otherwise, the motion that the then explanation overall situation is consistent relatively is obvious, has overall relative motion vectors.
Be embodied as:
If mvx
F<D
xT
x, show that the horizontal direction overall situation relative motion vectors of present image is not obvious, the horizontal component MVX (i)=0 of overall relative motion vectors is arranged; Otherwise show horizontal component MVX (the i)=mvx that has overall relative motion vectors
F
If mvy
F<D
yT
y, show that the vertical direction overall situation relative motion vectors of present image is not obvious, the vertical component MVY (i)=0 of overall relative motion vectors is arranged; Otherwise show vertical component MVY (the i)=mvy that has overall relative motion vectors
F
For given threshold value T
xAnd T
yDecide according to concrete the application respectively, recommend 1≤T here
x, T
y≤ 2.
(4) the motion vector computation module of compensate for jitter
That this module is imported is overall relative motion vectors MVX (i) and MVY (i), the wherein 1≤i≤F-1 of preceding F-1 frame.Output is the image motion vector CMVX (F) and the CMVY (F) of the compensate for jitter of present frame.
A kind of method commonly used adopts curve fit, supposes that the data that preceding F-1 frame is arranged can determine a multinomial of P time
P(x)=w
Px
P+w
P-1x
P-1+...+w
0
Here x is relative frame number, and first frame that we can select the F-1 frame is that 1, the second frame is that 2, the F-1 frames are F-1, and present frame is F.Output P (x) is the overall relative motion vectors of level or vertical direction.The p here sets according to actual conditions, for describing the exponent number of global motion vector track.For multiple normal global motion pattern, as at the uniform velocity taking photo by plane, become from speed 0 and at the uniform velocity to take photo by plane etc. and can describe by a multinomial of P time.As when the global motion pattern when at the uniform velocity taking photo by plane, p gets 1, when even the acceleration, p gets 2.Usually when calculating, the p value requires to choose according to the motion of actual support, and the motion of the high more description of p is also just complicated more, and general p≤5 just can be satisfied common motion and required.
By match, respectively the overall relative motion vectors of the present frame of horizontal direction and vertical direction is predicted that can obtain predicted current frame overall situation relative motion vectors is MVX (F) and MVY (F) to preceding F-1 two field picture.
The variance of F frame overall situation relative motion vectors is respectively before calculating simultaneously: DMVX (F) and DMVY (F), and, can determine the motion vector of compensate for jitter by following formula for COEFFICIENT K given in advance:
If | MVX (F)-MVX (F) |>KDMVX (F), represent that then may there be shake in the present level direction, then needs to compensate, CMVX (F)=MVX (F)-MVX (F) is then arranged, otherwise think not have shake, belong to normal moving range, CMVX (F)=0 is then arranged.
If | MVY (F)-MVY (F) |>KDMVY (F), represent that then may there be shake in current vertical direction, then needs to compensate, CMVY (F)=MVY (F)-MVY (F) is then arranged, otherwise think not have shake, belong to normal moving range, CMVY (F)=0 is then arranged.
The COEFFICIENT K here is recommended as 1≤K≤2.
As previously mentioned, because present embodiment only just carries out effective jitter compensation in the jitter compensation scope, therefore, the judgement formula
-XMAX≤CMVX(F)≤XMAX
-YMAX≤CMVY(F)≤YMAX
Whether set up,, show that the shake total size is positioned at maximum compensation range, directly exports the horizontal component CMVX (F) and the vertical component CMVY (F) of the motion vector of compensate for jitter if set up.If one of them is false or the two all is false, promptly in the horizontal direction and/or vertical direction exceeded maximum compensation range, then with described maximum compensating motion vector value XMAX and/or YMAX horizontal component and/or vertical component output as the motion vector of described compensate for jitter.
(5) jitter compensation module
The input of this module be the motion vector CMVX (F) of compensate for jitter and CMVY (F) and present frame big or small be the total pixel image of M * N, according to the effective pixel area of the M ' * N ' size of motion vector cutting relevant position, thereby be output as effective pixel area after the anti-shake compensation.Be specially:
At first, be central point (as the point of the o among Fig. 5) with the center of total pixel image of present frame, obtain compensation central point (as the o among Fig. 5 " point) according to the motion vector of compensate for jitter;
Then, be the center with described compensation central point (as the o among Fig. 5 " point), according to described valid pixel image size M ' * N ', on total pixel image of present frame, determine the clipping region;
At last, exporting image pixel in the described clipping region is effective image after the anti-shake compensation.
(6) overall relative motion vectors correcting module
Owing to carried out anti-shake compensation,, therefore need revise the overall relative motion vectors of F frame so the F frame with respect to the relative motion position of F-1 frame variation has taken place.
The overall relative motion vectors MVX (F) and the MXY (F) of the motion vector CMVX (F) of the compensate for jitter of this module input present frame and the present frame of CMVY (F) and estimation gained, thereby according to the following formula correction,
MVX(F)=MVX(F)-CMVX(F)
MVY(F)=MVY(F)-CMVY(F),
And export described overall relative motion vectors memory module to and store
(7) overall relative motion vectors memory module
Owing to need the overall relative motion vectors of front F frame in the calculating of anti-shake compensating motion vector.Therefore the overall relative motion vectors of F frame before preserving by Global Vector Memory.
(8) reference frame storing module
Owing to adopted the method for estimation, therefore the image that needs former frame then is kept at the former frame image in the reference frame storing module as the reference frame, is used for the estimation of current frame image.
The anti-shake example of a reality as shown in Figure 7.The frame preface that Digital Video is taken is Frame 1, Frame2, and Frame 3, and Frame 4.Generation along with shake constantly compensates, but the region limits of compensation is in the scope of total pixel region.
The advantage of present embodiment is to need not to add motion sensor device based on the anti-fluttering method of estimation, and carries out the prediction of motion vector from the Digital Image Processing angle merely, realizes anti-shake.Present embodiment eliminated since video camera follow shot situation hypograph owing to the anti-shake jumping phenomena that causes.
It is anti-shake that the anti-shake technology of present embodiment is based on dynamic image, can be applied to equipment such as camera, Digital Video.