Image sharpness assignment method and focusing method for auto-focusing
By employing a distributed focusing method, utilizing image sharpness compression baseline and hysteresis compensation, the problem of hill-climbing search algorithms getting stuck in local optima during autofocus is solved, achieving a fast and high-precision focusing process and improving the user experience.
Patent Information
- Application Number
- CN202310492027.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-20
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2041-10-20
AI Technical Summary
In existing technologies, hill-climbing search algorithms are prone to getting stuck in local optima during autofocus, have poor anti-interference capabilities, resulting in prolonged focusing time and a poor user experience.
A distributed focusing method is adopted, which involves parameter initialization, obtaining the image sharpness compression baseline, preliminary focusing and fine focusing range, combined with motor rotation and sharpness ratio traversal, to quickly search for the peak position of image sharpness and use backlash deviation to compensate for errors.
It achieves fast focusing, improves focusing accuracy and user experience, reduces the risk of repeatedly exceeding the sharpness peak, and enhances the accuracy of the focusing process.
Smart Images

Figure CN116489511B_ABST
Abstract
Description
[0001] This application is a divisional application based on the original application with application number 202111220532.2, application date October 20, 2021, entitled "An Automatic Focusing Method and System". Technical Field
[0002] This invention relates to the field of image processing, specifically to a fast autofocus method and system. Background Technology
[0003] Currently, most focusing methods are based on contrast-based image information, which mainly include the following steps: selecting the focus window, selecting the sharpness function, and searching for the focus position.
[0004] The search strategy used to find the focus position is a key factor affecting focusing accuracy and speed. Currently, hill-climbing search algorithms are often used to find the focus position, but they have the following problems:
[0005] 1. If the hill climbing search determines that the sharpness ratio has decreased, it will exceed the sharpness peak and easily get trapped in a local optimum, resulting in poor anti-interference ability;
[0006] 2. The hill climbing search involves multiple reverse processes, which increases the impact of the return difference and prolongs the focusing time, resulting in a poor user experience. Summary of the Invention
[0007] To address the shortcomings of existing technologies, this invention provides an autofocus method and system that enables rapid focusing with a small fine-tuning range, high focusing accuracy, and a superior customer experience.
[0008] To achieve the above objectives, the present invention provides the following technical solution:
[0009] An autofocus method is provided, which includes the following steps:
[0010] Parameter initialization;
[0011] Obtain the image sharpness compression baseline value;
[0012] Initial focusing completed;
[0013] Obtain a fine focus range;
[0014] The drive motor rotates to a point closer to the fine focus range, and then iterates through the sharpness ratio of each image within the fine focus range until the image position with the largest sharpness ratio is determined, thus completing the autofocus.
[0015] Preferably, "obtaining the image sharpness compression baseline value" includes the following steps:
[0016] Get the current position of the motor (hall);
[0017] If the current position of the motor hall > midhall, then the starting position of the motor during initial focusing is determined as startHall = farHall, the Hall value at the far focal limit of the motor, and the farthest position that the motor can reach during initial focusing is endHall = nearHall, the Hall value at the near focal limit of the motor.
[0018] If the current position of the motor hall ≤ midhall, then the starting position of the motor during initial focusing is determined as startHall = nearHall, the Hall value at the near-focus limit of the motor, and the farthest position that the motor can reach during initial focusing is endHall = farHall, the Hall value at the far-focus limit of the motor; where midhall = (nearHall + farHall) / 2.
[0019] The drive motor rotates from its current position hall to the motor's initial focusing position startHall, and acquires several images during the rotation process;
[0020] The sharpness ratio of a certain image is used as the image sharpness compression base value BaseC.
[0021] Preferably, "completing preliminary focusing" includes the following steps:
[0022] The motor is driven to rotate, and several focusing positions of the motor during the initial focusing process are acquired in real time during the rotation of the motor.
[0023] If each focusing position of the motor during the initial focusing process is less than the farthest position endHall that the motor can reach during the initial focusing, then the image corresponding to the focusing position is acquired at each focusing position, and the sharpness value of the image corresponding to each focusing position is acquired. The sharpness ratio of each image is acquired according to formula (1), and the sharpness of each image is compressed.
[0024] K(i) = C(i) / BaseC (1);
[0025] If the sharpness ratio K(i-1) of the previous frame image i is the maximum among all sharpness ratios of all images except the current frame image i, then the sharpness ratio Kmaxnext of the next frame image corresponding to the image sharpness peak Kmax is updated to Kmaxnext=K(i).
[0026] Based on this, if the sharpness ratio K(i) of the current frame image i is greater than or equal to the image sharpness peak Kmax, then the image sharpness peak Kmax is updated to Kmax = K(i), the image sharpness peak position maxId corresponding to the image sharpness peak Kmax is updated to maxId = the current focus position of the motor in the initial focusing process, and the sharpness ratio Kmaxpre of the previous frame image corresponding to the image sharpness peak Kmax is updated to Kmaxpre = the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i, and the number of consecutive unupdated frames Nmax is updated to Nmax = 0.
[0027] After updating the image sharpness peak Kmax, the image sharpness peak position maxId, and the sharpness ratio Kmaxpre of the previous frame image, the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i is updated to Kpre=K(i).
[0028] Preferably, "completing preliminary focusing" also includes the following steps:
[0029] If the sharpness ratio K(i) of the current frame image i is less than the peak image sharpness Kmax, then the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i is directly updated to Kpre = K(i), and the number of consecutive unupdated frames Nmax is incremented by 1;
[0030] If the peak image sharpness Kmax is greater than or equal to the sharpness threshold Kthr of all images after sharpness compression, and the number of consecutive unupdated frames Nmax is greater than or equal to the number of consecutive unupdated sharpness peak frames Nthr, then the initial focusing has been completed.
[0031] Preferably, if the peak image sharpness Kmax is less than the sharpness threshold Kthr of all images after sharpness compression, and / or the number of consecutive unupdated frames Nmax is less than the frame number threshold Nthr of the peak sharpness, then the above "complete initial focusing" step is repeated until the peak image sharpness Kmax is greater than or equal to the sharpness threshold Kthr of all images after sharpness compression, and the number of consecutive unupdated frames Nmax is greater than or equal to the frame number threshold Nthr of the peak sharpness.
[0032] Preferably, "obtaining the fine focus range" includes the following steps:
[0033] The return deviation is obtained based on the focusing position of the motor rotating in the forward and reverse directions, and the image sharpness peak position maxId corresponding to the image sharpness peak Kmax is corrected to obtain the corrected image sharpness peak position maxId'.
[0034] The fine focus range is obtained by using the ratio of the sharpness of the previous and next frames of the image corresponding to the peak sharpness Kmax, and the corrected peak sharpness position maxId'.
[0035] Preferably, the step of “obtaining the fine focus range based on the ratio of sharpness of the previous and next frames of the image corresponding to the peak image sharpness Kmax and the corrected peak image sharpness position maxId” includes the following steps:
[0036] If the sharpness ratio Kmaxpre of the previous frame corresponding to the peak sharpness Kmax is greater than or equal to the sharpness ratio Kmaxnext of the next frame corresponding to the peak sharpness Kmax, then the fine focus range is determined to be maxId'-vMax / f to maxId'; otherwise, the fine focus range is maxId' to maxId'+vMax / f; where f is the frame rate of the image device and 1 / f is the time interval between two frames.
[0037] Preferably, if the fine focusing range is maxId'~maxId'+vMax / f, and the motor starting position startHall during initial focusing is equal to the Hall value nearHall at the motor near focus limit, then the end closer to the fine focusing range is maxId'+vMax / f.
[0038] If the fine focus range is maxId'~maxId'+vMax / f, and the motor's starting position startHall during initial focusing is equal to the Hall value farHall at the motor's far focus limit, then the end closer to the fine focus range is maxId'.
[0039] If the fine focus range is maxId'-vMax / f~maxId', and the motor's starting position startHall during initial focusing is equal to the Hall value nearHall at the motor's near-focus limit, then the end closer to the fine focus range is maxId'.
[0040] If the fine focus range is maxId'-vMax / f to maxId', and the motor's starting position startHall during initial focusing is equal to the Hall value farHall at the motor's far focus limit, then the end closer to the fine focus range is maxId'-vMax / f.
[0041] Preferably, if each focusing position of the motor during the initial focusing process is greater than or equal to the farthest position endHall that the motor can reach during the initial focusing, then the step of "driving the motor to rotate to the end closer to the fine focusing range according to the fine focusing range, and then traversing the sharpness ratio of each image within the fine focusing range until the image position with the largest sharpness ratio is determined to complete the autofocus" is executed directly.
[0042] An autofocus system for implementing the above-described autofocus method is also provided, comprising:
[0043] Motor position acquisition unit, which is used to acquire the motor position;
[0044] The parameter initialization unit, which is connected to the motor position acquisition unit, is used to determine the starting position of the motor during initial focusing and the farthest position that the motor can reach during initial focusing.
[0045] A compression base value acquisition unit, which is connected to the parameter initialization unit, is used to take the sharpness ratio of a certain image as the image sharpness compression base value;
[0046] The preliminary focusing unit is used to complete the preliminary focusing based on the current focusing position of the motor during the preliminary focusing process obtained during the rotation of the drive motor and several images corresponding to each focusing position.
[0047] The return deviation acquisition unit is used to acquire the return deviation based on the focusing position of the motor rotating in the forward and reverse directions;
[0048] A peak position correction unit, which is connected to the hysteresis deviation acquisition unit, is used to correct the image sharpness peak position corresponding to the image sharpness peak to obtain the corrected image sharpness peak position.
[0049] A fine focus range acquisition unit, which is connected to the peak position correction unit, is used to acquire the fine focus range based on the sharpness ratio of the previous frame and the next frame of the image corresponding to the image sharpness peak and the corrected image sharpness peak position.
[0050] The sharpness comparison unit, which is connected to the fine focus range acquisition unit, is used to determine the image position with the largest image sharpness ratio when the motor is quickly driven to rotate to a position closer to the fine focus range according to the fine focus range, and then the sharpness ratio of each image within the fine focus range is traversed, so as to complete the autofocus.
[0051] Compared with the prior art, the present invention has the following beneficial effects:
[0052] This invention uses a distributed focusing method to quickly find the peak position of image sharpness, achieving rapid focusing without the need for active rangefinders or other components. It also has a small fine-tuning range, eliminating the perception of repeatedly exceeding the peak value. Therefore, customers can more accurately grasp the upward trend of image sharpness during focusing, improving the customer experience. At the same time, it uses backlash compensation to compensate for the forward and reverse errors caused by motor rotation, further ensuring focusing accuracy. Attached Figure Description
[0053] Figure 1 This is a flowchart of the automatic focusing method of the present invention;
[0054] Figure 2 This is a schematic diagram of the automatic focusing system of the present invention. Detailed Implementation
[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0056] Example 1:
[0057] This embodiment provides an autofocus method, such as Figure 1 As shown, it includes the following steps:
[0058] S0. Initialize the autofocus parameters, which includes the following steps:
[0059] Set the peak image sharpness Kmax of the compressed image to 1, the sharpness ratio Kmaxpre of the previous frame corresponding to the peak image to 0, the sharpness ratio Kmaxnext of the next frame corresponding to the peak image to 0, the image sharpness peak position maxId corresponding to the peak image Kmax to 0, the number of consecutive unupdated frames Nmax to 0, the image sharpness compression base value BaseC to 0, the sharpness ratio Kpre of the previous frame of the current frame to 0, and the sharpness ratio of the previous frame of the current frame to the maximum value among all the sharpness ratios of the remaining images excluding the current frame image, ifMaxpre to 0.
[0060] Then, reassign values to each parameter according to S1 to S4 below to update each parameter, which specifically includes the following steps;
[0061] S1. Obtain the image sharpness compression baseline value, which includes the following steps:
[0062] In this embodiment, the motor starting position startHall for initial focusing is determined based on the current position hall of the motor. The motor is driven to rotate from the current position hall to the starting position startHall for initial focusing. During the rotation, several images are acquired, and the sharpness ratio of a certain image is used as the image sharpness compression base value BaseC.
[0063] The specific process is as follows:
[0064] S11. Obtain the current position of the motor (hall);
[0065] S12. If the current position of the motor hall > midhall, then determine the starting position of the motor during initial focusing: startHall = Hall value farHall at the far focal limit of the motor, and the farthest position that the motor can reach during initial focusing: endHall = Hall value nearHall at the near focal limit of the motor.
[0066] If the current position of the motor hall ≤ midhall, then the starting position of the motor during initial focusing is determined as startHall = nearHall, the Hall value at the near focus limit of the motor, and the farthest position that the motor can reach during initial focusing is endHall = farHall, the Hall value at the far focus limit of the motor.
[0067] Where, midhall = (nearHall + farHall) / 2;
[0068] S13. Drive the motor to rotate from the current position hall to the motor's starting position startHall when initial focusing is performed, and acquire several images during the rotation process;
[0069] S14. Use the sharpness ratio of a certain image as the image sharpness compression base value BaseC; wherein, the certain image can be the image obtained when the motor moves to the starting position startHall of the motor.
[0070] S2. Complete the initial focusing, which includes the following steps:
[0071] The motor is driven to rotate at the maximum speed vMax, and several focusing positions of the motor during the initial focusing process are acquired in real time during the rotation of the motor: hall1', hall2'... hall(i-1)', hall(i)', hall(i+1)'... (i≥2 and are positive integers); in this embodiment, the value of the maximum speed vMax is between 800 and 1000pps.
[0072] If each focusing position of the motor during the initial focusing process is less than the farthest position endHall that the motor can reach during the initial focusing, then at each focusing position, the images 1, 2...i-1, i, i+1... corresponding to that focusing position are obtained, and the sharpness values C(1), C(2)...C(i-1), C(i), C(i+1)... corresponding to each focusing position hall1', hall2'...hall(i-1)', hall(i)', hall(i+1)'... are obtained respectively. The sharpness ratio K(i) of each image is obtained according to formula (1), and the sharpness of each image is compressed.
[0073] K(i) = C(i) / BaseC (1);
[0074] For example, the motor first rotates to the focus position hall1', then obtains the sharpness ratio C(1) of the image corresponding to the focus position hall1', calculates the sharpness ratio K(1), and compresses the image sharpness. Then the motor continues to rotate to the focus position hall2', repeats the above steps, and obtains the sharpness ratio K(2) of the next image. ... This process is repeated until the sharpness ratio of the image corresponding to each focus position is obtained, and the sharpness of each image is compressed.
[0075] If the sharpness ratio K(i-1) of the previous frame image i is the maximum sharpness ratio among all images except the current frame image i (i.e., ifMaxpre = 1), then the sharpness ratio Kmaxnext of the next frame image corresponding to the image sharpness peak Kmax is updated to Kmaxnext = K(i); if the sharpness ratio K(i-1) of the previous frame image i is not the maximum sharpness ratio among all images except the current frame image i (i.e., ifMaxpre ≠ 1), then there is no need to update the sharpness ratio Kmaxnext of the next frame image corresponding to the image sharpness peak Kmax, and the following judgment steps are directly entered.
[0076] Based on this, if the sharpness ratio K(i) of the current frame image i is greater than or equal to the image sharpness peak Kmax, then the image sharpness peak Kmax is updated to Kmax = K(i), the image sharpness peak position maxId corresponding to the image sharpness peak Kmax is updated to maxId = the current focus position of the motor during the initial focusing process, and the sharpness ratio Kmaxpre of the previous frame image corresponding to the image sharpness peak Kmax is updated to Kmaxpre = the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i, and the number of consecutive unupdated frames Nmax is updated to Nmax = 0; furthermore, after completing the update of Kmax, maxId and Kmaxpre, the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i is updated to Kpre = K(i) to reassign Kpre.
[0077] If the sharpness ratio K(i) of the current frame image i is less than the peak image sharpness Kmax, then the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i is directly updated to Kpre = K(i), and the number of consecutive unupdated frames Nmax is incremented by 1;
[0078] Furthermore, if the peak image sharpness Kmax is greater than or equal to the sharpness threshold Kthr of all images after sharpness compression, and the number of consecutive unupdated frames Nmax is greater than or equal to the number of consecutive unupdated sharpness peak frames Nthr, then it is considered that the image sharpness peak has been surpassed and the initial focusing has been completed. At this time, the peak image sharpness Kmax, the position maxId of the peak image sharpness corresponding to the peak image sharpness Kmax, the sharpness ratio Kmaxnext of the next frame of the image corresponding to the peak image sharpness Kmax, and the sharpness ratio Kmaxpre of the previous frame of the image corresponding to the peak image sharpness Kmax are saved.
[0079] S3. If the peak image sharpness Kmax is less than the sharpness threshold Kthr of all images after sharpness compression, and / or the number of consecutive unupdated frames Nmax is less than the frame number threshold Nthr of the peak image sharpness, then repeat step S2 to update the corresponding parameters until the peak image sharpness Kmax is greater than or equal to the sharpness threshold Kthr of all images after sharpness compression, and the number of consecutive unupdated frames Nmax is greater than or equal to the frame number threshold Nthr of the peak image sharpness.
[0080] S4. Obtain the fine focus range, which includes the following steps:
[0081] When focusing on the same scene multiple times, the return deviation returnDeta is obtained based on the focusing position of the motor rotating in the forward and reverse directions (which can be measured separately by the calibration device). The updated image sharpness peak position maxId corresponding to the image sharpness peak Kmax is corrected according to formula (2) to obtain the corrected image sharpness peak position maxId':
[0082] maxId'=maxId±returnDeta (2);
[0083] The fine focus range is obtained based on the ratio of sharpness to the sharpness of the previous and next frames of the image corresponding to the peak sharpness Kmax, and the corrected peak sharpness position maxId'. This involves the following steps:
[0084] If the sharpness ratio Kmaxpre of the previous frame corresponding to the peak image sharpness Kmax is greater than or equal to the sharpness ratio Kmaxnext of the next frame corresponding to the peak image sharpness Kmax, then the fine focus range is determined to be maxId'-vMax / f to maxId'; otherwise, the fine focus range is maxId' to maxId'+vMax / f; where f is the frame rate of the image device and 1 / f is the time interval between two frames.
[0085] And S5, according to the fine focus range, quickly drive the motor to rotate to the end closer to the fine focus range, and then slowly traverse the sharpness ratio of each image within the fine focus range until the image position with the largest sharpness ratio is determined to complete the autofocus;
[0086] If the fine focusing range is maxId'~maxId'+vMax / f, and the motor starting position startHall during initial focusing is equal to the Hall value nearHall at the motor near focus limit, then the end closer to the fine focusing range is maxId'+vMax / f.
[0087] If the fine focus range is maxId'~maxId'+vMax / f, and the motor's starting position startHall during initial focusing is equal to the Hall value farHall at the motor's far focus limit, then the end closer to the fine focus range is maxId'.
[0088] Similarly, if the fine focus range is maxId'-vMax / f~maxId', and the motor's starting position startHall during initial focusing is equal to the Hall value nearHall at the motor's near-focus limit, then the end closer to the fine focus range is maxId'.
[0089] If the fine focus range is maxId'-vMax / f to maxId', and the motor's starting position startHall during initial focusing is equal to the Hall value farHall at the motor's far focus limit, then the end closer to the fine focus range is maxId'-vMax / f.
[0090] Furthermore, if each focusing position of the motor during the initial focusing process is greater than or equal to the farthest position that the motor can reach during the initial focusing, endHall, then step S5 is executed directly.
[0091] Therefore, in this embodiment, the image sharpness compression baseline is determined first through parameter initialization, then the image sharpness ratio is compressed, and then fast preliminary focusing and slow fine focusing (i.e., distributed focusing method) are completed sequentially according to the compressed image sharpness ratio. This allows for rapid search of the peak position of image sharpness, achieving fast focusing without the need for active rangefinders or other components. Moreover, the fine focusing range is small, and there is no perceptual overshooting of the peak. Therefore, customers can more accurately grasp the upward trend of image sharpness during focusing, improving the customer experience. At the same time, the backlash error is used to compensate for the forward and reverse errors caused by the motor rotation, further ensuring focusing accuracy.
[0092] Example 2:
[0093] This embodiment provides an autofocus system that implements the autofocus method described in Embodiment 1, such as... Figure 2 As shown, it includes:
[0094] Motor position acquisition unit 1 is used to acquire the position of the motor; in this embodiment, the motor position acquisition unit 1 includes position detection devices such as photoelectric sensors;
[0095] The parameter initialization unit 2 is connected to the motor position acquisition unit 1 and is used to determine the starting position of the motor during initial focusing and the farthest position that the motor can reach during initial focusing. The determination process is the same as step S12 and will not be repeated here.
[0096] Compression base value acquisition unit 3, which is connected to the parameter initialization unit 2, is used to take the sharpness ratio of a certain image as the image sharpness compression base value; the image comes from the process of the drive motor rotating from the current position to the motor's starting position when it is initially focusing;
[0097] The preliminary focusing unit 4 is used to complete the preliminary focusing based on the current focusing position of the motor during the preliminary focusing process obtained during the process of driving the motor to rotate at the maximum speed vMax and the image corresponding to each focusing position. Its preliminary focusing process is the same as steps S2-S3, and will not be described again.
[0098] The return deviation acquisition unit 5 is used to acquire the return deviation based on the focusing position of the motor rotating in the forward and reverse directions.
[0099] Peak position correction unit 6, which is connected to the back deviation acquisition unit 5, is used to correct the image sharpness peak position corresponding to the image sharpness peak according to formula (2) so as to obtain the corrected image sharpness peak position.
[0100] The fine focus range acquisition unit 7 is connected to the peak position correction unit 6. It is used to acquire the fine focus range based on the sharpness ratio of the previous frame and the next frame of the image corresponding to the image sharpness peak and the corrected image sharpness peak position. The acquisition process is the same as step S4 and will not be described again.
[0101] The sharpness comparison unit 8 is connected to the fine focus range acquisition unit 7. When the motor is quickly driven to rotate to a position closer to the fine focus range according to the fine focus range, and then the sharpness ratio of each image within the fine focus range is traversed, the position of the image with the largest image sharpness ratio is determined to complete the autofocus. The process is the same as step S5 and will not be described again.
[0102] In summary, this invention sequentially performs rapid initial focusing and slow fine focusing (i.e., a distributed focusing method) based on the compressed image sharpness ratio. This allows for rapid location of the peak image sharpness position, achieving fast focusing without the need for active rangefinders or other components. Furthermore, the fine focusing range is relatively small, eliminating the perception of multiple peak crossings. As a result, customers can more accurately grasp the upward trend of image sharpness during focusing, enhancing the customer experience. Additionally, the invention employs backlash compensation to offset forward and reverse errors caused by motor rotation, further ensuring focusing accuracy.
[0103] It should be noted that the technical features in embodiments 1 and 2 above can be combined arbitrarily, and the resulting technical solutions all fall within the protection scope of this application. Furthermore, in this document, terms such as "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0104] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for assigning image sharpness values for autofocus, characterized in that, The image sharpness assignment method includes the following steps: Obtain the image sharpness compression baseline value; The image sharpness is compressed according to the image sharpness compression base value; And assign a value to the image sharpness ratio based on the sharpness of the compressed image; Image sharpness is compressed based on the image sharpness compression baseline, including the following steps: The motor is driven to rotate, and several focusing positions of the motor during the initial focusing process are acquired in real time during the rotation of the motor. If each focus position of the motor during the initial focusing process is less than the farthest position endHall that the motor can reach during the initial focusing, then the image corresponding to the focus position is acquired at each focus position, and the sharpness value of the image corresponding to each focus position is acquired. The sharpness ratio K(i) of each image is acquired according to formula (1), and the sharpness of each image is compressed. K(i) = C(i) / BaseC (1) Where C(i) is the sharpness ratio of the image corresponding to each focus position; BaseC is the image sharpness compression base value; Assigning values to the image sharpness ratio based on the sharpness of the compressed image includes the following steps: If the sharpness ratio K(i-1) of the previous frame image i is the maximum among all sharpness ratios of all images except the current frame image i, then the sharpness ratio Kmaxnext of the next frame image corresponding to the image sharpness peak Kmax is updated to Kmaxnext = K(i). Assigning values to the image sharpness ratio based on the sharpness of the compressed image includes the following steps: If the sharpness ratio K(i) of the current frame image i is greater than or equal to the image sharpness peak Kmax, then update the image sharpness peak Kmax to Kmax = K(i), update the image sharpness peak position maxId corresponding to the image sharpness peak Kmax to maxId = the current focus position of the motor in the initial focusing process, update the sharpness ratio Kmaxpre of the previous frame image corresponding to the image sharpness peak Kmax to Kmaxpre = the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i, and update the number of consecutive unupdated frames Nmax to Nmax = 0; Assigning values to the image sharpness ratio based on the sharpness of the compressed image includes the following steps: After updating the image sharpness peak Kmax, the image sharpness peak position maxId, and the sharpness ratio Kmaxpre of the previous frame image, the sharpness ratio Kpre of the previous frame image i-1 of the current frame image i is updated to Kpre=K(i).
2. The image sharpness assignment method as described in claim 1, characterized in that, Obtaining the image sharpness compression baseline includes the following steps: Get the current position of the motor (hall); The drive motor rotates from its current position hall to the motor's initial focusing position startHall, and acquires several images during the rotation process; The sharpness ratio of a certain image is used as the image sharpness compression base value BaseC.
3. The image sharpness assignment method as described in claim 2, characterized in that, If the current position of the motor hall > midhall, then the starting position of the motor during initial focusing is determined as startHall = farHall, the Hall value at the far focus limit of the motor, and the farthest position that the motor can reach during initial focusing is endHall = nearHall, the Hall value at the near focus limit of the motor. If the current position of the motor hall ≤ midhall, then the starting position of the motor during initial focusing is determined as startHall = nearHall, the Hall value at the near focus limit of the motor, and the farthest position that the motor can reach during initial focusing is endHall = farHall, the Hall value at the far focus limit of the motor, where midhall = (nearHall + farHall) / 2.
4. A focusing method, characterized in that, Including the image sharpness assignment method according to any one of claims 1-3.
5. The focusing method as described in claim 4, characterized in that, If the sharpness ratio K(i) of the current frame image i is less than the peak image sharpness Kmax, then directly update the sharpness ratio Kpre of the previous frame image i-1 to Kpre = K(i), and increment the number of consecutive unupdated frames Nmax by 1. If the peak image sharpness Kmax is greater than or equal to the sharpness threshold Kthr of all images after sharpness compression, and the number of consecutive unupdated frames Nmax is greater than or equal to the number of consecutive unupdated sharpness peak frames Nthr, then focusing is complete.
Citation Information
Patent Citations
Automatic focusing method
CN101236289A
