Atomatic focusing method and device
Technical field
The present invention relates to Autofocus Technology field more particularly to a kind of Atomatic focusing methods and device.
Background technology
Auto-focusing is essential key technology in contemporary optics imaging system, with the hair at full speed of science and technology
Exhibition, vernier focusing problem in digital imaging system by people common concern.Auto-focusing refers to by camera
Focusing mechanism changes object distance and position apart, makes the process of the imaging clearly of made thing body.With the quick hair of electronic equipment
Exhibition, the various electronic equipment uses comprising shooting function are more and more frequent, and requirement of the user to automatic focusing function is also increasingly
It is high.
Imaging device clearly image in order to obtain, needs to scheme imageable target by the Focusing module in imaging device
As sensor, such as complementary metal oxide semiconductor (CMOS, Complementary Metal-Oxide Semiconductor)
Or the imaging of charge coupling device (CCD, Charge Coupled Device) plane is in focusing state, i.e., so that image distance, object
Away from and focal length meet 1/u+1/v=1/f, wherein u is apart, v is object distance, and f is focal length.In the process that auto-focusing is realized
In, mainly by adjusting the distance between camera lens and imaging sensor, i.e. image distance so that imageable target can be in image sensing
Blur-free imaging on device.
During the auto-focusing of imaging device, with the movement of camera lens, the clarity of imaging is led in variation is not stopped
Imaging device can obtain maximum contrast in shape library state hypograph in the case of often, and imaging device can be according to image
The situation of change of contrast between pixel obtains the focusing position of imaging device, but imaging device is according to single image slices
Contrast extracting mode between element is highly susceptible to the influence of picture noise, it is difficult to accurately reflect the focusing of imaging device reality
State is easy to cause focusing failure, and during imaging device auto-focusing, imaging device is every under big noise circumstance
Secondary focusing is required to restore camera lens to fixed initial position, then starts to push camera lens and samples figure at different lens locations
The contrast of picture, and then determine according to acquired contrast the focusing position of imaging device, the above process due to focusing every time
Be required to since initial position search for focusing position, there are focusing speed it is slower the problem of.
Invention content
The present invention solves the problems, such as it is the problem of being difficult to accurate focusing and slower focusing speed.
To solve the above problems, technical solution of the present invention provides a kind of Atomatic focusing method, the method includes:
It obtains camera lens and often moves the imaging device obtained correspondence lens location described in the first step-length along the first direction
The first image, the focusing direction and first position of the camera lens are determined according to the contrast of described first image;
The camera lens is obtained to move described in the second step-length imaging along the focusing direction is every since the first position and set
Second image of the standby obtained correspondence lens location, the second position is determined according to the contrast of second image;
Determine focusing range, the focusing range is the region centered on the second position;
The mobile camera lens in the focusing range, by acquired in the imaging device in the focusing range it is each
Lens location in lens location corresponding to the image of contrast maximum is determined as the focusing position of the camera lens.
Optionally, the first direction is perifocus or the over focus movement from camera lens current location to the imaging device
Direction.
Optionally, the contrast includes the first contrast and the second contrast, and first contrast is according to described right
The luminance difference between pixel in burnt region is determined, and second contrast is according to the image in the focusing area
Luminance difference between block is determined.
Optionally, first contrast is determined by equation below:
Wherein, VpFor first contrast, M is the horizontal resolution of the focusing area, and N is the focusing area
Vertical resolution, i and j are respectively the horizontal and vertical index value of the pixel in the focusing area, and L (i, j) is described
The brightness value of the pixel at (i, j) position in focusing area;
Second contrast is determined by equation below:
Wherein, VbFor second contrast, X is the image block contained by horizontal direction after the focusing area piecemeal
Number, numbers of the Y for the image block contained by vertical direction after the focusing area piecemeal, s and t are respectively the focusing area
The horizontal and vertical index value of interior image block, LB (s, t) are picture in the image block at (s, t) position in the focusing area
The average brightness value of vegetarian refreshments.
Optionally, the focusing direction of the determining camera lens and the process of first position include:
The first contrast and the second contrast of corresponding each first image are obtained respectively;
If the maximum value of the first contrast of each first image and the ratio of minimum value are greater than or equal to first threshold,
The focusing direction for then determining the camera lens is the maximum that first contrast is changed to from the minimum value of first contrast
The moving direction of the lens location of value, the first position is corresponding to the minimum value of the first contrast of each first image
Lens location.
Optionally, the focusing direction of the determining camera lens and the process of first position further include:
If the maximum value of the first contrast of each first image and the ratio of minimum value are less than the first threshold, institute
The ratio of maximum value and minimum value for stating the second contrast of each first image is greater than or equal to the first threshold and the first number
According to more than the second data, it is determined that the focusing direction of the camera lens is to change to described the from the minimum value of second contrast
The moving direction of the lens location of the maximum value of two contrasts, the first position are the second contrast of each first image
Minimum value corresponding to lens location, first data are right for the maximum value of the second contrast of each first image
First contrast of the first image got at the lens location answered, second data for each first image the
First contrast of the first image got at the lens location corresponding to the minimum value of two contrasts.
Optionally, the focusing direction of the determining camera lens and the process of first position include:
The first contrast and the second contrast of corresponding each first image are obtained respectively;
If the maximum value of the second contrast of each first image and the ratio of minimum value are greater than or equal to first threshold
And first data be more than the second data, it is determined that the focusing direction of the camera lens is to change from the minimum value of second contrast
To the moving direction of the lens location of the maximum value of second contrast, the first position for each first image the
Lens location corresponding to the minimum value of two contrasts, first data for each first image the second contrast most
The first contrast of the first image got at the corresponding lens location of big value, second data are described each first
First contrast of the first image got at the lens location corresponding to the minimum value of the second contrast of image.
Optionally, the focusing direction of the determining camera lens and the process of first position further include:
If the maximum value of the second contrast of each first image and the ratio of minimum value are less than the first threshold, and
The maximum value of first contrast of each first image and the ratio of minimum value are greater than or equal to first threshold, determine the mirror
The focusing direction of head is the lens location for the maximum value that first contrast is changed to from the minimum value of first contrast
Moving direction, the first position for each first image the first contrast minimum value corresponding to lens location.
Optionally, the process of the determining second position includes:
Obtain the first contrast of corresponding each second image;
If the maximum value of the first contrast of each second image and first of the second image acquired in the last time
The ratio of contrast is greater than or equal to second threshold, it is determined that the second position is the first contrast of each second image
Maximum value corresponding to lens location.
Optionally, the process of the determining second position further includes:
If the maximum value of the first contrast of each second image and first of the second image acquired in the last time
The ratio of contrast is less than the second threshold, and the position after camera lens the last time adjustment is not up to the end position of camera lens
And the maximum value of the first contrast of each second image and the ratio of minimum value are greater than or equal to third threshold value, it is determined that institute
State the lens location corresponding to the maximum value for the first contrast that the second position is each second image.
Optionally, the center of the focusing range is the second position, and the width of the focusing range is described second
Step-length.
Optionally, the determination process of the focusing position of the camera lens includes:
Point processing such as carry out to the focusing range;
Each position of halving that the camera lens is adjusted to obtain after decile processing respectively;
Camera lens position in each position of halving acquired in the imaging device corresponding to the image of the first contrast maximum
Put the focusing position for being determined as the camera lens.
To solve the above problems, technical solution of the present invention also provides a kind of automatic focusing mechanism, described device includes:
Probe unit often moves the obtained correspondence of imaging device described in the first step-length along the first direction for obtaining camera lens
First image of the lens location, according to the contrast of described first image determine the camera lens focusing direction and first
It puts;
Coarse scanning unit often moves imaging device institute described in the second step-length for obtaining the camera lens along the focusing direction
Obtained the second image of the correspondence lens location determines the second position according to the contrast of second image;
Range determination unit, for determining focusing range, the focusing range is the area centered on the second position
Domain;
Position determination unit, will be acquired in the imaging device for the camera lens mobile in the focusing range
Lens location in the focusing range in each lens location corresponding to the image of contrast maximum is determined as the camera lens
Focusing position.
Compared with prior art, technical scheme of the present invention has the following advantages:
In auto-focusing, the initial position message of detection focusing direction and camera lens first, i.e., by obtaining camera lens along the
The first image of the obtained correspondence of imaging device described in the first step-length lens location is often moved in one direction, according to described
The contrast of one image determines the focusing direction and first position of the camera lens;So that imaging device enters coarse scanning, with
The possible focusing position of camera lens after first successive step is got, that is, obtains the camera lens and often moves second step along the focusing direction
The second image of the lens location is corresponded to obtained by the long imaging device, the is determined according to the contrast of second image
Two positions;And then focusing range is determined centered on the second position acquired in coarse scanning;Finally in the focusing range, lead to
Cross in the focusing range the mobile camera lens, and by acquired in the imaging device in the focusing range each camera lens
Lens location in position corresponding to the image of contrast maximum is determined as the focusing position of the camera lens, realizes to imaging device
Focusing position be accurately positioned.This method determines the focusing direction of camera lens in the starting stage of auto-focusing so that each
When focusing again, lens location after the completion of being focused with last time simultaneously restarts to focus according to focusing direction, without each
Again focus and focusing scanned all since fixed initial position, the speed of auto-focusing can be effectively improved, particularly into
In the case of not being too big as scene changes, the acquisition speed and accuracy of focusing position can be significantly improved.
Further, it is originally determined focusing direction during, with reference to image the first contrast and the second contrast into
Row considers that the second contrast of image is the contrast-data obtained according to the image block of focusing area, the second contrast
The process equalized to image data is obtained, acquired contrast in this way can effectively remove picture noise to comparison
The influence of degrees of data, and even if in the case where the real focusing position of distance of camera lens is distant, can also keep preferable
Contrast sensitivity so that can accurately detect focusing direction, improve the speed and accuracy of auto-focusing.
Description of the drawings
Fig. 1 is the flow diagram for the Atomatic focusing method that technical solution of the present invention provides;
Fig. 2 is the focusing direction of determining camera lens provided in an embodiment of the present invention and the flow diagram of first position;
Fig. 3 is the first contrast of image provided in an embodiment of the present invention and the schematic diagram of the second contrast;
Fig. 4 is the schematic diagram of focusing area provided in an embodiment of the present invention;
Fig. 5 is the division schematic diagram of focusing area provided in an embodiment of the present invention;
Fig. 6 is that another embodiment of the present invention provides the focusing direction of horizontal glass head really and the flow diagram of first position;
Fig. 7 is the flow diagram of the determining second position provided in an embodiment of the present invention;
Fig. 8 is the flow diagram of determining focusing position provided in an embodiment of the present invention;
Fig. 9 is focusing position schematic diagram provided in an embodiment of the present invention;
Figure 10 is the structure diagram of automatic focusing mechanism provided in an embodiment of the present invention.
Specific embodiment
The focusing position and the slow problem of auto-focusing for being difficult to accurately determining auto-focusing exists in the prior art.
To solve the above problems, technical solution of the present invention provides a kind of Atomatic focusing method.Fig. 1 is technical solution of the present invention
The flow diagram of the Atomatic focusing method of offer.
As shown in Figure 1, step S1 is first carried out, obtains camera lens and often move imaging device described in the first step-length along the first direction
First image of the obtained correspondence lens location, the focusing of the camera lens is determined according to the contrast of described first image
Direction and first position.
First to focusing direction detect, it is described focusing direction refer to camera lens from current location to focusing focal position into
The mobile direction of row.
Camera lens is moved along the first direction according to the first step-length, for camera lens often after movement once, imaging device can be corresponding
Obtain the image at the corresponding position of camera lens after movement, hereon referred to as the first image, i.e. camera lens are often mobile primary, can obtain
First image of the lens location after to a corresponding movement.
The situation of change of the contrast of obtained each first image determines focusing side after being moved according to each camera lens
To, if for example, during camera lens moves along the first direction, if the contrast of obtained first image is increasing,
Show during camera lens moves, becoming for image is more and more clear, you can to determine that the first direction is to focus
Direction.
After focusing direction is determined, determined to perform auto-focusing mistake according to the situation of change of the contrast of described first image
The initial position of identified focus process behind determining focusing direction in present specification, is known as the by the initial position of journey
One position, and then the coarse scanning process of auto-focusing is entered according to focusing direction and first position.
Step S2 is performed, is obtained obtained by the camera lens often moves imaging device described in the second step-length along the focusing direction
The correspondence lens location the second image, the second position is determined according to the contrast of second image.
During coarse scanning, camera lens is moved along focusing direction since first position according to second step length, mirror
For head often after movement once, imaging device can accordingly obtain the image at the corresponding position of camera lens after movement, hereon referred to as
Second image, i.e. camera lens are often mobile primary, can obtain the second image of the lens location after a corresponding movement.
The situation of change of the contrast of obtained each second image primarily determines one after being moved according to each camera lens
The position that a second picture contrast peak value occurs, in present specification, by the variation feelings of the contrast according to the second image
The position that contrast peak value determined by condition is likely to occur is known as the second position, and the second position is determined by coarse scanning process
Focusing position that may be present.After the second position is determined, into fine control process, to obtain accurate focusing position.
Step S3 is performed, determines focusing range, the focusing range is the region centered on the second position.
One smaller focusing range is determined according to the second position, for example, can be using the second position in
The heart, and the image-region in certain area coverage is determined as the focusing range.The specific width of the focusing range can be with
It is set according to the step-length of the camera lens during coarse scanning, you can be set accordingly according to second step length.
Perform step S4, the mobile camera lens in the focusing range, by acquired in the imaging device described
Lens location in focusing range in each lens location corresponding to the image of contrast maximum is determined as the focusing position of the camera lens
It puts.
During fine control, with smaller step-length moving lens in the focusing range, and and then each position of acquisition
The maximum value in the contrast for the image that place is got is put, the lens location corresponding to the image of contrast maximum is determined as
The focusing position of camera lens.
This method determines focusing direction and first position in the detection phase, and the second position is determined in the coarse scanning stage, into
And the accurate focusing position of camera lens is obtained in the fine control stage, focusing position can be accurately obtained, improves imaging device focusing position
The accuracy put.The focusing direction of camera lens is determined in the starting stage of auto-focusing so that, can be with when focusing again every time
Last time focusing after the completion of lens location and according to focusing direction restart to focus, without focusing again every time all from fixed
Initial position starts scanning focusing, effectively improves the speed of auto-focusing, is not feelings too greatly particularly in image scene variation
Under condition, hence it is evident that improve the speed for getting accurate focusing position;Under the premise of focusing direction is determined, and then according to pair of image
The second position after coarse scanning is determined than degree, specific focusing range is determined, and then in the focusing range with the second position
Accurate focusing position is got, effectively improves the accuracy of focusing position.
It is understandable for the above objects, features and advantages of the present invention is enable to become apparent, below in conjunction with the accompanying drawings to the present invention
Specific embodiment be described in detail.
In specific implementation process, described acquisition camera lens often moves the first step-length institute along the first direction in step sl
The first image of the imaging device obtained correspondence lens location is stated, according to determining the contrast of described first image
The focusing direction of camera lens and the realization process of first position please refer to Fig.2, and Fig. 2 is the focusing of determining camera lens provided in this embodiment
Direction and the flow diagram of first position.
As shown in Fig. 2, during the focusing direction of detecting lenses and first position, step S201 is first carried out, really
Surely the initial position detected.
The initial position of detection is the initial position of camera lens when starting auto-focusing of camera lens.
The moving lens since the initial position of detection, to realize to the focusing direction of camera lens and determining for first position.
In the present embodiment, the first position refers to after focusing direction is determined, identified to be opened again according to the focusing direction
Beginning carries out the initial position of focusing coarse tuning process.
Step S202 is performed, camera lens is moved along the first direction into the first step-length.
When imaging device carries out auto-focusing, for a selected focusing scene, camera lens is in different positions, in image
Imaging definition on sensor would also vary from, and the contrast of obtained image would also vary from, if usually camera lens is worked as
Front position apart from best end focusing position farther out when, the contrast of image also can be smaller, that is to say, that the position of camera lens away from
More remote from focusing position, the contrast of obtained image is smaller, and image also can be than less clear.So according to this rule, it can
With focus start when, the shot detection that first makes is moved toward a direction, by shot detection it is mobile it is several compared with
Small stepping, and the contrast of imaging device image of corresponding acquisition on each stepping position is obtained, according to the comparison of image
The changing rule judgement camera lens of degree can obtain the most clearly direction of lens location, that is, determine focusing direction.
In present specification, the direction that shot detection moves is known as first direction, camera lens is moved along the first direction
The length of dynamic stepping is known as the first step-length, and camera lens is often moved to the obtained correspondence of the long imaging device of the first step along the first direction
The image of lens location is known as the first image.
In specific selected first direction, if camera lens present position close to the nearly burnt end of imaging system, by first
Direction is determined as the direction from nearly burnt end to remote burnt end movement, if conversely, the present position of camera lens is close to imaging system
First direction is then determined as the direction from remote burnt end to nearly burnt end movement by remote coke end.
The length of the first step-length that the camera lens moves along the first direction can be according to the system performance of imaging system, focusing
Sensitivity, accuracy requirement Binding experiment data set accordingly.
Step S203 is performed, obtains the first image that lens location is corresponded to when camera lens moves along the first direction the first step-length,
And record the first contrast and the second contrast of described first image.
When camera lens often moves the first step-length, imaging system can obtain the first image corresponding to current lens position,
It obtains herein when camera lens moves along the first direction the first step-length and corresponds to the first image of lens location, and obtain current lens position
The contrast of the first corresponding image.
The contrast of image acquired in imaging system can be counted according to the brightness value of the pixel in image
It calculates.Specifically, in the present embodiment, in the detection phase, be respectively adopted two methods the contrast of same image is carried out it is true
It is fixed, i.e., illustrated so that the contrast of described image respectively includes the first contrast and the second contrast as an example, according to positioned at pair
The luminance difference between pixel in burnt region determines the first contrast of image, according between the image block in focusing area
Luminance difference determine the second contrast.
The contrast of image is weighed using two ways in the detection phase, mainly it is considered that opening in focusing
Stage beginning, before determining focusing direction, the current position potential range imaging of camera lens most clearly focusing position away from
From distant, the image at this time acquired in imaging system is more smudgy, and the noise of image can be bigger, if using single
The contrast that image is determined according to the luminance difference between pixel, since the interference of noise in image is bigger, lead to figure
As the difference between pixel can be smaller, i.e., as shown in Figure 3 in the lens location place apart from focusing position farther out
First contrast of the image got can be smaller.If the single luminance difference according between pixel determines the comparison of image
The sensitivity of degree can be very low, thus may cause to carry out the determining of focusing state according to this mode to fail, i.e. picture noise
Focusing can be caused to fail in the case of bigger.
So in the present embodiment, with reference to the comparison that image is determined by the luminance difference between the block of pixels in image
Degree, due to when picture noise is bigger, luminance difference between block of pixels more can accurately, pair of actual response image
Than degree situation of change, though lens location apart from focusing position farther out when, can also also keep image contrast it is sensitive
Degree, this is highly useful to the detection in the focusing direction at initial stage of focusing.It is shown in Fig. 3 between the block of pixels in image
Luminance difference determined by the second contrast change curve, at focusing position lens location farther out, image
Second contrast significantly has better sensitivity than the first contrast of image.
In the present embodiment, in the contrast for determining image, according to the pixel being located in image in focusing area
Brightness value determines the first contrast and the second contrast of image.
The focusing area can be the central area of whole image range, the signal of focusing area as illustrated in FIG. 4
Figure, the size of the focusing area can be set according to imaging system performance, experimental data etc., not limited specifically herein
It is fixed.
First contrast of image can be in focusing area the brightness value of each pixel be determined, in this implementation
In example, the first contrast of image is determined according to formula (1).
Wherein, VpFor first contrast, M is the horizontal resolution of the focusing area, and N is the focusing area
Vertical resolution, i and j are respectively the horizontal and vertical index value of the pixel in the focusing area, and L (i, j) is described
The brightness value of the pixel at (i, j) position in focusing area.
Second contrast of image can be determined according to the luminance difference between the block of pixels in focusing area.
Piecemeal processing is carried out for the pixel in focusing area to image first, the width of focusing area is divided into X
Decile is highly divided into Y deciles, as shown in figure 5, then each sub-regions are the block of pixels obtained after dividing.In this implementation
In example, the value of X, Y are 32, i.e., focusing area are divided into 32 × 32 block of pixels, according to each pixel pixel in the block
Brightness value determine the average brightness value of the block of pixels, will the brightness of pixel all pixels point in the block sum, then
Carry out the average brightness of the average acquiring block of pixels.
Second contrast of image is determined according to formula (2).
Second contrast is determined by equation below:
Wherein, VbFor second contrast, X is the image block contained by horizontal direction after the focusing area piecemeal
Number, numbers of the Y for the image block contained by vertical direction after the focusing area piecemeal, s and t are respectively the focusing area
The horizontal and vertical index value of interior image block, LB (s, t) are picture in the image block at (s, t) position in the focusing area
The average brightness value of vegetarian refreshments.
When the first step-length is often moved for camera lens, imaging system is obtained according to formula (1) and formula (2) and obtains current lens
First the first contrast of image and the second contrast corresponding to position, and obtained contrast information is recorded, so as to
In subsequently determining focusing direction and first position according to the first contrast of recorded each first image and the second contrast information,
I.e. after camera lens is often mobile once, the first contrast and second of the first image of a corresponding camera lens current location can be all recorded
Contrast.
Perform step S204, the maximum value and minimum value of the first contrast of each first image of acquisition and the second contrast
Maximum value and minimum value.
In moving lens each time and record the first contrast and of corresponding first image in current lens position place
After two contrasts, in the first contrast and the second contrast of each first image corresponding to each lens location recorded,
The first contrast of each first image and maximum value and minimum value in the second contrast are found out respectively, herein by the first image
Maximum value in first contrast is denoted as Vp_max, the minimum value in the first contrast of the first image is denoted as Vp_min, by first
Maximum value in second contrast of image is denoted as Vb_max, the minimum value in the second contrast of the first image is denoted as Vb_min。
Step S205 is performed, judges whether the maximum value of the first contrast and the ratio of minimum value are greater than or equal to the first threshold
Value.
The amplitude of variation that first threshold judges the first contrast of the first image is combined first.Preset first threshold,
For describing the amplitude of variation of the first contrast of the first image, the first threshold can carry out corresponding according to experimental data
Setting.
In the maximum value V of the first contrast of the first imagep_maxWith minimum value Vp_minBetween ratio be greater than or equal to institute
When stating first threshold, illustrate the first contrast more apparent change as the variation of the position of camera lens has occurred of the first image
Change, then it can be according to the first contrast from minimum value Vp_minTo maximum value Vp_maxThe direction of variation determines final focusing position.
If the ratio between the maximum value and minimum value of the first contrast of the first image is also less than described first at present
Threshold value then illustrates to judge what camera lens should adjust according to the data of the first contrast of the first image currently recorded
It is correctly oriented, the second contrast that can combine the first image at this time determines the focusing direction of camera lens.
I.e. when step S205 judging results are "Yes", step S210 is performed;Otherwise step S206 is performed.
Step S206, judges whether the maximum value of the second contrast and the ratio of minimum value are greater than or equal to first threshold.
The situation of change of the contrast of the first image is determined according to the situation of change of the brightness value of the block of pixels of image.
If the maximum value V of the second contrast of the first imageb_maxWith minimum value Vb_minBetween ratio be greater than or equal to institute
When stating first threshold, although illustrating that contrast changes unobvious determined by the brightness of the pixel of image at this time, according to figure
As block of pixels brightness determined by the variation of contrast or obvious, then according to the second contrast from minimum value
Vb_minTo maximum value Vb_maxThe direction of variation may can determine final focusing position, in order to direction of focusing determine it is accurate
Property, the first comparison of the image at the lens location corresponding when the second contrast obtains maximum value and minimum value can be combined
Degree accounts for.If the conversely, maximum value V of the second contrast of the first imageb_maxWith minimum value Vb_minBetween ratio be less than
The first threshold then illustrates that the information by current the first acquired image can't determine focusing direction, needs to continue to move
Index glass head obtains the first image at the lens location after mobile first step-length, is further judged.
When step S206 judging results are "Yes", step S208 is performed;Otherwise step S207 is performed.
Step S207, the next position of setting camera lens.
According to first direction and the first step-length, next lens location of current lens is determined.After step S207,
It returns and performs step S202, moving lens performs subsequent step to corresponding position.
Step S208 determines the second contrast maximum value and the lens location corresponding to minimum value, and obtains the first data
With the second data.
Specifically, remember the second contrast maximum value V of the first imageb_maxCorresponding lens location be P0, the first image
The second contrast minimum value Vb_minCorresponding lens location is P1, is obtained in recorded the first comparison in lens location P0
The first contrast of the first image corresponding with P1 positions place is put, corresponding first contrast in lens location P0 places is denoted as
Vp_p0, corresponding first contrast in lens location P1 positions place is denoted as Vp_p1.In present specification, by described each first
The maximum value V of second contrast of imageb_maxFirst comparison of the first image got at corresponding lens location P0
Spend Vp_p0Referred to as the first data, by the minimum value V of the second contrast of each first imageb_minCorresponding lens location P1
First contrast V of the first image that place is gotp_p1Referred to as the second data.
Step S209 is performed, judges whether the first data are more than the second data.
The changing rule of the contrast of the first image is determined with reference to the first data and the second data.
If the judging result of step S209 is "Yes", step S210 is performed;Otherwise it returns and performs step S207.
When the judging result of step S209 is "No", although illustrating currently the first image according to determined by block of pixels
Second contrast meets the maximum value V of the second contrastb_maxWith minimum value Vb_minBetween ratio be greater than or equal to described first
The condition of threshold value, but the first data are less than the second data, same the first image, the first contrast at different location and the
The size variation rule of two contrasts is different, illustrates accurately determine the focusing direction of camera lens, to need to return at present
Step S207 continues to set next lens location, continues to detect.
Step S210 determines focusing direction and first position, into the coarse scanning stage.
When step S209 judging results are "Yes", illustrate to meet:The maximum value V of second contrast of the first imageb_max
With minimum value Vb_minBetween ratio be greater than or equal to the condition that the first threshold and the first data are more than the second data, then press
The second contrast from minimum value Vb_minTo maximum value Vb_maxThe direction of variation can determine final focusing position, can incite somebody to action
Camera lens is from minimum value Vb_minTo maximum value Vb_maxMobile direction is determined as final focusing direction.By the second of the first image
Lens location corresponding to the minimum value of contrast is determined as the first position, i.e., by the second contrast minimum value Vb_minInstitute
Corresponding lens location is as the follow-up initial position into during coarse scanning.
And when being "Yes" if in step S205 judging results, illustrate to meet:First contrast of the first image is most
The ratio of big value and minimum value is greater than or equal to first threshold, can be by camera lens from the first contrast from minimum value Vp_minTo maximum
Value Vp_maxMobile direction is determined as final focusing direction.By the mirror corresponding to the minimum value of the first contrast of the first image
Head location determination is the first position, i.e., by the first contrast minimum value Vp_minCorresponding lens location enters as follow-up
Initial position during coarse scanning.
By above-mentioned steps S201 to step S210, during the auto-focusing of image, you can realize as shown in fig. 1
The step S1 gone out.
In another embodiment of the invention, the focusing direction of camera lens can also be determined using method as illustrated in FIG. 6
And first position.
As shown in fig. 6, step S601 is first carried out to step S604.
Step S601 determines the initial position of detection.
Camera lens is moved along the first direction the first step-length by step S602.
Step S603 is obtained when camera lens moves along the first direction the first step-length and is corresponded to the first image of lens location, and remember
Record the first contrast and the second contrast of described first image.
Step S604, the maximum value and minimum value of the first contrast of each first image of acquisition and the second contrast are most
Big value and minimum value.
The realization process of step S601 to step S604 uses the implementation method shown by step S201 to step S204,
This is repeated no more.
Step S605 is performed after step S604, judges whether the maximum value of the second contrast and the ratio of minimum value are more than
Or equal to first threshold.
Step S605 please refers to step S206.
If step S605 judging results are "Yes", step S606 is performed;Otherwise step S609 is performed.
Step S606 determines the second contrast maximum value and the lens location corresponding to minimum value, and obtains the first data
With the second data.
Step S606 please refers to step S208.
Step S607 is performed after step S606.
Step S607, judges whether the first data are more than the second data.
The changing rule of the contrast of the first image is determined with reference to the first data and the second data.
Step S607 please refers to step S209.
If step S607 judging results are "Yes", step S610 is performed;Otherwise step S608 is performed.
Step S608, the next position of setting camera lens.
According to first direction and the first step-length, next lens location of current lens is determined.
Step S608 please refers to step S207.
It after step S608, returns and performs step S602, moving lens performs subsequent step to corresponding position.
Step S609, judges whether the maximum value of the first contrast and the ratio of minimum value are greater than or equal to first threshold.
Specifically whether the ratio of the maximum value to the first contrast and minimum value is greater than or equal to the judgement of first threshold
Journey please refers to step S205.
When step S609 judging results are "Yes", step S610 is performed;Otherwise it returns and performs step S608.
Step S610 determines focusing direction and first position.
During if in step S607 judging results for "Yes", illustrate to meet:The maximum of second contrast of the first image
Value Vb_maxWith minimum value Vb_minBetween ratio be greater than or equal to the item that the first threshold and the first data are more than the second data
Part, then according to the second contrast from minimum value Vb_minTo maximum value Vb_maxThe direction of variation can determine final focusing position,
It can be by camera lens from minimum value Vb_minTo maximum value Vb_maxMobile direction is determined as final focusing direction.By the first image
The second contrast minimum value corresponding to lens location, be determined as the first position, i.e., by the second contrast minimum value
Vb_minCorresponding lens location is as the follow-up initial position into during coarse scanning.
And when being "Yes" if in step S609 judging results, illustrate to meet:First contrast of the first image is most
The ratio of big value and minimum value is greater than or equal to first threshold, can be by camera lens from the first contrast from minimum value Vp_minTo maximum
Value Vp_maxMobile direction is determined as final focusing direction.By the mirror corresponding to the minimum value of the first contrast of the first image
Head location determination is the first position, i.e., by the first contrast minimum value Vp_minCorresponding lens location enters as follow-up
Initial position during coarse scanning.
By above-mentioned steps S601 to step S610, during the auto-focusing of image, can equally realize as in Fig. 1
Shown step S1.
The step S2 shown in Fig. 1 is described in detail with reference to Fig. 7.Step S2 shown in Fig. 1 also may be used
To be not understood as through coarse scanning, thick step determines the process of the focusing position of camera lens.During coarse scanning, camera lens is with preset
Second step length is moved according to determining focusing direction, and acquired figure during coarse scanning is found during stepping
Lens location corresponding to image contrast maximum value, as coarse scanning result.
In specific implementation process, the acquisition camera lens described in step S2 is along the focusing direction from described first
Position corresponds to the second image of the lens location obtained by the imaging device when starting every the second step-length of movement, according to described
The contrast of second image determines that the realization process of the second position please refers to Fig. 7, and Fig. 7 is determining camera lens provided in this embodiment
The flow diagram of the second position.
Step S701 is performed, sets the initial position during coarse scanning.
Using by the first position as acquired in upper type as the initial position during coarse scanning.
Step S702 is performed, camera lens is moved into the second step-length along focusing direction.
In present specification, imaging device obtained corresponding camera lens when camera lens edge focusing direction is moved the second step-length
The image of position is known as the second image.
The length of the second step-length that the camera lens is moved along focusing direction can be according to imaging system system performance, focusing
Sensitivity, accuracy requirement Binding experiment data set accordingly.
Step S703 is performed, obtains the second image that lens location is corresponded to when camera lens moves the second step-length along focusing direction,
And obtain the first contrast of the second image.
In the coarse scanning stage in order to which the true situation of change of the contrast of image can be accurately obtained, according to the picture of image
Luminance difference between element determines the contrast of image, i.e., using the first contrast of image to picture contrast situation of change into
Row description.
When camera lens often moves the second step-length, imaging system can obtain the second image corresponding to current lens position,
It obtains herein when camera lens moves the second step-length along focusing direction and corresponds to the second image of lens location, and obtain current lens position
The contrast of the second corresponding image.
First contrast of second image can according to it is as shown above go out formula (1) obtained, herein no longer
It repeats.
When the second step-length is often moved for camera lens, imaging system can be obtained according to formula (1) and obtain current lens position
The first contrast of the second corresponding image is put, records obtained second contrast, in order to each subsequently according to recording
First contrast of the second image determines the second position, i.e., after camera lens is often mobile once, can all record a corresponding camera lens and work as
First contrast of the second image of front position.
In present specification, after camera lens is moved the second step-length, imaging system is obtained corresponding to current lens position
First contrast of the second image is denoted as Vp_now。
Step S704 is performed, obtains the maximum value and minimum value of the first contrast of each second image.
In moving lens each time and after recording the first contrast of corresponding second image in current lens position place,
Maximum value and minimum value are found out in first contrast of each second image corresponding to each lens location recorded, herein by
Maximum value in first contrast of two images is denoted as Vp2_max, the minimum value in the first contrast of the second image is denoted as
Vp2_min。
Step S705 is performed, judges whether the maximum value of the first contrast and the ratio of current value are greater than or equal to the second threshold
Value.
The current value refers to the first contrast of the second image acquired in imaging device the last time, i.e., as described above
Imaging system obtain the first contrast V of the second image corresponding to current lens positionp_now。
Second threshold is preset, the second threshold can accordingly be set according to experimental data.
In the maximum value V of the first contrast of the second imagep2_maxWith current value Vp_nowBetween ratio be greater than or equal to the
During two threshold values, illustrate the maximum value V of the first contrast of the second imagep2_maxIt may be the thick step to be obtained in the coarse scanning stage
Lens location corresponding to the maximum value of first contrast of the second image is known as the second position by focusing position.
When step S705 judging results are "Yes", step S709 is performed;Otherwise step S706 is performed.
Step S706, judges whether camera lens reaches end position.
In the maximum value V of the first contrast of the second imagep2_maxWith current value Vp_nowBetween ratio be less than described second
During threshold value, need further to judge whether current lens position reaches end position, the end position refers to that camera lens can be adjusted
The maximum position of section.
If current lens reach end position not yet, adjustment lens location is can also continue to, then it is next to set camera lens
Position;If current lens have reached end position, the maximum value V of the first contrast according to the second image can be attemptedp2_max
With minimum value Vp2_minBetween Relation acquisition coarse scanning result.
When step S706 judging results are "No", step S707 is performed;Otherwise step S708 is performed.
Step S707, the next position of setting camera lens.
According to focusing direction and the second step-length, next lens location of current lens is determined.After step S707,
It returns and performs step S702, moving lens performs subsequent step to corresponding position.
Step S708, judges whether the maximum value of the first contrast and the ratio of minimum value are greater than or equal to third threshold value.
Third threshold value is preset, the third threshold value can accordingly be set according to experimental data.
In the maximum value V of the first contrast of the second imagep2_maxWith minimum value Vp2_minBetween ratio be greater than or equal to
During the third threshold value, it may also be said to which the peak position in bright coarse scanning stage has been determined;If the first contrast of the second image
Maximum value Vp2_maxWith minimum value Vp2_minBetween ratio be less than the third threshold value, then illustrate according to the currently recorded
The data of first contrast of two images can't determine the peak position of image during coarse scanning, and camera lens has reached at this time
End position can not also continue to move, and also can not just determine the focusing position of camera lens, perform step S710, determine focusing
Failure.
Step S709, determines the second position, into smart sweep phase.
It is "Yes" in step S705 judging results, meets the maximum value of the first contrast of the second image and the ratio of current value
Value is more than or equal to the condition of the second threshold, then illustrating the peak position in coarse scanning stage can be determined, by the second figure
As the first contrast maximum value corresponding to lens location be determined as the second position.
When step S708 judging results are "Yes", meet the maximum value and minimum value of the first contrast of the second image
Ratio is greater than or equal to the condition of third threshold value, it may also be said to which the peak position in bright coarse scanning stage can be determined, and can be incited somebody to action
Lens location corresponding to the maximum value of first contrast of the second image is determined as the second position.
After the second position is determined, into smart sweep phase.
By above-mentioned steps S701 to step S710, during the auto-focusing of image, can realize as shown in fig. 1
The step S2 gone out.
After the second position is determined by coarse scanning, can according to the second position, determine one for determine finally
The focusing range of focusing position, the focusing range is it can be appreciated that be the range for essence scanning.The focusing range can
To be the region centered on the second position.
Step S3 shown in Fig. 1:Determine focusing range, the focusing range is centered on the second position
Region, in specific implementation, can be centered on the coarse scanning stage obtained second position, each two points before and after the second position
One of the second step width region as the focusing range.
Step S4 shown in Fig. 1:The mobile camera lens in the focusing range, will be acquired in the imaging device
The lens location in the focusing range in each lens location corresponding to the image of contrast maximum be determined as the camera lens
Focusing position, in specific implementation, can be realized according to the flow of determining focusing position as illustrated in FIG. 8.
Determining the second position, and after determining focusing range according to the second position, when determining final focusing position,
Step S801 can be first carried out, point processing such as carry out to focusing range.
The focusing range such as is subjected at point processing, the width of specific decile can based on experience value, experimental data etc. into
The corresponding setting of row.
Fig. 9 is focusing position schematic diagram provided in an embodiment of the present invention, as shown in figure 9, can will be during coarse scanning
It, will be with second in coordinate system determined by the first contrast obtained at obtained lens location and corresponding lens location
The focusing range for being set to center such as carries out at point processing, in the present embodiment, is illustrated by taking the quartering as an example.In Fig. 9, solid line institute
Corresponding lens location represents the lens location during coarse scanning, and the lens location represented by dotted line is during close scanning etc.
Point treated lens location, the wherein second position is the camera lens scan position of coarse scanning and close scanning simultaneously.
Step S802 is performed, camera lens is adjusted to each position of halving obtained after decile processing respectively.
After decile processing, camera lens is pushed on position of halving.
Step S803 is performed, with corresponding to the image of the first contrast maximum in each position of halving acquired in imaging device
Lens location be determined as the focusing position of the camera lens.
Camera lens can obtain corresponding to the first contrast of the image of the lens location, obtain on each position of halving
The lens location corresponding to the image of the first contrast maximum is taken, which is determined as final as shown in Figure 9
Focusing position.
According to it is as shown above go out step S1, step S2, step S3 and step S4 specific embodiment, automatic right
In burnt process, when direction is focused in detection, obtain the first contrast and the second contrast of the first image respectively, according to based on
The second contrast that image block obtains can average image data during the focusing direction for determining camera lens
Process, this process can effectively remove the influence that picture noise extracts contrast-data, and the second contrast is in mirror
Head position from practical focusing position farther out when, preferable location sen-sitivity can also be kept, can still obtain the true of image
Real contrast situation, this is highly useful to the focusing orientation detection focused early period, can effectively improve the speed of auto-focusing
And accuracy.Focusing early period used focusing orientation detection mode come obtain focusing place value direction, so every time focus just
It can start to focus with the position that last time focusing is completed, without scanning focusing since initial position every time, this is in scene changes
In the case of not being too big, focusing speed can be effectively improved.
Corresponding above-mentioned Atomatic focusing method, the embodiment of the present invention also provide a kind of automatic focusing mechanism.Figure 10 is the present invention
The structure diagram for the automatic focusing mechanism that embodiment provides.
As shown in Figure 10, described device includes:Probe unit U11, coarse scanning unit U12, range determination unit U13 and position
Put determination unit U14.
The probe unit U11 is often moved obtained by imaging device described in the first step-length along the first direction for obtaining camera lens
The first image of the correspondence lens location arrived determines the focusing direction of the camera lens according to the contrast of described first image
And first position.The contrast include the first contrast and the second contrast, first contrast according to image be located at pair
The luminance difference between pixel in burnt region is determined, and second contrast is according to the image in the focusing area
Luminance difference between block is determined.
The coarse scanning unit U12, for obtain the camera lens along it is described focusing direction often move described in the second step-length into
As the second image of the equipment obtained correspondence lens location, second is determined according to the contrast of second image
It puts.
The range determination unit U13, for determining focusing range, the focusing range be using the second position in
The region of the heart.
The position determination unit U14, for the camera lens mobile in the focusing range, by the imaging device institute
The lens location in the focusing range in each lens location corresponding to the image of contrast maximum obtained is determined as described
The focusing position of camera lens.
The probe unit U11 includes:First obtains subelement U111 and the first determination subelement U112.
Described first obtains subelement U111, for obtaining the first contrast of corresponding each first image and second pair respectively
Degree of ratio.
The first determination subelement U112, in the maximum value and minimum of the first contrast of each first image
When the ratio of value is greater than or equal to first threshold, the focusing direction for determining the camera lens is the minimum value from first contrast
The moving direction of the lens location of the maximum value of first contrast is changed to, the first position is each first image
The first contrast minimum value corresponding to lens location.
The probe unit U11 is further included:Second determination subelement U113, in the first couple of each first image
It is less than the first threshold, the maximum value of the second contrast of each first image than the maximum value of degree and the ratio of minimum value
It is greater than or equal to the first threshold with the ratio of minimum value and the first data is more than the second data, it is determined that pair of the camera lens
Burnt direction is the movement of the lens location for the maximum value that second contrast is changed to from the minimum value of second contrast
Direction, the first position are the lens location corresponding to the minimum value of the second contrast of each first image, described the
One data are by the first figure for being got at the lens location corresponding to the maximum value of the second contrast of each first image
First contrast of picture, second data are the camera lens position corresponding to the minimum value of the second contrast of each first image
Put the first contrast of the first image that place is got.
The probe unit U11 is further included:Third determination subelement U114, in the second couple of each first image
When being greater than or equal to first threshold and the first data than the maximum value of degree and the ratio of minimum value and being more than the second data, determine described
The focusing direction of camera lens is the camera lens position for the maximum value that second contrast is changed to from the minimum value of second contrast
The moving direction put, the first position are the camera lens position corresponding to the minimum value of the second contrast of each first image
It puts, first data at the lens location corresponding to the maximum value of the second contrast of each first image by getting
The first image the first contrast, second data for each first image the second contrast minimum value corresponding to
Lens location at the first contrast of the first image for being got.
The probe unit U11 is further included:4th determination subelement U115, if the second couple for each first image
It is less than the first threshold, and the maximum of the first contrast of each first image than the maximum value of degree and the ratio of minimum value
When the ratio of value and minimum value is greater than or equal to first threshold, the focusing direction for determining the camera lens is from first contrast
Minimum value change to first contrast maximum value lens location moving direction, the first position is described each
Lens location corresponding to the minimum value of first contrast of the first image.
The coarse scanning unit U12 includes:Second obtains subelement U121 and the 5th determination subelement U122.
Described second obtains subelement U121, for obtaining the first contrast of corresponding each second image;
The 5th determination subelement U122, in the maximum value of the first contrast of each second image and recently
When the ratio of first contrast of primary the second acquired image is greater than or equal to second threshold, determine that the second position is
Lens location corresponding to the maximum value of first contrast of each second image.
The coarse scanning unit U12 is further included:6th determination subelement U123, for the first of each second image
The ratio of first contrast of the second image acquired in the maximum value of contrast and the last time is less than the second threshold, institute
State end position and the first contrast of each second image that the position after the adjustment of camera lens the last time is not up to camera lens
When the ratio of maximum value and minimum value is greater than or equal to third threshold value, the of the second position for each second image is determined
Lens location corresponding to the maximum value of one contrast.
The position determination unit U14 includes:Wait subdivisions U141, mobile unit U142 and focusing unit U143.
It is described to wait subdivisions U141, for point processing such as carrying out to the focusing range.
The mobile unit U142, for each the decile position for being adjusted to obtain after decile processing respectively by the camera lens
It puts.
The focusing unit U143, it is maximum for the first contrast in each position of halving acquired in the imaging device
Image corresponding to lens location be determined as the focusing position of the camera lens.
Although present disclosure is as above, present invention is not limited to this.Any those skilled in the art are not departing from this
It in the spirit and scope of invention, can make various changes or modifications, therefore protection scope of the present invention should be with claim institute
Subject to the range of restriction.