Focusing method, device, electronic equipment and storage medium

By controlling the motor in the infrared camera to drive the lens to move in steps and obtaining the image clarity evaluation value, stopping the movement according to the change rate condition, and selecting the optimal focusing position, the problem of long focusing time in the existing technology is solved and the efficiency is improved. and user experience.

CN114460791BActive Publication Date: 2024-09-06YANTAI RAYTRON TECH CO LTD
View PDF 20 Cites 0 Cited by

Patent Information

Application Number
CN202210217352.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-07
Publication Date
2024-09-06
Estimated Expiration
2042-03-07

AI Technical Summary

Technical Problem

The focusing time of existing infrared cameras is long, especially with large lenses and heavy metal casings. Manual focusing operations are cumbersome, and the automatic focusing method relies on a hill-climbing search algorithm, which results in long focusing times and affects the user experience.

Method used

By controlling the motor to drive the lens to move in one step, the image sharpness evaluation value of each position is obtained. When the change rate of the sharpness evaluation value meets the preset conditions, the movement stops, and the evaluation value that meets the conditions is selected to determine the preferred focusing position. , and then determine the target focusing position.

Benefits of technology

It enables quick search for image clarity evaluation values ​​that meet preset conditions, reduces focusing time, and improves focusing efficiency and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114460791B
    Figure CN114460791B
Patent Text Reader

Abstract

The present application provides a focusing method, device, equipment and storage medium, wherein the focusing method controls a motor to drive a lens to move with a first step length, and in the process of the motor driving the lens with the first step length, obtains a first image clarity evaluation value corresponding to each moving position of the first step length, and when the change rate of the first image clarity evaluation value meets a preset change rate condition, stops controlling the motor to drive the lens to move with the first step length, and selects the first image clarity evaluation value that meets a first preset condition to determine a first preferred focusing position based on the first image clarity evaluation value, and finally determines the target focusing position of the lens based on the first preferred focusing position. Therefore, the focusing method provided by the present application can quickly search for the first image clarity evaluation value that meets the preset condition and determine its corresponding preferred focusing position, effectively improving the focusing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of camera photography and videography, and in particular to a focusing method, device, electronic equipment and storage medium. Background Art

[0002] In infrared camera products, the clarity and contrast of the image directly affect the effects of temperature measurement and monitoring. After the product is formed, how to make the lens have the best imaging effect on the target, that is, in the best focusing position, becomes an urgent problem to be solved. Traditional focusing methods include manual focusing and automatic focusing. Manual focusing is cumbersome and unrealistic in some scenarios. For example, forest fire prevention infrared lenses are large and are often wrapped in bulky metal casings, making manual focusing very inconvenient. Therefore, automatic focusing technology, which can automatically adjust the optimal focusing position without manual interference, has become an increasingly important research focus in industry and academia.

[0003] The automatic focusing method based on image quality relies on the clarity evaluation value of the imaging target at different focal lengths, combined with a certain search algorithm to determine the peak value of the clarity evaluation value of the imaging target, and then determines the optimal focusing position based on the clarity evaluation peak value. Therefore, a suitable search algorithm is crucial for focusing. Determining the peak value of the clarity evaluation value based on the hill climbing search algorithm is a common method in automatic focusing. However, this method requires a full range of travel to find the maximum peak during the focusing process, which requires a long focusing time and brings a poor user experience. Summary of the invention

[0004] In order to solve the existing technical problems, the present application provides a fast focusing method, device, equipment and storage medium.

[0005] A focusing method, comprising:

[0006] Control the motor to drive the lens to move in the first step;

[0007] In the process of the motor driving the lens to move with the first step length, obtaining a first image clarity evaluation value corresponding to each moving position of the first step length;

[0008] When the change rate of the first image definition evaluation value meets a preset change rate condition, stopping the control motor to drive the lens to move at the first step;

[0009] Selecting the first image clarity evaluation value that meets a first preset condition from among the acquired first image clarity evaluation values ​​to determine a first preferred focusing position;

[0010] According to the first preferred focusing position, a target focusing position of the lens is determined.

[0011] A focusing device, comprising:

[0012] A movement control module, used for controlling the motor to drive the lens to move in the first step;

[0013] An evaluation value acquisition module, used for acquiring a first image clarity evaluation value corresponding to each moving position of the first step in the process in which the motor drives the lens to move with the first step;

[0014] A stop control module, configured to stop the control motor from driving the lens to move at the first step length when the change rate of the first image definition evaluation value meets a preset change rate condition;

[0015] a preferred focus position determining module, configured to select the first image clarity evaluation value that meets a first preset condition from among the acquired first image clarity evaluation values ​​to determine a first preferred focus position;

[0016] A target focusing position determining module is used to determine a target focusing position of the lens according to the first preferred focusing position.

[0017] A focusing electronic device comprising a memory and a processor;

[0018] When the processor runs the computer program instructions stored in the memory, the processor executes the steps of the focusing method.

[0019] A computer-readable storage medium, characterized in that the computer-readable storage medium stores computer program instructions;

[0020] When the computer program instructions are executed by the processor, the steps of the focusing method described above are implemented.

[0021] As can be seen from the above, in the focusing method, device, equipment and storage medium provided by the present application, the motor is controlled to drive the lens to move with the first step length, and in the process of the motor driving the lens with the first step length, the first image clarity evaluation value corresponding to each moving position of the first step length is obtained, and when the change rate of the first image clarity evaluation value meets the preset change rate condition, the control motor is stopped to drive the lens to move with the first step length, and according to the first image clarity evaluation value, the first image clarity evaluation value that meets the first preset condition is selected to determine the first preferred focusing position, and finally, according to the first preferred focusing position, the target focusing position of the lens is determined. Therefore, the focusing method provided by the present application can quickly search for the first image clarity evaluation value that meets the preset condition and determine its corresponding preferred focusing position, which effectively improves the focusing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The accompanying drawings are only used to illustrate the embodiments and are not to be considered as limiting the present invention. In addition, the same reference symbols are used to represent the same components throughout the accompanying drawings. In the accompanying drawings:

[0023] Figure 1 A schematic diagram of a flow chart of a focusing method provided according to some embodiments of the present application;

[0024] Figure 2 A schematic diagram of a flow chart of a focusing process based on a first-stage focusing result in a focusing method provided in some embodiments of the present application;

[0025] Figure 3 A schematic flow chart of a second-stage focusing process based on an improved hill climbing algorithm in a focusing method provided in some embodiments of the present application;

[0026] Figure 4 A schematic flow chart of an improved hill climbing algorithm used in the second-stage focusing process in the focusing method provided in some embodiments of the present application;

[0027] Figure 5 A schematic diagram of a flow chart of a focusing process based on a focusing result of the second stage in a focusing method provided in some embodiments of the present application;

[0028] Figure 6 A schematic diagram of a flow chart of a focusing method provided according to other embodiments of the present application;

[0029] Figure 7 A schematic diagram of a flow chart of a focusing process when changing magnification in a focusing method provided according to some embodiments of the present application;

[0030] Figure 8 A focusing device provided according to some embodiments of the present application;

[0031] Fig. 9 A focusing device is provided according to some embodiments of the present application. DETAILED DESCRIPTION

[0032] The technical solution of the present application is further elaborated in detail below in conjunction with the accompanying drawings and specific embodiments of the specification.

[0033] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit the implementation of this application. The term "and / or" used herein includes any and all combinations of one or more related listed items.

[0034] In the following description, reference is made to “some embodiments” which describe a subset of possible embodiments, but it should be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0035] Based on the problem of long focusing time in existing infrared focusing technology, the present application provides a focusing method, device, equipment and storage medium. Figures 1 to 7 1 and 2 are flowcharts of the focusing process in different embodiments according to the focusing method provided in the present application. The focusing method provided in the present application can be used in the following embodiments: Figure 8 The focusing device shown and Fig. 9 The focusing device shown in the figure is implemented. Figures 1 to 9 A relatively detailed description is given of the focusing method, device, equipment and storage medium provided in this application.

[0036] See also Figure 1 In some embodiments, the focusing method provided in the present application includes S21, S22, S23, S24 and S40.

[0037] S21: Control the motor to drive the lens to move in the first step.

[0038] S21 can be Figure 8 The mobile control module 101 in the focusing device shown in the figure is implemented, or by Fig. 9 The memory 202 in the focusing device shown in the figure stores the corresponding movement control program, which is then Fig. 9 The processor 201 in the focusing device shown is implemented when executing the movement control program stored in the memory 202 .

[0039] During the process of automatically focusing the lens of the camera device, the motor drives the lens to move according to a certain movement strategy, and finally moves the lens to the best focusing position, so that the image clarity evaluation value of the image captured by the lens is maximized, that is, the image captured by the lens is the clearest. In the present application, the camera device can be an infrared camera device or a visible light camera device. The focusing method provided in the present application is used to achieve the focusing of the large lens of the camera device. In addition, it should be noted that the subsequent motor movement refers to the movement of the lens driven by the motor.

[0040] When starting the focus adjustment, the motor is first controlled to move in a certain direction with the first step length, and during the movement, the moving direction is changed according to the image clarity evaluation value obtained subsequently. In order to reduce the number of times the motor switches its moving direction during the focusing process, when starting the focus adjustment, the motor can be controlled to move in the farther direction with the first step length. The farther end here refers to the end of the motor's initial position during the first stage of focusing that is farther from the two end points of the motor's moving position range.

[0041] S22: When the motor drives the lens to move with the first step length, a first image clarity evaluation value corresponding to each moving position of the first step length is obtained.

[0042] S22 can be Figure 8 The evaluation value acquisition module 102 in the focusing device shown in FIG. Fig. 9 The memory 202 in the focusing device shown in the figure stores the corresponding evaluation value acquisition program, which is then Fig. 9 The processor 201 in the illustrated focusing device is implemented when executing the evaluation value acquisition program stored in the memory 202 .

[0043] After the control motor drives the lens to start moving with the first step length, each time the motor moves one step with the first step length, a corresponding moving position is obtained, and the first image clarity evaluation value of the image captured by the lens at the moving position is obtained. Specifically, the first image clarity evaluation value of each captured image can be obtained based on the image clarity evaluation function. The image clarity evaluation function can be, but is not limited to, an energy gradient function, a Roberts gradient function, a Sobel gradient function, a variance function, etc. The first image clarity evaluation value of the captured image can be a clarity evaluation value of the entire image of the captured image, or it can be a clarity evaluation value corresponding to a region of interest in the captured image.

[0044] S23: When the change rate of the first image definition evaluation value meets a preset change rate condition, stop the control motor to drive the lens to move with the first step.

[0045] S23 can be Figure 8 The stop control module 103 in the focusing device shown in FIG. Fig. 9 The memory 202 in the focusing device shown in the figure stores the corresponding stop control program, which is then Fig. 9 The processor 201 in the focusing device shown is implemented when executing the stop control program stored in the memory 202 .

[0046] In the process of the motor driving the lens to move in the first step, it is necessary to find the peak value of the first image clarity evaluation value within the moving range of the motor, that is, to search for the global peak value within the moving range of the motor. In the process of research, the inventor of the present application found that when searching for the global peak value (the peak value of the image clarity evaluation value corresponding to each moving position), the growth rate of the consecutive frames before the peak value is high, and the decline rate after the peak value is also high, while the corresponding change rate before and after the local extreme value of each first image clarity evaluation value is small. According to this feature, the inventor of the present application uses whether the change rate of the first image clarity evaluation value meets the preset change rate condition to control the end time of the process of the motor driving the lens to move in the first step in the first stage of focusing. That is, when the change rate of the first image clarity evaluation value meets the preset change rate condition, the motor driving the lens to move in the first step is stopped, so that it is not necessary to control the motor to move in the entire motor moving range before obtaining the first preferred focusing position, which can effectively reduce the focusing time.

[0047] It should be noted here that the rate of change of the first image clarity evaluation value includes a growth rate and a decrease rate. When the growth rate is represented by a number greater than 0 and the decrease rate is represented by a number less than 0, the size of the change rate refers to the size of the growth rate or the size of the decrease rate, that is, the size of the change rate is the absolute value of the growth rate or the decrease rate. The preset change rate can be set according to the robustness performance requirements and accuracy performance requirements of the focus, and it can be set based on experience. The larger the value of the preset change rate is set, the more accurate the focus may be, but the robustness is not good (that is, the number of adapted scenes is small), and the smaller the value of the preset change rate is set, the better the robustness, but the corresponding focusing accuracy will decrease. Therefore, different preset change rates can be set according to different scenes, such as indoors and outdoors.

[0048] In some embodiments, S23: when the change rate of the first image definition evaluation value meets a preset change rate condition, stopping the control motor to drive the lens to move at the first step length further includes:

[0049] S231: Calculate a change rate of the first image clarity evaluation value corresponding to the current moving position of the motor relative to the first image clarity evaluation value corresponding to a preset moving position of the motor before the current moving position.

[0050] S232: Determine whether the absolute value of the change rate in S231 is greater than or equal to a preset threshold value, and if so, stop the control motor to drive the lens to move at the first step.

[0051] Specifically, in some embodiments, if the preset moving position before the current moving position is 2 moving positions before the current moving position, the calculation formula for the change rate of the first image clarity evaluation value is as follows:

[0052]

[0053] Wherein, F3 is the first image clarity evaluation value corresponding to the captured image of the current frame, and F1 is the first image clarity evaluation value corresponding to the captured images of the first two frames before the current frame. If the captured images of the first two frames are the first frame, then the current frame is the third frame. Wherein, abs in the above formula represents taking the absolute value, and thres is the preset threshold value, which can be set according to the actual scene, such as 0.02. In addition, the specific number of the preset values ​​can be set according to the actual value. In this embodiment, it is set to 2, that is, in the first image clarity evaluation value obtained, the first image clarity evaluation value corresponding to every three consecutive frames needs to be calculated once as shown in the above formula to obtain the corresponding rate of change.

[0054] S24: Selecting the first image clarity evaluation value that meets a first preset condition from the acquired first image clarity evaluation values ​​to determine a first preferred focusing position.

[0055] S24 can be Figure 8 The preferred focus position determination module 104 in the focus adjustment device shown in FIG. 1 is implemented by Fig. 9 The memory 202 in the focusing device shown in the figure stores the corresponding preferred focusing position determination program, which is then Fig. 9 The processor 201 in the illustrated focusing device is implemented when executing the preferred focusing position determination program stored in the memory 202 .

[0056] After the motor stops moving with the first step length, a first image clarity evaluation value that meets the first preset condition is selected from each of the first image clarity evaluation values ​​as the value to be searched in the stage where the motor drives the lens to move with the first step length, and then the moving position corresponding to the value is used as the first preferred focusing position. In some embodiments, the first preset condition is that the selected first image clarity evaluation value is the maximum value among all first image clarity evaluation values ​​or its size meets the preset size. In some embodiments, after the motor stops moving with the first step length, all currently obtained first image clarity evaluation values ​​are compared, and the largest first image clarity evaluation value is selected as the global peak value to be searched for in the first stage of focusing, and the moving position corresponding to the largest first image clarity evaluation value is used as the first preferred focusing position.

[0057] S40: Determine a target focusing position of the lens according to the first preferred focusing position.

[0058] S40 can be Figure 8 The target focus position determination module 105 in the focus adjustment device shown in FIG. Fig. 9The memory 202 in the focusing device shown in the figure stores the corresponding target focusing position determination program, which is then Fig. 9 The processor 201 in the image focusing device shown is implemented when executing the target focusing position determination program stored in the memory 202 .

[0059] The target focus position is the position of the lens after all the focusing of the lens is completed. After the lens reaches the target focus position, it is used to collect images that meet the user's needs for the user to use. In some embodiments, according to the first preferred focus position, a method for determining the target focus position of the lens is: using the first preferred focus position as the starting point of the next stage of focusing, and then using a smaller moving step size than the first step to control the motor movement to perform the next stage of focusing to determine the target focus position. This focusing method includes multiple stages of focusing, wherein the process of controlling the motor to drive the lens to move with the first step size is the first stage of focusing process. In some other embodiments, the first preferred focus position can also be directly used as the target focus position. This focusing method only includes one stage of focusing.

[0060] As can be seen from the above, in the focusing method provided by the present application, the motor is controlled to drive the lens to move with the first step length, and in the process of the motor driving the lens with the first step length, the first image clarity evaluation value corresponding to each moving position of the first step length is obtained, and when the change rate of the first image clarity evaluation value meets the preset change rate condition, the control motor is stopped to drive the lens to move with the first step length, and according to the first image clarity evaluation value, the first image clarity evaluation value that meets the first preset condition is selected to determine the first preferred focusing position, and finally, according to the first preferred focusing position, the target focusing position of the lens is determined. Therefore, the focusing method provided by the present application can quickly search for the first image clarity evaluation value that meets the preset condition and determine its corresponding preferred focusing position, which effectively improves the focusing efficiency.

[0061] Please refer to Figure 2 , which is a flow chart of focusing according to the result of the first stage focusing in the focusing method according to some embodiments of the present application, that is, in some embodiments, Figure 1 S40 further includes S41, S42 and S60.

[0062] S41: Taking the first preferred focusing position as a starting point, controlling the motor to drive the lens to move with a second step length that is smaller than the first step length.

[0063] In this embodiment, the focusing process of the lens includes not only the above-mentioned first stage focusing, but also further includes a second stage focusing based on the result of the first stage focusing. The second stage focusing process refers to the process of controlling the motor to drive the lens to move in a second step length.

[0064] For the focusing of the infrared camera device, if there is no object with a large temperature difference in the field of view of the infrared camera device, the infrared target has no obvious edge or the image noise is large, the image clarity evaluation value obtained at each moving position of the motor may have multiple local extreme points. If the first preferred focusing position obtained by the first stage focusing step is simply used as the final focusing position, it may fall into the local extreme point and the focusing result is inaccurate. Therefore, in the focusing method of the present application, during the first stage focusing, the first step length can be set to a larger step length (such as the range of the first step length can be [0,1 / 2] of the entire lens focusing range) to complete the coarse focusing, and then the next stage of focusing is performed based on the focusing result of the coarse focusing operation, that is, the second stage focusing in S41.

[0065] During the second stage of focusing, the moving step length of the motor is set smaller than that of the first stage of focusing, that is, the second step length is smaller than the first step length, and the second stage of focusing is fine focusing relative to the first stage of focusing which is coarse focusing. The starting point of the second stage of focusing is determined as the first preferred focusing position determined in the first stage of focusing, and then the motor is controlled to move from the first preferred focusing position to the first direction with a second step length. As with the setting of the initial moving direction of the motor in the first stage of focusing, during the second stage of focusing, the first direction is the current moving position of the motor moving toward a relatively farther end.

[0066] S42: When the motor drives the lens to move with the second step length, a second image clarity evaluation value corresponding to each moving position of the second step length is obtained, and a target image clarity evaluation value of the lens and a corresponding second preferred focusing position are determined according to the second image clarity evaluation value.

[0067] In some embodiments, during the second stage focusing process, the method of obtaining the second image clarity evaluation value corresponding to each moving position of the second step length is the same as the method of obtaining the first image clarity evaluation value, which is not repeated here. During the second stage focusing process, after the target image clarity evaluation value is obtained according to the obtained second image clarity evaluation value, the second stage focusing is terminated.

[0068] S60: Determine a target focusing position of the lens according to the target image clarity evaluation value and the second preferred focusing position.

[0069] Similarly, in some embodiments, according to the second preferred focus position, a method for determining the target focus position of the lens is to use the second preferred focus position as the starting point of the next stage of focus, and then use a smaller moving step than the second step to control the motor to move for the next stage of focus to determine the target focus position, that is, the focusing method includes at least a third stage of focus with a smaller moving step in addition to the first stage of focus and the second stage of focus, and the third stage of focus process is the process of controlling the motor to drive the lens to move with a third step. In some other embodiments, the second preferred focus position can also be directly used as the target focus position.

[0070] In S42, the target image clarity evaluation value of the lens and the corresponding second preferred focus position can be determined based on the hill climbing algorithm according to the second image clarity evaluation value. However, the focusing time required by the hill climbing algorithm is relatively long. Therefore, in order to further reduce the focusing time, the present application provides an improved hill climbing algorithm to implement S42. For details, please refer to Figure 3 In some embodiments, S42 implemented based on the improved hill climbing algorithm includes S421, S422, S423, S424, S425 and S426.

[0071] S421: When the motor drives the lens to move toward the first direction with the second step length, a second image clarity evaluation value corresponding to each moving position of the second step length is obtained, and whether a change in the second image clarity evaluation value satisfies a peak determination condition is determined.

[0072] In the existing hill climbing algorithm, when a certain value rises continuously, it is considered to be climbing a mountain, and when it falls continuously, it is considered to be going down a mountain. After the motor has repeatedly traversed all the strokes, the maximum value obtained in the reverse process is selected as the peak value. In this embodiment, based on the improved hill climbing algorithm to implement the second stage focusing process, the peak judgment condition is reset, so that the target image clarity evaluation value can be determined without the motor moving the entire distance (the range of the motor movement), thereby quickly completing the second stage focusing and improving the focusing efficiency. Therefore, specifically, in some embodiments, the determination of whether the change of the second image clarity evaluation value meets the peak judgment condition includes: determining whether the second image clarity evaluation value increases continuously for a first preset number of times and then decreases continuously for the first preset number of times, and whether the change rate of the second image clarity evaluation value is greater than or equal to the second preset threshold value during the continuous increase process. Therefore, in this embodiment, the peak judgment condition is: whether the second image clarity evaluation value increases continuously for a first preset number of times and then decreases continuously for the first preset number of times, and whether the change rate of the second image clarity evaluation value is greater than or equal to the second preset threshold value during the continuous increase process. That is, when the second image clarity evaluation value rises for multiple consecutive times, it is considered to be climbing. If during the continuous rise, the corresponding change rate is greater than or equal to the second preset threshold, and if it continuously decreases after the continuous rise, it means that the current moving position of the motor has passed the position corresponding to the peak value, and the motor needs to be controlled to move in the opposite direction, that is, S422 is executed. In other embodiments, the peak judgment condition further includes that after the second image clarity evaluation value continuously rises and the change rate meets the preset change rate, it continuously decreases, and the corresponding change rate during the continuous decrease also needs to meet the preset change rate.

[0073] The second preset threshold is consistent with the setting method of the preset change rate in the first stage focusing process, and will not be repeated here.

[0074] S422: When the peak judgment condition is met, control the motor to drive the lens to move in a second direction with the second step length; the second direction is the opposite direction of the first direction.

[0075] S423: When the motor drives the lens to move in the second direction with the second step length, obtain a second image clarity evaluation value corresponding to each moving position, and select the second image clarity evaluation value that meets the second preset condition as a candidate image clarity evaluation value.

[0076] In some embodiments, the second preset condition is: the selected second image clarity evaluation value is the maximum second image clarity evaluation value obtained in the reverse process.

[0077] S424: Determine whether the number of switching times of the movement direction of the lens driven by the motor meets the preset switching number.

[0078] S425: When the preset switching times are met, stop controlling the motor to drive the lens to move with the second step length, and select the candidate image clarity evaluation value that meets the third preset condition as the target image clarity evaluation value.

[0079] In some embodiments, the third preset condition is that the selected candidate image clarity evaluation value is the maximum value among all candidate image clarity evaluation values.

[0080] S426: Using the lens position corresponding to the target clarity evaluation value as the second preferred focusing position.

[0081] During the second stage focusing process, in addition to controlling the reverse rotation of the motor according to the change of the second image clarity evaluation value, the reverse rotation of the motor can also be controlled according to whether the motor is stuck at the limit point and / or whether the current position of the motor is at the position corresponding to the local extreme value.

[0082] Therefore, in some embodiments, the focusing method further includes: during the process of the motor driving the lens to move toward the first direction with the second step length, determining whether the motor is stuck at a stopper point, and if so, controlling the motor to drive the lens to move toward the second direction with the second step length. Specifically, in some embodiments, determining whether the motor is stuck at a stopper point includes: determining whether there are a set number of consecutive second image clarity evaluation value corresponding positions, and whether the potential value of the potentiometer is at the stopper point, and if so, determining that the motor is currently stuck at the stopper point, and needing to control the motor to move in the opposite direction.

[0083] In some embodiments, the focusing method further includes: during the process of the motor driving the lens to move toward the first direction with the second step length, determining whether the current moving position of the motor is at a position corresponding to the local extreme value of the second image clarity evaluation value, and if so, controlling the motor to drive the lens to move toward the second direction with the second step length. Specifically, in some embodiments, determining whether the current moving position of the motor is at a position corresponding to the local extreme value of the second image clarity evaluation value includes: determining that the second image clarity evaluation value corresponding to the captured images of the set number of frames has not decreased for a preset number of consecutive times, indicating that the current moving position of the motor is at a position corresponding to the local extreme value of the second image clarity evaluation value, and it is necessary to control the motor to move in the opposite direction.

[0084] See also Figure 4, which is a flow chart of implementing the second stage focusing process based on the improved hill climbing algorithm provided in the present application. In the present embodiment, after each movement of the motor in the second step length, the potential value corresponding to the potentiometer is obtained, and the potential value is used to characterize the moving position corresponding to the second step length, that is, each second image clarity evaluation value corresponds to a potential value. Before executing the improved hill climbing algorithm, the second image clarity evaluation value is first defined as f(i), and its corresponding potential value is defined as p(i), where i represents the captured image of the i-th lens obtained in the second stage focusing process, and the maximum number of motor reverse times is CountMax (corresponding to the above-mentioned preset switching number), and the maximum value obtained each time in reverse, that is, the candidate image clarity evaluation value is defined as Fmax(k) (k<=CountMax), k is the number of k-th reverse movements, and the corresponding potential value at this time is Pmax(k). According to Figure 4 The method implements the improved hill climbing algorithm, and the process is as follows:

[0085] Sa: parameter initialization, determine the maximum direction times CountMax and the first direction, and set the initial value of the reverse movement times k to 0, and use the largest second image clarity evaluation value among the corresponding second image clarity evaluation values ​​of the first three frames of the current frame of the lens as the currently obtained maximum second image clarity evaluation value Fmax, and its corresponding potential value is Pmax. After executing Sa, execute Sb.

[0086] Sb: Control the motor to move in the first direction with a second step length to perform a second stage of focusing on the lens. The potential value corresponding to the starting position of the second stage of focusing is the potential value corresponding to the first preferred focusing position. After executing Sb, execute Sc.

[0087] Sc: When the motor moves in the first direction with the second step length, i increases once for each step, and the second image clarity evaluation value f(i) and the corresponding potential value p(i) corresponding to each step are calculated. After executing Sc, execute Sd.

[0088] Sd: Determine whether the f(i) corresponding to the next i consecutive frames (generally less than or equal to 3 frames, i.e., i is less than or equal to 3) of captured images are all greater than or equal to Fmax, and compare whether the growth rate corresponding to the i consecutive frames of captured images meets the preset change rate. If so, execute Se, otherwise execute Sf.

[0089] Se: Assign the currently obtained f(i) to Fmax, and assign the currently corresponding p(i) to Pmax, and then execute Sg.

[0090] Sf: Determine whether f(i) corresponding to the next i consecutive frames of captured images are all less than or equal to Fmax.

[0091] Sg: Determine whether f(i) corresponding to the next i consecutive frames of captured images are all greater than or equal to Fmax, and compare whether the growth rate corresponding to the i consecutive frames of captured images meets the preset change rate. If so and the judgment result of Sf is also yes, it means that the motor has passed the peak value and needs to be controlled in the reverse direction. Then execute Sh next, otherwise return to Sb.

[0092] Sh: Control the motor to move in the opposite direction (i.e., move in the second direction opposite to the first direction), add 1 to the value of k, assign the currently obtained Fmax to Fmax(k), and assign the currently corresponding Pmax to Pmax(k), and then execute Sj.

[0093] Sj: Determine whether the current k is greater than or equal to the set maximum number of directions CountMax. If so, execute sl, if not, return to Sb.

[0094] S1: Sort all Fmax(k), obtain the maximum value of Fmax(k), and determine the value as the target image clarity evaluation value DFmax, and use the position corresponding to the potential value Dpmax corresponding to the target clarity evaluation value Dfmax as the second preferred focusing position.

[0095] In addition, continue to read Figure 4 In this embodiment, the process of implementing the second stage focusing based on the improved hill climbing algorithm further includes Sm, which is executed after Sa.

[0096] Sm: Whether the motor is at the limiter point for multiple consecutive frames or the second image clarity evaluation value does not drop for three consecutive frames for multiple consecutive frames. If so, execute Sh, otherwise return to Sb.

[0097] By setting Sm, the motor can be prevented from getting stuck or falling into a local minimum during movement, which is beneficial for quickly achieving accurate focusing.

[0098] It should be noted that, in this embodiment, after the result of Sd is judged as yes, Se is executed to further judge whether the corresponding second image clarity evaluation value continues to increase while the motor continues to move in the first direction. If so, the motor is controlled to reverse only when the result of Sf is judged as yes, that is, the motor has indeed passed the position corresponding to the peak value, which can reduce the probability of misjudgment. In other embodiments, Se may not be necessary, that is, first judge whether the second image clarity evaluation value rises continuously, and whether its corresponding change rate during the continuous rise is greater than or equal to the set threshold change rate. If so, judge whether the second image clarity evaluation value decreases continuously after the continuous rise. If so, control the motor to reverse. As can be seen from the above, in the present application, the second stage focusing process is fine focusing based on the improved hill climbing algorithm, and the fine focusing is performed near the result of coarse focusing.

[0099] In some embodiments, in order to further improve the focusing accuracy, after the second stage focusing, it is necessary to continue to perform the next step of focusing with a smaller motor movement step size according to the result of the second stage focusing. Figure 5 As shown, in some embodiments, S60 further includes S61, S62 and S63.

[0100] S61: Taking the second preferred focusing position as a starting point, controlling the motor to drive the lens to move with a third step length that is smaller than the second step length.

[0101] S62: When the motor drives the lens to move with the third step length, a third image clarity evaluation value corresponding to each moving position of the third step length is obtained.

[0102] S63: When the relationship between the third image clarity evaluation value and the target image clarity evaluation value satisfies a first preset relationship, stop controlling the motor to drive the lens to move with the third step length, and determine the current position of the lens as the target focusing position.

[0103] The specific implementation method of S61 can be the same as S21 and S41, and the specific implementation method of S62 can be the same as S22 and S42, so they will not be repeated here. In S63, the first preset relationship can be that the third image clarity evaluation value currently obtained is greater than or equal to the target image clarity evaluation value. When the first preset relationship is met, it means that the focus is adjusted to the optimal position, the focusing is stopped, and the current position is the target focusing position. In some other embodiments, the first preset relationship can also be replaced by or further include: during the third stage focusing process, if the difference between the obtained third image clarity evaluation value and the target image clarity evaluation value is greater than or equal to the set evaluation value difference. When the first preset relationship is met, it means that the current focusing may have failed, and it is necessary to control the motor to stop the third stage focusing to avoid complete defocusing, thereby realizing defocusing protection during the focusing process.

[0104] As can be seen from the above, the third stage of focusing is a fine-tuning with reference to the focusing result of the second stage of focusing, and a focusing protection mechanism is incorporated into the fine-tuning process to avoid defocusing.

[0105] In addition, in some embodiments, in order to avoid complete defocusing, the focusing direction further includes: in the process of the motor driving the lens to move with the third step length, determining whether the relationship between the moving position corresponding to the third step length and the second preferred focusing position satisfies the second preset relationship, and if so, stopping the control of the motor to move with the third step length, and determining the current position of the lens as the target focusing position. The second preset relationship is that the difference between the current moving position corresponding to the third step length and the second preferred focusing position is greater than or equal to the set position difference. When the second preset relationship is met, it means that a failure may have occurred at present, and it is necessary to control the motor to stop the third stage focusing to avoid complete defocusing, thereby realizing defocusing protection during the focusing process.

[0106] In some embodiments, before S21: controlling the motor to drive the lens to move with the first step, the focusing method further includes: determining a focusing window according to a captured image of the lens.

[0107] The purpose of the focusing method provided in the present application is to focus the lens, that is, to determine the focusing position of the lens, where the lens can be an infrared lens, and the captured image can be an infrared image. In a specific implementation, in order to obtain targets with more edges within the field of view, so that the image clarity evaluation function can be better evaluated and the focusing accuracy can be improved, when focusing, a window selection can be performed on the current image captured by the lens, and an area of ​​interest can be selected, that is, a focusing window is determined.

[0108] It is understandable that in some embodiments, this step can select the entire current captured image as the focus window, which can be better applicable to all scenes. When the target is small or in a special position, the entire image evaluation value can still cover the target area. For the calculation of the entire image, the image block method can be used (for example, for an image with a resolution of 1280*1024, it is divided into 4*4 blocks), and the clarity evaluation value of each small block is calculated separately, and the sum can be used to obtain the clarity evaluation value of the entire image.

[0109] In addition, in some embodiments, since the lens will be directly facing the target position, the target of interest is the central position, that is, the central area method can be selected for window selection. When the central area is not the user's target, the user can manually select the focusing area. Of course, this step can also adopt an adaptive window focusing method, perform image block operation according to the current image, calculate the gradient of different blocks and sort them, and select the first few areas with larger gradient values ​​as focusing windows, so as to achieve adaptive window focusing, that is, this step may include: collecting the current image through the lens, and performing block operation on the current image; calculating the gradient of each block, and determining the block with the gradient greater than the preset value as the focusing window. The above preset value can be flexibly set based on the actual situation of the current image, and is not specifically limited here.

[0110] Specifically, in some embodiments, after determining the focus window, S22: in the process of the motor driving the lens to move with the first step length, obtaining a first image clarity evaluation value corresponding to each moving position of the first step length includes:

[0111] When the motor drives the lens to move with the first step length, the clarity of the focus window in the captured image at each moving position corresponding to the first step length is evaluated to obtain the average clarity value of each of the first images.

[0112] In some embodiments, in the process where the motor drives the lens to move with a second step length, obtaining a second image clarity evaluation value corresponding to each moving position of the second step length includes:

[0113] When the motor drives the lens to move in a second step length, the clarity of the focus window in the captured image corresponding to each moving position of the second step length is evaluated to obtain an average clarity value of each second image.

[0114] In some embodiments, in the process where the motor drives the lens to move with a third step length, obtaining a third image clarity evaluation value corresponding to each moving position of the third step length includes:

[0115] When the motor drives the lens to move with the first step length, the clarity of the focus window in the captured image at each moving position corresponding to the third step length is evaluated to obtain the average clarity value of each third image.

[0116] As can be seen from the above, in some embodiments, the focusing process provided in the present application mainly includes determining a focusing window, and after determining the focusing window, coarse focusing, fine focusing and micro focusing are performed in sequence.

[0117] See also Figure 6 , which is a schematic diagram of a method flow of a focusing method provided according to another embodiment of the present application. In some embodiments, the focusing method includes: S1, S2, S3 and S4.

[0118] S1: Setting the full focus window. Specifically, the full focus window can be set according to the above method for determining the focus window.

[0119] S2: Coarse focusing based on large step length movement and image clarity evaluation value change rate to find the global maximum value. Specifically, based on a large step length, it means that during the entire focusing process, the first step length is set to the maximum, that is, the first step length is greater than the second step length, and the second step length is greater than the third step length. During the coarse focusing process, the motor is moved with a large step length, and the coarse focusing is controlled to end when the change rate of the first image clarity evaluation value meets the preset change rate, which means that the global maximum value is found, and then the corresponding global maximum value is used as the focusing result of the coarse focusing. The coarse focusing corresponds to the first stage of focusing.

[0120] S3: Fine focusing of the definition evaluation value of the target image based on the improved hill climbing algorithm near the global maximum. The fine focusing corresponds to the second stage focusing, and fine focusing is performed near the global maximum, that is, starting from the focusing result of the coarse focusing, and fine focusing is performed at the preferred position of the first stage obtained by the coarse focusing.

[0121] S4: Fine-focusing based on the fine-focusing result and the focus protection mechanism. The fine-focusing corresponds to the third stage of focusing mentioned above. After the fine-focusing, the target image clarity evaluation value and the corresponding fine-focusing preferred focus position are obtained. The fine-focusing takes the fine-focusing preferred focus position as the starting point, performs fine-focusing near it, and implements focus protection in the process of fine-focusing according to the first preset relationship between the third image clarity evaluation value and the target image clarity evaluation value and the second preset relationship between the current moving position in the process of fine-focusing and the fine-focusing preferred focus position, so as to avoid the defocusing problem in the process of fine-focusing.

[0122] When the camera device where the lens is located is zoomed, when the zoom ratio exceeds a certain threshold, the lens may be out of focus and should be refocused. Because it has been focused before and is close to the focus point at this time, the method of searching nearby can be used to continuously change the focus direction to find the focus point.

[0123] Please refer to Figure 7 , which is a schematic flow chart of the focusing process when changing magnification in the focusing method provided by the present application. In this embodiment, after determining the target focusing position of the lens, the focusing method also includes S81, S82 and S83.

[0124] S81: Determine whether the current zoom ratio meets the preset zoom ratio. If so, take the target focus position as the starting point and control the motor to drive the lens to move in different directions in a fourth step and within a preset range away from the target focus position.

[0125] Specifically, whether the current zoom ratio satisfies the preset zoom ratio refers to determining whether the current zoom ratio is greater than or equal to the preset zoom ratio. If so, refocusing is required, and the fourth step length can be determined according to the difference between the current zoom ratio and the preset zoom ratio. The larger the difference, the longer the fourth step length can be set.

[0126] S82: When the motor drives the lens to move in a fourth step, a fourth image clarity evaluation value corresponding to each moving position of the fourth step is obtained, and the fourth image clarity evaluation value and the corresponding fourth preferred focusing position that meet a fourth preset condition are determined.

[0127] Specifically, the process in which the motor drives the lens to move with the fourth step length is the process of the fourth stage of focusing. The method of changing the focusing direction by 2 times the number of frames can be used to find the maximum focusing point. For example, first shoot 10 frames in one direction, and use the above-mentioned improved hill climbing algorithm to find out whether the peak value has been reached. If the peak value is not found, when it reaches 10 frames, control the motor to reverse; continue to search, if it is still not found, when it reaches 20 frames, control the motor to reverse again, and continue to judge whether the peak value has been reached. If it is still not found, continue to search for 40 frames and then reverse, and so on. Generally, the global maximum point can be found within 80 frames, that is, the maximum fourth image clarity evaluation value corresponding to the fourth focusing stage and the corresponding fourth stage preferred focusing position are found. The fourth preset condition is that the current fourth image clarity evaluation value obtained is the maximum value of all the fourth image clarity evaluation values ​​that have been obtained.

[0128] S83: Taking the fourth stage preferred focusing position as the starting point, returning to the first preferred focusing position as the starting point; taking the fourth preferred focusing position as the starting point, returning to the first preferred focusing position as the starting point, controlling the motor to drive the lens to move in a second step.

[0129] The motor is controlled to move with a second step length that is smaller than the first step length to perform a second stage focusing of the lens.

[0130] In addition, when the pan / tilt of the camera device where the lens is located rotates, it indicates that the scene has changed. When the pan / tilt stops rotating, refocusing is required. During focusing, if the pan / tilt rotates again, the focusing is stopped at this time, and the focus is refocused when the pan / tilt stops. In order to reduce the number of focusing times, when the pan / tilt rotates less, the automatic focusing is not started. Therefore, in some embodiments, the focusing method further includes: determining whether the rotation amplitude of the pan / tilt meets the preset amplitude, and if so, returning to S21: returning to the control motor to drive the lens to move with the first step length.

[0131] In some embodiments, controlling the motor to drive the lens to move for the first step further comprises:

[0132] SX11: Get the initial potential value of the potentiometer corresponding to the initial position where the motor drives the mirror to move with the first step length.

[0133] SX12: taking the one with a relatively larger difference between the maximum potential value and the minimum potential value of the potentiometer and the initial potential value as the target potential, and taking the motor movement direction corresponding to the potential value of the potentiometer approaching the target potential from the initial potential value as the target direction.

[0134] SX13: Control the motor to drive the lens to move toward the target direction with the first step length.

[0135] Specifically, in some embodiments, the preset step size may be the first step size, and S21 further includes SX11, SX12 and SX13.

[0136] Specifically, in some embodiments, the preset step size may be the second step size, and S41 further includes SX11, SX12 and SX13.

[0137] Specifically, in some embodiments, the preset step length may be the third step length, and S61 further includes SX11, SX12 and SX13.

[0138] Specifically, in some embodiments, the preset step size may be the fourth step size, and S81 further includes SX11, SX12 and SX13.

[0139] In some embodiments, before S24: selecting the first image clarity evaluation value that meets the first preset condition to determine the first preferred focusing position, the focusing method also includes: in the process of the motor driving the lens to move with the first step, obtaining the potential value of the potentiometer corresponding to each moving position of the first step.

[0140] Then S24: the selecting the first image clarity evaluation value that meets the first preset condition to determine the first preferred focusing position includes: selecting the first image clarity evaluation value that meets the first preset condition, determining a corresponding potential value according to the first image clarity evaluation value that meets the first preset condition, and determining the first preferred focusing position according to the corresponding potential value.

[0141] Similarly, in other embodiments of the present application, the corresponding focusing position can be determined according to other image clarity evaluation values ​​by first obtaining the potential value corresponding to the image clarity evaluation value, and then determining the corresponding focusing position according to the potential value corresponding to the image clarity evaluation value.

[0142] The focusing method provided in the present application, in some embodiments, combines the method of large-step motor rotation and the change rate threshold of the image clarity evaluation value to quickly find the global maximum while reducing the influence of local noise, achieving a faster focusing speed, and reducing the focusing time from 10s to within 3s. In addition, the large-lens focusing lens, combined with the scene switching under the pan / tilt and zoom conditions, automatically triggers automatic focusing to improve the user experience; in the final fine-focusing stage, a focusing protection mechanism is designed to improve the focusing stability in complex scenes.

[0143] Please refer to Figure 8 In some embodiments, the present application further provides a focusing device. The focusing device includes a moving module 101, an evaluation value acquisition module 102, a stop control module 103, a preferred focus position determination module 104, and a target focus position determination module 105. The moving control module 101 is used to control the motor to move with the first step length to perform the first stage focusing on the lens; the evaluation value acquisition module 102 is used to obtain the first image clarity evaluation value corresponding to each moving position of the first step length during the first stage focusing process; the stop control module 103 is used to stop the control motor from moving with the first step length when the change rate of the first image clarity evaluation value meets the preset change rate condition; the preferred focus position determination module 104 selects the first image clarity evaluation value that meets the first preset condition according to the first image clarity evaluation value to determine the first preferred focus position; the target focus position determination module 105 is used to determine the target focus position of the lens according to the first preferred focus position.

[0144] Please refer to Fig. 9 In some embodiments, the present application further provides a focusing device, which includes a memory 202 and a processor 201. When the processor 201 runs the computer program instructions stored in the memory 202, it executes the steps of the focusing method described in any embodiment of the present application.

[0145] In addition, the present application also provides a computer-readable storage medium, which stores computer program instructions; when the computer program instructions are executed by a processor, the steps of the focusing method described in the items provided in any embodiment of the present application are implemented.

[0146] The processor may be a CPU (Central Processing Unit), or an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the moving target detection device may be processors of the same type, such as one or more CPUs; or may be processors of different types, such as one or more CPUs and one or more ASICs.

[0147] The above-mentioned memory may include high-speed RAM (Random Access Memory), and may also include NVM (Non-Volatile Memory), such as at least one disk storage.

[0148] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A focusing method, characterized in that: include: Control the motor to drive the lens to move in the first step; In the process of the motor driving the lens to move with the first step length, obtaining a first image clarity evaluation value corresponding to each moving position of the first step length; When the change rate of the first image definition evaluation value meets a preset change rate condition, stopping the control motor to drive the lens to move at the first step; Selecting the first image clarity evaluation value that meets a first preset condition from among the acquired first image clarity evaluation values ​​to determine a first preferred focusing position; Taking the first preferred focus position as a starting point, controlling the motor to drive the lens to move with a second step length that is smaller than the first step length; When the motor drives the lens to move in the first direction with the second step length, obtaining a second image clarity evaluation value corresponding to each moving position of the second step length, and determining whether a change in the second image clarity evaluation value satisfies a peak determination condition; When the peak judgment condition is met, controlling the motor to drive the lens to move in a second direction with the second step length; the second direction is the opposite direction of the first direction; When the motor drives the lens to move in the second direction with the second step length, obtaining a second image clarity evaluation value corresponding to each moving position, and selecting the second image clarity evaluation value that meets the second preset condition as a candidate image clarity evaluation value; Determine whether the number of switching times of the movement direction of the lens driven by the motor meets the preset switching number; When the preset switching times are met, stop controlling the motor to drive the lens to move with the second step length, and select the candidate image clarity evaluation value that meets the third preset condition as the target image clarity evaluation value; The lens position corresponding to the target image clarity evaluation value is used as the second preferred focusing position; Determining a target focusing position of the lens according to the target image clarity evaluation value and the second preferred focusing position; The determining whether the change of the second image definition evaluation value satisfies a peak determination condition includes: It is determined whether the second image clarity evaluation value increases continuously for a first preset number of times and then decreases continuously for the first preset number of times, and whether the rate of change of the second image clarity evaluation value is greater than or equal to a second preset threshold during the continuous increase.

2. The focusing method according to claim 1, characterized in that: The focusing method further comprises: During the process in which the motor drives the lens to move in the first direction with the second step length, determining whether the motor is stuck at a stopper point, and if so, controlling the motor to drive the lens to move in the second direction with the second step length; and / or, During the process of the motor driving the lens to move toward the first direction with the second step length, it is determined whether the current moving position of the motor is at the position corresponding to the local extreme value of the second image clarity evaluation value; if so, the motor is controlled to drive the lens to move toward the second direction with the second step length.

3. The focusing method according to claim 1, characterized in that: The step of determining the target focusing position of the lens according to the target image clarity evaluation value and the second preferred focusing position includes: Taking the second preferred focus position as a starting point, controlling the motor to drive the lens to move in a third step length that is smaller than the second step length; In the process where the motor drives the lens to move with the third step length, obtaining a third image clarity evaluation value corresponding to each moving position of the third step length; When the relationship between the third image clarity evaluation value and the target image clarity evaluation value satisfies a first preset relationship, the control of the motor to drive the lens to move with the third step length is stopped, and the current position of the lens is determined as the target focusing position.

4. The focusing method according to claim 3, characterized in that: The focusing method further comprises: In the process of the motor driving the lens to move with the third step length, determining whether the relationship between the moving position corresponding to the third step length and the second preferred focusing position satisfies a second preset relationship; If so, stop controlling the motor to move with the third step length, and determine the current position of the lens as the target focus position.

5. The focusing method according to claim 1, characterized in that: After determining the target focus position of the lens, the method further includes: Determine whether the current zoom ratio meets the preset zoom ratio, and if so, take the target focus position as the starting point, control the motor to drive the lens to move in different directions in a fourth step length in sequence within a preset range that deviates from the target focus position; In the process of the motor driving the lens to move in a fourth step length, obtaining a fourth image clarity evaluation value corresponding to each moving position of the fourth step length, and determining the fourth image clarity evaluation value and the corresponding fourth preferred focusing position that meet a fourth preset condition; Taking the fourth preferred focus position as a starting point, returning to the first preferred focus position as a starting point, and controlling the motor to drive the lens to move with a second step length.

6. The focusing method according to any one of claims 1 to 5, characterized in that: The focusing method further comprises: Determine whether the rotation range of the pan / tilt head meets the preset range, and if so, return to the control motor to drive the lens to move at the first step length.

7. The focusing method according to any one of claims 1 to 5, characterized in that: The control motor drives the lens to move for the first step, including: Obtaining an initial potential value of the potentiometer corresponding to an initial position where the motor drives the mirror to move with the first step length; The one of the maximum potential value and the minimum potential value of the potentiometer with a relatively larger difference from the initial potential value is used as the target potential, and the motor movement direction corresponding to the potential value of the potentiometer approaching the target potential from the initial potential value is used as the target direction; The motor is controlled to drive the lens to move toward the target direction at a first step length.

8. The focusing method according to any one of claims 1 to 5, characterized in that: Before the control motor drives the lens to move at the first step, the focusing method further includes: Determine the focus window according to the collected image of the lens; In the process of the motor driving the lens to move with the first step length, obtaining a first image clarity evaluation value corresponding to each moving position of the first step length includes: When the motor drives the lens to move with the first step length, the clarity of the focus window in the captured image at each moving position corresponding to the first step length is evaluated to obtain a clarity evaluation value corresponding to each of the first images.

9. The focusing method according to any one of claims 1 to 5, characterized in that: When the change rate of the first image definition evaluation value meets a preset change rate condition, stopping the control motor to drive the lens to move at the first step length includes: Calculate the change rate of the first image definition evaluation value corresponding to the current moving position of the lens driven by the motor relative to the first image definition evaluation value corresponding to the preset moving position of the lens driven by the motor before the current moving position; It is determined whether the absolute value of the change rate is greater than or equal to a preset threshold value. If so, the control motor is stopped to drive the lens to move at the first step.

10. The focusing method according to any one of claims 1 to 5, characterized in that: Before selecting the first image clarity evaluation value that meets the first preset condition to determine the first preferred focusing position, the focusing method further includes: In the process of the motor driving the lens to move with the first step length, obtaining a potential value of the potentiometer corresponding to each moving position of the first step length; The selecting the first image clarity evaluation value that meets the first preset condition to determine the first preferred focusing position includes: Selecting the first image clarity evaluation value that meets the first preset condition; Determining a corresponding potential value according to the first image clarity evaluation value that meets the first preset condition; A first preferred focusing position is determined according to the corresponding potential value.

11. A focusing device, characterized in that: include: A movement control module, used for controlling the motor to drive the lens to move in the first step; An evaluation value acquisition module, used for acquiring a first image clarity evaluation value corresponding to each moving position of the first step in the process in which the motor drives the lens to move with the first step; A stop control module, configured to stop the control motor from driving the lens to move at the first step when the change rate of the first image definition evaluation value meets a preset change rate condition; a preferred focus position determining module, configured to select the first image clarity evaluation value that meets a first preset condition from among the acquired first image clarity evaluation values ​​to determine a first preferred focus position; The target focus position determination module is used to perform the following steps: Taking the first preferred focus position as a starting point, controlling the motor to drive the lens to move with a second step length that is smaller than the first step length; In the process of the motor driving the lens to move in the first direction with the second step length, a second image clarity evaluation value corresponding to each moving position of the second step length is obtained, and it is determined whether a change in the second image clarity evaluation value satisfies a peak judgment condition; wherein, the determination of whether a change in the second image clarity evaluation value satisfies a peak judgment condition comprises: determining whether the second image clarity evaluation value increases continuously for a first preset number of times and then decreases continuously for the first preset number of times, and whether a change rate of the second image clarity evaluation value is greater than or equal to a second preset threshold value during the continuous increase process; When the peak judgment condition is met, controlling the motor to drive the lens to move in a second direction with the second step length; the second direction is the opposite direction of the first direction; When the motor drives the lens to move in the second direction with the second step length, obtaining a second image clarity evaluation value corresponding to each moving position, and selecting the second image clarity evaluation value that meets the second preset condition as a candidate image clarity evaluation value; Determine whether the number of switching times of the movement direction of the lens driven by the motor meets the preset switching number; When the preset switching times are met, stop controlling the motor to drive the lens to move with the second step length, and select the candidate image clarity evaluation value that meets the third preset condition as the target image clarity evaluation value; The lens position corresponding to the target image clarity evaluation value is used as the second preferred focusing position; The target focusing position of the lens is determined according to the target image clarity evaluation value and the second preferred focusing position.

12. A focusing electronic device, characterized in that: including memory and processor; When the processor runs the computer program instructions stored in the memory, the processor performs the steps of the focusing method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that: The computer readable storage medium stores computer program instructions; When the computer program instructions are executed by a processor, the steps of the focusing method described in any one of claims 1 to 10 are implemented.

Citation Information

Patent Citations

  • Control method for automatic focusing and device thereof

    CN101790043A

  • Video auto-focusing system based on embedded media processor

    CN101840055A

  • Automatic focusing method and automatic focusing device

    CN103048766A

  • Method, device and system for adjusting camera back focus

    CN106375647A

  • Automatic focusing method and device

    CN106921830A