This non-provisional application claims priority under 35 U.S.C. §119(a) on Patent Application No(s). 098131644 filed in Taiwan, R.O.C. on Sep. 18, 2009 the entire contents of which are hereby incorporated by reference.
1. Field of Invention
The present invention relates to a focusing method, and more particularly to a focusing method for a digital camera to determine a focusing focal length that needs to be adjusted in an auto focusing stage.
2. Related Art
A user usually takes a picture with a digital camera in the following several stages. First, the digital camera is turned on; at this time, the digital camera enters a live view stage. Second, the user half presses a shutter after aiming at an object to be shot, and at the same time, the digital camera enters an auto focusing stage. Third, the user fully presses the shutter, and at this time, the digital camera enters a shooting stage and shoots the corresponding image picture.
The auto focusing stage refers to a focusing stage in which focusing is performed on the object to be shot and the shutter is not fully pressed for shooting. Briefly, it is a process in which the digital camera focuses on the object to be shot when the shutter is half pressed. During this process, a lens of the digital camera is moved to different focus positions (i.e., to different lens positions or steps, which are image sampling steps), and a degree of clarity or blur of the image is determined according to a focus value acquired at each lens position.
Conventional algorithms for determining a focusing focal length include a global search algorithm, a hill-climbing search algorithm, and a binary search algorithm. An effective search algorithm needs to consider the time required for search, the number of times for moving the lens, and search correctness. If too much search time is spent, the efficiency of auto focusing is lowered. If the lens is moved for too many times, additional battery power of the digital camera is consumed. On the contrary, the imaging quality of the digital camera is influenced.
For example, in the global search algorithm, a digital image acquired each time the lens is moved by one step is recorded; afterwards, a lens position corresponding to a digital image having the highest clarity is extracted; then, the lens is moved to the position corresponding to the highest clarity to achieve auto focusing, as shown in the diagram of a contrast value curve of
Although the conventional art can find out an optimum focal length of the digital camera for the object to be shot precisely, the power consumption is a serious problem.
Especially, in the prior art, the digital camera performs focusing once again in the auto focusing stage after having performed a coarse focusing on an object to be shot in the live view stage; for two different objects to be shot close to each other in distance, the digital camera still needs to search from a shortest focal length to a longest focal length for the second object to be shot after shooting the first object; in addition, the digital camera cannot shoot a clear digital image if an object to be shot moves in the auto focusing stage. Thus, extra power is consumed, and the user cannot take pictures before the digital camera completes the adjustment.
Accordingly, the present invention is a fast focusing method for a digital camera, suitable for the digital camera to judge whether a focusing focal length needs to be adjusted in an auto focusing stage.
In order to achieve the above objective, the present invention provides a fast focusing method for a digital camera, which comprises: capturing a target image at a reference focal length; performing a blur detection procedure on the target image to acquire a focus value; setting a focusing focal length range covering the reference focal length when the focus value is between a lower limit focusing threshold and an upper limit focusing threshold; capturing corresponding comparison images at different focusing focal lengths respectively in the focusing focal length range; calculating a contrast value of each comparison image; and calculating a target focal length based on the contrast values through a quadratic curve approximation method.
The blur detection procedure further comprises: setting at least one sampling area having a plurality of image pixels in the comparison image; comparing pixel values of every two of the adjacent image pixels in the sampling area respectively to obtain a plurality of contrast differences; accumulating the focus value if the contrast differences are greater than a preset threshold; and repeating the steps of calculation and accumulating the focus value until the steps are completed for all the image pixels in the sampling area.
In the present invention, it is judged whether refocusing needs to be performed on a captured digital image according to the captured digital image and a focal length thereof through a blur detection procedure. If a degree of clarity of an object to be shot in the digital image falls in a set threshold range, search does not need to be performed from the shortest focusing end to the longest focusing end. In this way, power consumption for moving the lens is effectively lowered, and focusing time of the digital camera is reduced.
The present invention will become more fully understood from the detailed description given herein below for illustration only, and thus are not limitative of the present invention, and wherein:
In the present invention, a digital camera adjusts a focusing focal length to a target focal length of an object to be shot rapidly in an auto focusing stage. It is judged whether a lens arrangement of a lens group needs to be readjusted according to a digital image captured by the digital camera, so as to obtain an optimal focusing focal length.
In Step S100, a target image is captured at a reference focal length.
In Step S200, a blur detection procedure is performed on the target image to acquire a focus value.
In Step S300, the focus value is compared.
In Step S400, when the focus value is between a lower limit focusing threshold and an upper limit focusing threshold, a focusing focal length range covering the reference focal length is set.
In Step S500, corresponding comparison images are captured at different focusing focal lengths respectively in the focusing focal length range.
In Step S600, a contrast value of each comparison image is calculated.
In Step S700, a target focal length is calculated based on the contrast values through a quadratic curve approximation method.
In Step S800, when the focus value is greater than the upper limit focusing threshold, a focal length of the target image is directly used as the target focal length.
In Step S900, when the focus value is less than the lower limit focusing threshold, the focusing focal length range is set to be from a shortest focal length to a longest focal length.
First, the digital camera captures a corresponding digital image at the reference focal length. Here, the digital image is defined as the target image. An operation mode of the present invention is further explained herein according to the following digital camera. The digital camera may be, but is not limited to, a digital camera shown in
When Step S300 is performed, the processing unit 95 starts to perform the blur detection procedure on the digital image.
In Step S311, at least one sampling area having a plurality of image pixels is further set in the target image.
In Step S312, pixel values of every two adjacent image pixels in the sampling area are compared respectively to obtain a plurality of contrast differences.
In Step S313, the number of the contrast differences greater than a preset threshold is accumulated as a focus value.
It should be noted that, each of the contrast differences generated in Step S312 is obtained by calculating every two adjacent image pixels of all the image pixels in the sampling area.
When the digital camera 90 sets the focusing frame 411 thereof to be the focusing frame 411 in the center, the digital camera 90 performs focusing and comparison on the focusing frame 411 in the center. Similarly, the focusing frames 411 in other areas and positions also provide the same function. The face focusing frame 411 is the corresponding focusing frame 411 produced according to a face area judged by the digital camera 90. If a plurality of face focusing frames 411 appears at the same time, in this implementation aspect of the present invention, it is assumed that the face focusing frame 411 having the shortness focal length is taken as the sampling area for judgment, but the present invention is not limited thereto. In other words, the face focusing frame 411 closest to the digital camera 90 is taken as the sampling area.
In the first implementation aspect, all the contrast differences are calculated, and then the focus value is accumulated. In addition to this, the accumulating step in Step S313 may also be changed to a step of judging whether to accumulate the focus value each time the calculation of the comparison difference is completed. This operation process is shown in
The second implementation aspect comprises the following steps.
In Step S311, at least one sampling area having a plurality of image pixels is further set in the target image.
In Step S312, pixel values of every two adjacent image pixels in the sampling area are compared respectively to obtain a plurality of contrast differences.
In Step S314, if the contrast differences are greater than a preset threshold, a focus value is accumulated.
In Step S315, the steps of calculation and accumulating the focus value are repeated until the steps are completed for all the image pixels in the sampling area.
In the process for calculating the contrast differences in Step S312 in the first implementation aspect and the second implementation aspect, two adjacent image pixels are respectively selected for processing. Here, an image pixel to be compared is defined as a target pixel 512, and another adjacent pixel that is selected is defined as a comparison pixel 511. The selection of the comparison pixel 511 may be selecting a pixel horizontally or vertically adjacent to the target pixel. The target pixel 512 may be selected sequentially according to a pixel arrangement in the sampling area. For example, if a pixel set in the sampling area is a two-dimensional array (it is assumed that the pixel set is a pixel_array[m][n] pixel array), the target pixel 512 is selected by moving one by one from a position having a minimum serial number (i.e., pixel_array[0][0]) to a position having a maximum serial number (i.e., pixel_array[0][n−1]) of the array. After the movement is completed for all pixels in each row, it is performed from the current row to a next row, as shown by arrows in
In addition to the above steps, the blur detection procedure may further be performed in the following variations.
In Step S331, an image edge detection procedure is performed on the target image to obtain a plurality of edge pixels.
In Step S332, a plurality of continuous selected pixels is selected from the edge pixels.
In Step S333, a maximum value in differences between pixel values of the adjacent selected pixels is taken as an adjacent difference.
In Step S334, a maximum difference of the selected pixels is taken as a total difference.
In Step S335, the adjacent difference is divided by the total difference to obtain a contrast ratio.
In Step S336, Steps S333-S335 are repeated until the contrast ratios of all the edge pixels are calculated.
In Step S337, the number of the contrast ratios greater than a preset threshold is accumulated as a focus value.
The target image 410 is processed through the image edge detection procedure to produce a corresponding edge image 710. The edge detection algorithm described in the present invention may be a Sobel edge detection algorithm, a Dijkstra's algorithm, a Canny edge detection algorithm, or the like.
Referring to
Then, a segment having a pixel variation exceeding a variation threshold is selected from the gray scale distribution curve, and is defined as an edge segment. A plurality of edge pixels is selected from the edge segment.
Max((A,B),(B,C),(C,D))/(D,A) (Formula 1)
The following example is taken herein for illustration. It is assumed that four pixels A=38, B=46, C=68, and D=82 are selected from the edge segment. The edge pixel sets are respectively (A, B), (B, C), and (C, D), which are respectively (A, B)=8, (B, C)=22, and (C, D)=14, and the total difference is (A, D)=44. A maximum value of the three edge pixel sets is 22, so that the adjacent difference is (B, C), and thus the contrast ratio is 22/44=0.5.
If only two pixels exist in the edge segment, a difference of this edge segment is not calculated, because this would cause the contrast ratio of this edge segment to become 1 so that whether the edge segment is an edge of the image object cannot be judged accurately. After this edge segment is calculated, the calculation of other edge segments in the gray scale distribution curve is continued to obtain the rest differences. Then, comparison is performed on the differences to determine whether they are greater than the preset threshold after the differences are obtained. The number of all the differences greater than the present threshold is calculated, and the accumulated number is defined as the focus value.
Different from the third implement aspect in which the focus value is not accumulated until all the contrast ratios are accumulated, the fourth implementation aspect also first calculates contrast ratios one by one, judges whether the produced contrast ratio is greater than the preset threshold, and repeats this step until all the contrast ratios are calculated.
In Step S341, an image edge detection procedure is performed on the target image to obtain a plurality of edge pixels.
In Step S342, a plurality of continuous selected pixels is selected from the edge pixels.
In Step S343, a maximum value in differences between pixel values of the adjacent selected pixels is taken as an adjacent difference.
In Step S344, a maximum difference of the selected pixels is taken as a total difference.
In Step S345, the adjacent difference is divided by the total difference to obtain a contrast ratio.
In Step S346, the number of the contrast ratios greater than the preset threshold is accumulated as a focus value.
In Step S347, Steps S343-S346 are repeated until the contrast ratios of all the edge pixels are calculated and the final accumulated focus value is output.
After the focus value is obtained, the processing unit 95 performs comparison according to relationships between the focus value, a lower limit focusing threshold, and an upper limit focusing threshold. When the focus value falls between the lower limit focusing threshold and the upper limit focusing threshold, the processing unit 95 sets a focusing focal length range covering the reference focal length. In the present invention, the reference focal length is set to be the longest focal length of the focusing focal length range. In a similar way, the reference focal length may also be set to be the shortest focal length of the focusing focal length range or set to be in the focusing focal length range.
When focusing on an object to be shot, the digital camera 90 will adjust from the shortest focal length of the focusing focal length range to the longest focal length of the focusing focal length range, and performs Steps S500 and S600 to obtain the contrast value of each comparison image during the movement. Since the distribution of the contrast values may form a curve, the processing unit 95 may find out a maximum contrast value from the contrast values through a quadratic curve approximation method, and define a focal length corresponding to the found contrast value as a target focal length. The quadratic curve approximation method may be realized through a Simpson method, a Newton method, or other algorithms.
In the present invention, for example, three digital images are captured in the focusing focal length range in the following description. Any variation made by persons skilled in the art to the number of the captured digital images shall fall within the scope of the present invention. Then, the processing unit 95 records focusing information of each digital image. Finally, a focal length corresponding to the found maximum focusing information is set as the target focal length of the object to be shot, and the focal length of the lens is adjusted to this focal length. In this way, the digital camera 90 does not need to move between the original longest focusing focal length and shortest focusing focal length. Thus, the movement of lenses in the lens group 91 can be effectively reduced, thereby enhancing the focusing speed of the digital camera 90 and lowering the power consumption of the digital camera 90.
In order to further illustrate the digital camera and the operation of the present invention, refer to
Finally, after the fast focusing procedure is completed, corresponding processing procedures are provided not only for the case that the focus value falls between the upper limit focusing threshold and the lower limit focusing threshold, but also for the case that the focus value is at different focusing thresholds in the implementation aspects of the present invention. If the focus value is greater than the upper limit focusing threshold, it indicates that the current focal length is the focusing focal length most suitable for the object to be shot, and thus the digital camera 90 does not need to readjust the focusing focal length. If the focus value is less than the lower limit focusing threshold, it indicates that the focusing focal length of the digital camera 90 does not fall on the object to be shot, and thus the digital camera 90 needs to readjust the focusing focal length. The digital camera 90 moves from the shortest focal length to the longest focal length and acquires corresponding images at different focal lengths, finds out the clearest image from the acquired images, and determines that a focal length of this image is the target focal length.
In the present invention, it is judged whether refocusing needs to be performed on a captured digital image according to the captured digital image and a focal length thereof through a blur detection procedure. If a degree of clarity of an object to be shot in the digital image falls in a set threshold range, search does not need to be performed from the shortest focusing end to the longest focusing end. In this way, the power consumption of moving the lens is effectively lowered, and the focusing time of the digital camera is reduced.
Number | Date | Country | Kind |
---|---|---|---|
098131644 | Sep 2009 | TW | national |