CN114460791A - Focusing method and device, electronic equipment and storage medium - Google Patents

Focusing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114460791A
CN114460791A CN202210217352.7A CN202210217352A CN114460791A CN 114460791 A CN114460791 A CN 114460791A CN 202210217352 A CN202210217352 A CN 202210217352A CN 114460791 A CN114460791 A CN 114460791A
Authority
CN
China
Prior art keywords
focusing
lens
evaluation value
step length
motor
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210217352.7A
Other languages
Chinese (zh)
Inventor
刘健康
吕贤敏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Infiray Technologies Co Ltd
Original Assignee
Infiray Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Infiray Technologies Co Ltd filed Critical Infiray Technologies Co Ltd
Priority to CN202210217352.7A priority Critical patent/CN114460791A/en
Publication of CN114460791A publication Critical patent/CN114460791A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G03PHOTOGRAPHY; CINEMATOGRAPHY; ANALOGOUS TECHNIQUES USING WAVES OTHER THAN OPTICAL WAVES; ELECTROGRAPHY; HOLOGRAPHY
    • G03BAPPARATUS OR ARRANGEMENTS FOR TAKING PHOTOGRAPHS OR FOR PROJECTING OR VIEWING THEM; APPARATUS OR ARRANGEMENTS EMPLOYING ANALOGOUS TECHNIQUES USING WAVES OTHER THAN OPTICAL WAVES; ACCESSORIES THEREFOR
    • G03B13/00Viewfinders; Focusing aids for cameras; Means for focusing for cameras; Autofocus systems for cameras
    • G03B13/32Means for focusing
    • G03B13/34Power focusing
    • G03B13/36Autofocus systems
    • GPHYSICS
    • G02OPTICS
    • G02BOPTICAL ELEMENTS, SYSTEMS OR APPARATUS
    • G02B7/00Mountings, adjusting means, or light-tight connections, for optical elements
    • G02B7/28Systems for automatic generation of focusing signals
    • G02B7/36Systems for automatic generation of focusing signals using image sharpness techniques, e.g. image processing techniques for generating autofocus signals
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/60Control of cameras or camera modules
    • H04N23/67Focus control based on electronic image sensor signals

Landscapes

  • Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Optics & Photonics (AREA)
  • Automatic Focus Adjustment (AREA)
  • Studio Devices (AREA)

Abstract

The application provides a focusing method, a focusing device, equipment and a storage medium, wherein the focusing method drives a lens to move in a first step length by controlling a motor, acquires a first image definition evaluation value corresponding to each moving position of the first step length in the process of driving the lens in the first step length by the motor, stops controlling the motor to drive the lens to move in the first step length when the change rate of the first image definition evaluation value meets a preset change rate condition, selects the first image definition evaluation value meeting a first preset condition according to the first image definition evaluation value to determine a first preferred focusing position, and finally determines a target focusing position of the lens according to the first preferred focusing position. Therefore, the focusing method provided by the application can quickly search the first image definition evaluation value meeting the preset condition and determine the corresponding optimal focusing position, and the focusing efficiency is effectively improved.

Description

Focusing method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of camera shooting and image pickup technologies, and in particular, to a focusing method and apparatus, an electronic device, and a storage medium.
Background
In an infrared camera product, the definition and the contrast of an image directly influence the effects of temperature measurement, monitoring and the like. After a product is molded, how to make the lens have the best imaging effect on a target, namely, the lens is in the best focusing position becomes a problem to be solved urgently. Conventional focusing methods include manual focusing and automatic focusing. The manual focusing has the problems of complex operation and unrealistic operation in certain scenes. For example, the infrared lens for forest fire prevention is large, the lens is often wrapped by a heavy metal shell, and manual focusing is inconvenient. Therefore, the automatic focusing technology is becoming an important research in industry and academia because it can automatically adjust the optimal focusing position without manual interference.
The automatic focusing method based on the image quality is characterized in that the peak value of the definition evaluation value of an imaging target is determined by combining a certain search algorithm depending on the definition evaluation values of the imaging target at different focal length positions, and then the optimal focusing position is determined according to the peak value of the definition evaluation. Therefore, a suitable search algorithm is critical for focus. The peak value of the sharpness evaluation value is determined to be a common method in automatic focusing based on a hill climbing search algorithm, however, in the process of focusing, the method needs to fill a full stroke to find a maximum peak value, so that long focusing time is needed, and poor user experience is brought.
Disclosure of Invention
In order to solve the existing technical problems, the application provides a fast focusing method, a fast focusing device, fast focusing equipment and a storage medium.
A method of focusing, comprising:
controlling a motor to drive a lens to move by a first step length;
acquiring a first image definition evaluation value of each moving position corresponding to the first step length in the process that the motor drives the lens to move in 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 in a first step length;
selecting the first image definition evaluation value which meets a first preset condition from the acquired first image definition evaluation values to determine a first preferred focusing position;
and determining a target focusing position of the lens according to the first preferred focusing position.
A focusing apparatus, comprising:
the movement control module is used for controlling the motor to drive the lens to move in a first step length;
the evaluation value acquisition module is used for acquiring a first image definition evaluation value of each moving position corresponding to the first step length in the process that the motor drives the lens to move in the first step length;
the stop control module is used for stopping the control motor to drive the lens to move in a first step length when the change rate of the first image definition evaluation value meets a preset change rate condition;
a preferred focusing position determining module, configured to select, from the acquired first image sharpness evaluation values, the first image sharpness evaluation value that meets a first preset condition to determine a first preferred focusing position;
and the target focusing position determining module is used for determining the target focusing position of the lens according to the first preferred focusing position.
A focusing electronic device comprising a memory and a processor;
the processor, when executing the computer program instructions stored in the memory, performs the steps of the focusing method.
A computer-readable storage medium, wherein the computer-readable storage medium has stored thereon computer program instructions;
the computer program instructions, when executed by a processor, implement the steps of the focusing method.
As can be seen from the above, in the focusing method, the focusing device, the focusing apparatus, and the storage medium provided in the present application, the lens is driven by controlling the motor to move in a first step length, and in a process of driving the lens in the first step length by the motor, a first image sharpness evaluation value corresponding to each moving position of the first step length is obtained, when a change rate of the first image sharpness evaluation value satisfies a preset change rate condition, the motor is stopped from being controlled to drive the lens to move in the first step length, and the first image sharpness evaluation value conforming to a first preset condition is selected according to the first image sharpness evaluation value to determine a first preferred focusing position, and finally, according to the first preferred focusing position, a target focusing position of the lens is determined. Therefore, the focusing method provided by the application can quickly search the first image definition evaluation value meeting the preset condition and determine the corresponding optimal focusing position, and the focusing efficiency is effectively improved.
Drawings
The drawings are only for purposes of illustrating embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a schematic flow chart of a focusing method according to some embodiments of the present application;
fig. 2 is a schematic flow chart illustrating a focusing process based on a first-stage focusing result in a focusing method according to some embodiments of the present disclosure;
fig. 3 is a schematic flow chart of a second stage focusing process based on an improved hill-climbing algorithm in a focusing method according to some embodiments of the present application;
fig. 4 is a schematic flow chart of an improved hill-climbing algorithm adopted in a second stage focusing process in a focusing method according to some embodiments of the present application;
fig. 5 is a schematic flow chart illustrating a focusing process based on a second-stage focusing result in a focusing method according to some embodiments of the present application;
FIG. 6 is a flowchart illustrating a focusing method according to another embodiment of the present application;
fig. 7 is a schematic flowchart of a focusing process during zooming in a focusing method according to some embodiments of the present disclosure;
FIG. 8 illustrates a focusing apparatus provided in accordance with some embodiments of the present application;
FIG. 9 illustrates a focusing apparatus according to some embodiments of the present application.
Detailed Description
The technical solution of the present application is further described in detail with reference to the drawings and specific embodiments of the specification.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein in the description of the present application is for the purpose of describing particular embodiments only and is not intended to be limiting of implementations of the present application. As used herein, the term "and/or" includes any and all combinations of one or more of the associated listed items.
In the following description, reference is made to the expression "some embodiments" which describe a subset of possible embodiments, but it is 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.
Based on the problem of long focusing time of the existing infrared focusing technology, the application provides a focusing method, a focusing device, focusing equipment and a storage medium. Fig. 1 to 7 are respectively schematic flowcharts of a focusing process in a focusing method according to the present application in different embodiments, and the focusing method according to the present application may be implemented in a focusing apparatus shown in fig. 8 and a focusing apparatus shown in fig. 9. The focusing method, apparatus, device and storage medium provided in the present application are described in detail with reference to fig. 1 to 9.
Referring to fig. 1, in some embodiments, the focus adjustment method provided by the present application includes S21, S22, S23, S24, and S40.
S21: the motor is controlled to drive the lens to move by a first step length.
S21 may be implemented by the movement control module 101 in the focusing apparatus shown in fig. 8, or by the memory 202 in the focusing apparatus shown in fig. 9 storing a corresponding movement control program, and then by the processor 201 in the focusing apparatus shown in fig. 9 executing the movement control program stored in the memory 202.
The camera device drives the lens to move according to a certain movement strategy through the motor in the process of automatically focusing the lens, and finally moves the lens to the optimal focusing position, so that the image definition evaluation value of the image collected through the lens is the largest, even if the image collected through the lens is the clearest. In the present application, the imaging device may be an infrared imaging device or a visible light imaging device. According to the focusing method provided by the application, the large lens of the camera device is focused. In addition, it should be noted that the motor movement that occurs subsequently refers to the movement of the lens driven by the motor.
When the focusing is started, the motor is controlled to move in a certain direction in a first step length, and the moving direction of the motor is changed according to a subsequently acquired image definition evaluation value in the moving process. In order to reduce the number of times of switching the moving direction of the motor in the focusing process, when the focusing is started, the motor can be controlled to move towards the far end direction in the first step length. The far end herein means an end of the motor at which the initial position of the motor at the time of the first-stage focusing is far from both end points of the motor movement position range.
S22: and acquiring a first image definition evaluation value of each moving position corresponding to the first step length in the process that the motor drives the lens to move in the first step length.
S22 may be implemented by the evaluation value acquisition module 102 in the focusing apparatus shown in fig. 8, or by the memory 202 in the focusing apparatus shown in fig. 9 storing a corresponding evaluation value acquisition program, and then by the processor 201 in the focusing apparatus shown in fig. 9 executing the evaluation value acquisition program stored in the memory 202.
After the motor is controlled to drive the lens to move by the first step length, the motor correspondingly obtains a moving position every time the motor moves by one step by the first step length, and a first image definition evaluation value of an acquired image when the lens is at the moving position is obtained. Specifically, the first image sharpness evaluation value of each captured image may be acquired based on an image sharpness evaluation function. The image sharpness evaluation function may be, but is not limited to, an energy gradient function, a Roberts gradient function, a Sobel gradient function, a variance function, and the like. The first image sharpness evaluation value of the captured image may be a sharpness evaluation value of the entire image of the captured image, or may be a sharpness evaluation value corresponding to a region of interest in the captured image.
S23: and 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 in a first step length.
S23 may be implemented by the stop control module 103 in the focusing apparatus shown in fig. 8, or by the memory 202 in the focusing apparatus shown in fig. 9 storing a corresponding stop control program, and by the processor 201 in the focusing apparatus shown in fig. 9 executing the stop control program stored in the memory 202.
In the process that the motor drives the lens to move in the first step length, the peak value of the first image definition evaluation value needs to be found in the moving range of the motor, namely, the global peak value is searched in the moving range of the motor. In the process of research, the inventor of the present application finds that when a global peak value (a peak value of image definition evaluation values corresponding to each moving position) is searched, the increasing rate of continuous frames before the peak value is high, the decreasing rate after the peak value is high, and the corresponding change rate before and after the local extreme value of each first image definition evaluation value is small, according to the characteristic, in the first stage focusing process, the inventor adopts the method that the end time of the first step length moving process of the motor-driven lens is controlled according to whether the change rate of the first image definition evaluation value meets the preset change rate condition, namely when the change rate of the first image definition evaluation value meets the preset change rate condition, namely the motor-driven lens is stopped to move in the first step length, so that the first preferred focusing position can be obtained after the motor is not controlled to move in the whole motor moving range, the focusing time can be effectively reduced.
Here, the change rate of the first image sharpness evaluation value includes an increase rate and a decrease rate, and when the increase rate is represented by a number greater than 0 and the decrease rate is represented by a number less than 0, the change rate is the magnitude of the increase rate or the magnitude of the decrease rate, that is, the change rate is the absolute value of the increase rate or the decrease rate. The preset change rate can be set according to the robust performance requirement and the precision performance requirement of focusing, and can be set according to experience, the larger the value of the preset change rate is set, the more accurate the focusing is possible, but the robustness is not good (namely, the adaptive scenes are few), and the smaller the value of the preset change rate is set, the better the robustness is, but the corresponding focusing accuracy is reduced. Therefore, different preset change rates can be set according to different scenes, such as indoor and outdoor.
In some embodiments, S23, when the change rate of the first image sharpness evaluation value satisfies a preset change rate condition, stopping the control motor from driving the lens to move by a first step length, further includes:
s231: and calculating the change rate of the first image definition evaluation value corresponding to the current moving position of the motor relative to the first image definition evaluation value corresponding to the preset moving position of the motor before the current moving position.
S232: and judging whether the absolute value of the change rate in the step S231 is greater than or equal to a preset threshold value, if so, stopping the control motor to drive the lens to move in a first step length.
Specifically, in some embodiments, if the preset number of moving positions before the current moving position is 2 moving positions before the current moving position, a calculation formula of a change rate of the first image sharpness evaluation value is as follows:
Figure BDA0003535535570000061
f3 is a first image sharpness evaluation value corresponding to the captured image of the current frame, F1 is a first image sharpness evaluation value corresponding to the captured image of the previous 2 frames of the current frame, and if the captured image of the previous 2 frames is the 1 st frame, the current frame is the 3 rd frame. Wherein abs in the above formula represents an absolute value, thres is a preset threshold, and the value may be set according to an actual scene, for example, may be set to 0.02. In addition, the specific number of the previous preset numbers may be set according to an actual value, and is set to be 2 in this embodiment, that is, in the acquired first image sharpness evaluation value, the calculation of the above formula needs to be performed once for each consecutive 3 frames of the first image sharpness evaluation value, so as to obtain the corresponding change rate.
S24: selecting the first image sharpness evaluation value which meets a first preset condition from the acquired first image sharpness evaluation values to determine a first preferred focusing position.
S24 may be implemented by the preferred focus position determining module 104 in the focusing apparatus shown in fig. 8, or by the memory 202 in the focusing apparatus shown in fig. 9 storing a corresponding preferred focus position determining program, and by the processor 201 in the focusing apparatus shown in fig. 9 executing the preferred focus position determining program stored in the memory 202.
After the motor stops moving by the first step length, one first image definition evaluation value meeting a first preset condition is selected from the first image definition evaluation values to serve as a value to be searched at the stage that the lens is moved by the motor by the first step length, and then the moving position corresponding to the value is used as a first preferred focusing position. In some embodiments, the first preset condition is that the selected first image sharpness evaluation value is that a maximum value of all the first image sharpness evaluation values or a size thereof satisfies a preset size. In some embodiments, after the motor stops moving by the first step length, all currently obtained first image sharpness evaluation values are compared, the largest first image sharpness evaluation value among them is selected as a global peak value that needs to be searched for in focusing at the first stage, and a moving position corresponding to the largest first image sharpness evaluation value is set as a first preferred focusing position.
S40: and determining a target focusing position of the lens according to the first preferred focusing position.
S40 may be implemented by the target focus position determination module 105 in the focusing apparatus shown in fig. 8, or by the memory 202 in the focusing apparatus shown in fig. 9 storing a corresponding target focus position determination program, and then by the processor 201 in the image focusing apparatus shown in fig. 9 when executing the target focus position determination program stored in the memory 202.
And the target focusing position is the position of the lens after the focusing on the lens is completely finished. And the lens is used for collecting images meeting the user requirements after being positioned at the target focusing position for the user to use. In some embodiments, one way to determine the target focus position of the lens based on the first preferred focus position is to: and taking the first optimal focusing position as a focusing starting point of the next stage, and then controlling the motor to move by adopting a moving step length which is smaller relative to the first step length to perform focusing of the next stage so as to determine the target focusing position. In other embodiments, the first preferred focusing position may be directly used as the target focusing position, and the focusing method only includes one stage of focusing.
As can be seen from the above, in the focusing method provided by the present application, a motor is controlled to drive a lens to move in a first step length, and in the process of driving the lens in the first step length by the motor, a first image sharpness evaluation value corresponding to each moving position of the first step length is obtained, when a change rate of the first image sharpness evaluation value satisfies a preset change rate condition, the motor is controlled to stop driving the lens to move in the first step length, the first image sharpness evaluation value conforming to a first preset condition is selected according to the first image sharpness evaluation value to determine a first preferred focusing sharpness position, and finally, a target focusing position of the lens is determined according to the first preferred focusing position. Therefore, the focusing method provided by the application can quickly search the first image definition evaluation value meeting the preset condition and determine the corresponding optimal focusing position, and the focusing efficiency is effectively improved.
Please refer to fig. 2, which is a schematic flow chart illustrating focusing according to a result of the first stage focusing in the focusing method according to some embodiments of the present application, that is, in some embodiments, S40 in fig. 1 further includes S41, S42, and S60.
S41: and controlling the motor to drive the lens to move in a second step length smaller than the first step length by taking the first optimal focusing position as a starting point.
In this embodiment, the process of focusing the lens further includes, in addition to the first stage focusing, a second stage focusing performed according to a result of the first stage focusing, where the second stage focusing is a process of controlling a motor to drive the lens to move by a second step length.
For focusing of the infrared camera, when an object with a large temperature difference does not exist in a field of view of the infrared camera, an infrared target does not have a remarkable edge or image noise is large, a plurality of local extreme points may exist in an image definition evaluation value obtained at each moving position of a motor, and if a first optimal focusing position obtained by simply adopting a first stage focusing step is taken as a final focusing position, the local extreme points may be trapped, so that a focusing result is inaccurate. Therefore, in the focusing method of the present application, at the time of the first-stage focusing, the first step size may be set to a larger step size (e.g., [0,1/2] of the entire lens focusing range), coarse focusing is completed, and then focusing in the next stage, that is, the second-stage focusing in S41, is performed based on the focusing result of the coarse focusing operation.
In the second stage focusing process, the moving step length of the motor is set to be smaller than that in the first stage focusing, namely the second step length is smaller than the first step length, and the second stage focusing is fine focusing relative to the first stage focusing of coarse focusing. The starting point of the second stage focusing is determined as the first preferred focusing position determined in the first stage focusing, and then the motor is controlled to move in a second step from the first preferred focusing position toward the first direction. As with the setting of the initial moving direction of the motor in the first stage focusing, the first direction is a direction in which the current moving position of the motor moves toward the relatively farther end in the second stage focusing.
S42: and in the process that the motor drives the lens to move in the second step length, acquiring a second image definition evaluation value of each moving position corresponding to the second step length, and determining a target image definition evaluation value and a corresponding second preferred focusing position of the lens according to the second image definition evaluation value.
In some embodiments, during the second-stage focusing, the second image sharpness evaluation value for each moving position corresponding to the second step is acquired in the same manner as the first image sharpness evaluation value, and will not be described in detail here. And in the process of the second-stage focusing, after the target image definition evaluation value is obtained according to the obtained second image definition evaluation value, finishing the second-stage focusing.
S60: and determining the target focusing position of the lens according to the target image sharpness evaluation value and the second preferred focusing position.
Also, in some embodiments, one implementation method for determining the target focusing position of the lens according to the second preferred focusing position is to use the second preferred focusing position as a focusing start point of a next stage, and then control the motor to move by a moving step smaller than the second step length to perform focusing of the next stage, so as to determine the target focusing position. In other embodiments, the second preferred focusing position may be directly used as the target focusing position.
In S42, a target image sharpness evaluation value of the lens and a corresponding second preferred focusing position may be determined from the second image sharpness evaluation value based on a hill climbing algorithm. However, the focusing time required for the hill climbing algorithm is relatively long, and therefore, in order to further reduce the focusing time, the present application provides an improved hill climbing algorithm to implement S42. Specifically, referring to fig. 3, in some embodiments, S42 implemented based on the improved hill-climbing algorithm includes S421, S422, S423, S424, S425, and S426.
S421: and acquiring a second image definition evaluation value of each moving position corresponding to the second step length in the process that the motor drives the lens to move towards the first direction by the second step length, and judging whether the change of the second image definition evaluation value meets a peak value judgment condition or not.
In the existing hill climbing algorithm, when a certain value continuously rises, the motor is considered to be climbing, and when the certain value continuously falls, the motor is considered to descend, and after the motor repeatedly traverses all strokes, the maximum value obtained in the reverse process is selected as a peak value. In this embodiment, in the process of implementing the second-stage focusing based on the improved hill-climbing algorithm, the peak value determination condition is reset, so that the target image sharpness evaluation value can be determined without moving the motor in the whole process (the movable range of the motor), thereby quickly completing the second-stage focusing and improving the focusing efficiency. Therefore, in some embodiments, the determining whether the change of the second image sharpness evaluation value satisfies the peak determination condition includes: and judging whether the second image definition evaluation value is continuously increased for a first preset time and then continuously decreased for the first preset time, and in the continuous increasing process, judging whether the change rate of the second image definition evaluation value is larger than or equal to a second preset threshold value. Therefore, in this embodiment, the peak determination condition is: and whether the second image definition evaluation value continuously increases for a first preset time and then continuously decreases for the first preset time, and whether the change rate of the second image definition evaluation value is greater than or equal to a second preset threshold value in the continuous increasing process. That is, when the second image sharpness evaluation value continuously increases multiple times, it is considered that the second image sharpness evaluation value climbs, and if the corresponding change rate is greater than or equal to the second preset threshold value in the process of continuously increasing, and continuously decreases after continuously increasing, it indicates that the current moving position of the motor has already passed the position corresponding to the peak value, and it is necessary to control the motor to move in the reverse direction, that is, S422 is executed. In other embodiments, the peak determination condition further includes that after the second image sharpness evaluation value continuously rises and the change rate satisfies a preset change rate, the second image sharpness evaluation value continuously falls, and the corresponding change rate also needs to satisfy the preset change rate when the second image sharpness evaluation value continuously falls.
The second preset threshold value is consistent with the setting mode of the preset change rate in the first-stage focusing process, and the setting mode is not described in detail here.
S422: when the peak value judgment condition is met, controlling the motor to drive the lens to move towards a second direction by the second step length; the second direction is opposite to the first direction.
S423: and in the process that the motor drives the lens to move towards the second direction by the second step length, acquiring a second image definition evaluation value corresponding to each moving position, and selecting the second image definition evaluation value meeting a second preset condition as a candidate image definition evaluation value.
In some embodiments, the second preset condition is: and the selected second image definition evaluation value is the maximum second image definition evaluation value obtained in the reverse process.
S424: and judging whether the moving direction switching times of the lens driven by the motor meet the preset switching times.
S425: and when the preset switching times are met, stopping controlling the motor to drive the lens to move in the second step length, and selecting the candidate image definition evaluation value meeting a third preset condition as a target image definition evaluation value.
In some embodiments, the third preset condition is: the selected candidate image sharpness evaluation value is the maximum value of all candidate image sharpness evaluation values.
S426: and taking the lens position corresponding to the target definition evaluation value as the second preferred focusing position.
In the process of the second stage focusing, the motor reversal is controlled according to the change of the second image definition evaluation value, and the motor reversal can be controlled according to whether the motor is clamped at a stopper point and/or whether the current position of the motor is in a position corresponding to a local extreme value.
Accordingly, in some embodiments, the focusing method further comprises: and judging whether the motor is clamped at a stopper point or not in the process that the motor drives the lens to move towards the first direction by the second step length, and if so, controlling the motor to drive the lens to move towards the second direction by the second step length. Specifically, in some embodiments, the determining whether the motor is clamped at the stopper point includes: and judging whether the potential values of the potentiometers at the positions corresponding to the continuously set number of second image definition evaluation values are at the limit point, if so, judging that the motor is currently clamped at the limit point, and controlling the motor to move reversely.
In some embodiments, the focusing method further comprises: and in the process that the motor drives the lens to move towards the first direction by the second step length, judging whether the current moving position of the motor is at the position corresponding to the local extreme value of the second image definition evaluation value, and if so, controlling the motor to drive the lens to move towards the second direction by 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 sharpness evaluation value includes: and judging that the second image definition evaluation value corresponding to the collected images with the continuously set frame number does not decrease for the continuously preset times, and if the current moving position of the motor is in the position corresponding to the local extreme value of the second image definition evaluation value, controlling the motor to move reversely.
Referring to fig. 4, a schematic flow chart of implementing the second stage focusing process based on the improved hill-climbing algorithm according to the present application is shown. In this embodiment, after the motor moves by the second step length each time, the potential value corresponding to the potentiometer is obtained, and the moving position corresponding to the second step length is represented by the potential value, that is, each second image definition evaluation value corresponds to one potential value. Before executing the improved hill climbing algorithm, defining a second image definition evaluation value as f (i), and defining a corresponding potential value as p (i), wherein i represents a collected image of an i-th lens acquired in a second-stage focusing process, the maximum value of the motor reversal times is set as CountMax (corresponding to the preset switching times), the maximum value obtained in each reversal, namely a candidate image definition evaluation value, is defined as fmax (k) (k ═ CountMax), k is the number of times of k-th reversal movement, and the corresponding potential value is pmax (k) at this moment. The improved hill climbing algorithm is executed according to the method of fig. 4, and the process is as follows:
initializing parameters, determining the number of times CountMax of setting the maximum direction and determining the first direction, setting the initial value of the number k of reverse movement as 0, and taking the largest one of the second image definition evaluation values corresponding to the first 3 frames of the acquired image of the current frame of the lens as the currently obtained largest second image definition evaluation value Fmax, wherein the corresponding potential value is Pmax. After executing Sa, Sb is executed.
And Sb, controlling the motor to move towards the first direction in a second step length so as to perform second-stage focusing on the lens. And the potential value corresponding to the initial position of the second-stage focusing is the potential value corresponding to the first optimal focusing position. Sc is performed after execution of Sb.
And (C) Sc: in the process that the motor moves towards the first direction in the second step length, i is increased once every step of movement, and a second image definition evaluation value f (i) and a corresponding potential value p (i) corresponding to each step are calculated. Sd is performed after Sc is performed.
Sd: judging whether f (i) corresponding to the collected images of the next continuous i frames (generally less than or equal to 3 frames, namely i is less than or equal to 3) is greater than or equal to Fmax, comparing whether the growth rate corresponding to the collected images of the continuous i frames meets the preset change rate, if so, executing Se, and otherwise, executing Sf.
Se: assigning the currently obtained f (i) to Fmax and the currently corresponding p (i) to Pmax, and then executing Sg.
Sf: and judging whether f (i) corresponding to the next continuous i frames of acquired images is less than or equal to Fmax.
Sg: and judging whether f (i) corresponding to the next i frames of acquired images is greater than or equal to Fmax, comparing whether the growth rate corresponding to the i frames of acquired images meets the preset change rate, if so, judging that the motor exceeds the peak value and needs to be controlled to reverse, executing Sh, and otherwise, returning to Sb.
Sh: the motor is controlled to move in the reverse direction (i.e. to a second direction opposite to the first direction) and the value of k is added by 1 and the currently obtained Fmax is assigned to Fmax (k) and the currently corresponding Pmax is assigned to Pmax (k) and then Sj is executed.
Sj: and judging whether the current k is greater than or equal to the set maximum direction times CountMax, if so, executing sl, and if not, returning to Sb.
And Sl, sequencing all the fmax (k), acquiring the maximum value of the fmax (k), determining the maximum value as a target image definition evaluation value DFmax, and taking the position corresponding to the potential value Dpmax corresponding to the target definition evaluation value Dfmax as a second preferred focusing position.
In addition, with continued reference to fig. 4, in the present embodiment, the process of implementing the second-stage focusing based on the improved hill-climbing algorithm further includes Sm, which is executed after Sa.
And Sm, judging whether the motor is in a position of a limiter point for continuous multiframes or continuous 3-frame descending of the second image definition evaluation value does not occur for continuous multiframes, if so, executing Sh, and otherwise, returning to Sb.
By arranging Sm, the phenomenon that a motor is stuck at a point or falls into a local minimum value in the moving process can be avoided, and accurate focusing can be rapidly realized.
It should be noted that, in this embodiment, after the result of Sd determination is yes, Se is executed to further determine whether the corresponding second image sharpness evaluation value continuously increases while the motor continues to move toward the first direction, and if yes, the motor is controlled to reverse when the result of Sf determination is yes, that is, the motor actually has already crossed the position corresponding to the peak value, so as to reduce the probability of erroneous determination. In other embodiments, Se may not be needed, that is, it is determined whether the second image sharpness evaluation value continuously rises first, and whether a corresponding change rate during the continuous rising is greater than or equal to a set threshold change rate, if so, it is determined whether the second image sharpness evaluation value continuously falls after the continuous rising is completed, and if so, the motor is controlled 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 the coarse focusing.
In some embodiments, in order to further improve the focusing accuracy, after the second stage focusing is performed, it is also necessary to continue the next focusing with a smaller motor moving step size according to the result of the second stage focusing. Thus, as shown in fig. 5, in some embodiments, S60 further includes S61, S62, and S63.
S61: and controlling the motor to drive the lens to move in a third step length smaller than the second step length by taking the second optimal focusing position as a starting point.
S62: and acquiring a third image definition evaluation value of each moving position corresponding to the third step length in the process that the motor drives the lens to move in the third step length.
S63: and when the relation between the third image definition evaluation value and the target image definition evaluation value meets a first preset relation, stopping controlling the motor to drive the lens to move by the third step length, and determining the current position of the lens as a target focusing position.
The specific implementation of S61 may be the same as S21, S41, and the specific implementation of S62 may be the same as S22, S42, and therefore, the description thereof will not be repeated here. In S63, the first preset relationship may be that the currently obtained third image sharpness evaluation value is greater than or equal to the target image sharpness evaluation value, and when the first preset relationship is satisfied, focusing to an optimum position is described, focusing is stopped, and the current position is taken as the target focusing position. In other embodiments, the first preset relationship may alternatively or further include: in the third stage focusing process, if the difference value between the obtained third image definition evaluation value and the target image definition evaluation value is larger than or equal to the set evaluation value difference value, the third image definition evaluation value is compared with the target image definition evaluation value, and the target image definition evaluation value is compared with the set evaluation value difference value. When the first preset relation is met, it is indicated that the current focusing may fail, and the motor needs to be controlled to stop the third stage focusing to avoid complete defocusing, so that defocusing protection in the focusing process is realized.
Therefore, the third stage focusing is fine focusing performed by taking the focusing result of the second stage focusing as reference, and a focusing protection mechanism is integrated in the fine focusing process to avoid defocusing.
Furthermore, in some embodiments, to avoid complete defocus, the focusing direction further comprises: and in the process that the motor drives the lens to move in the third step length, judging whether the relation between the moving position corresponding to the third step length and the second optimal focusing position meets a second preset relation, if so, stopping controlling the motor to move in the third step length, and determining the current position of the lens as a 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 relation is met, it is indicated that failure may occur at present, and the motor needs to be controlled to stop focusing at the third stage so as to avoid complete defocusing, thereby realizing defocusing protection in the focusing process.
In some embodiments, at S21: before controlling the motor to drive the lens to move in the first step length, the focusing method further comprises: and determining a focusing window according to the acquired image of the lens.
The focusing method provided by the application aims to focus a lens, namely, the focusing position of the lens is determined, the lens can be an infrared lens, and a collected image can be an infrared image. In specific implementation, in order to acquire a target with more edges in a field range, an image definition evaluation function can be evaluated better, focusing accuracy is improved, a current image acquired by a lens can be subjected to window selection during focusing, an area of interest is selected, and a focusing window is determined.
It is understood that in some embodiments, this step may select the whole currently captured image as a focusing window, which may be better applicable to all scenes, and when the target is small or in a particular position, the whole image evaluation value may still cover the target area. For the calculation of the whole image, the sharpness evaluation value of each small block may be calculated by an image blocking method (for example, dividing the image with a resolution of 1280 × 1024 into 4 × 4 blocks), and the sharpness evaluation values of the whole image may be obtained by summing up.
In addition, in some embodiments, since the lens is directly oriented to the target position, the target of interest is the central position, i.e., the central region method can be selected for window selection. When the central area is not the user's target, the user may manually select the focus area. Of course, this step may also adopt a method of adaptive window focusing, perform image blocking operation according to the current image, calculate gradients for different blocks and sort them, select the first several regions with larger gradient values as focusing windows, thereby implementing adaptive window focusing, that is, this step may include: acquiring the current image through the lens, and carrying out blocking operation on the current image; and calculating the gradient of each block, and determining the block with the gradient larger than a preset value as the focusing window. The preset value may be flexibly set based on the actual situation of the current image, and is not specifically limited herein.
Specifically, in some embodiments, after determining the focus window, S22: the method for obtaining the first image definition evaluation value of each moving position corresponding to a first step length in the process that the motor drives the lens to move in the first step length comprises the following steps:
and in the process that the motor drives the lens to move in a first step length, evaluating the definition of the focusing window in the collected image of each moving position corresponding to the first step length to obtain the average value of the definition of each corresponding first image.
In some embodiments, in the process that the motor drives the lens to move by a second step length, acquiring a second image sharpness evaluation value of each moving position corresponding to the second step length includes:
and in the process that the lens is driven by the motor to move in a second step length, evaluating the definition of the focusing window in the collected image of each moving position corresponding to the second step length to obtain the average definition of each second image.
In some embodiments, in the process that the motor drives the lens to move by a third step length, acquiring a third image sharpness evaluation value of each moving position corresponding to the third step length includes:
and in the process that the motor drives the lens to move in the first step length, evaluating the definition of the focusing window in the collected image of each moving position corresponding to the third step length to obtain the average value of the definition of each corresponding third image.
As can be seen from the above, in some embodiments, the focusing process provided by the present application mainly includes determining a focusing window, and performing coarse focusing, fine focusing, and fine focusing in sequence after determining the focusing window.
Please refer to fig. 6, which is a flowchart illustrating a method of a focus adjustment method according to some embodiments of the present application. In some embodiments, the focusing method comprises: s1, S2, S3, and S4.
And S1, setting a full focusing window. Specifically, the full focus window may be set according to the method for determining the focus window.
S2: and searching coarse focusing of the global maximum value based on the large-step movement and the image definition evaluation value change rate. Specifically, based on a large step length, the maximum first step length is set in the whole focusing process, that is, the first step length is larger than a second step length, and the second step length is larger than a third step length. In the coarse focusing process, the motor is moved in large step length, the coarse focusing is controlled to be finished when the change rate based on the first image definition evaluation value meets the preset change rate, namely, 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 focusing.
S3: and searching fine focusing of the target image definition evaluation value near the global maximum value based on an improved hill-climbing algorithm. And the fine focusing corresponds to the second stage focusing, and the fine focusing is carried out near the global maximum value, namely the fine focusing is carried out at the position where the coarse focusing is obtained and the first stage is preferred by taking the focusing result of the coarse focusing as a starting point.
S4: and taking the fine focusing result as a reference and based on a focusing protection mechanism for fine focusing. The fine focusing corresponds to the third stage focusing. After the fine focusing, a target image sharpness evaluation value and a corresponding fine focusing preferred focusing position are obtained. And in the fine focusing process, focusing protection is realized according to a first preset relation between a third image definition evaluation value and a target image definition evaluation value and a second preset relation between a current moving position in the fine focusing process and the fine focusing preferred focusing position, so that the out-of-focus problem in the fine focusing process is avoided.
When the zoom magnification exceeds a certain threshold value, the lens may be in virtual focus and should be focused again. Because the focus is already focused before, and the focus is closer to the focusing point, a method of searching nearby can be adopted, the focusing direction is continuously changed, and the focusing point is searched.
Referring to fig. 7, which is a schematic flow chart illustrating a focusing process during zooming in the focusing method provided by the present application, in the present embodiment, after determining the target focusing position of the lens, the focusing method further includes S81, S82, and S83.
S81: and judging whether the current variable-magnification ratio meets a preset variable-magnification ratio, if so, controlling the motor to drive the lens to sequentially move along different directions in a fourth step length and in a preset range deviating from the target focusing position by taking the target focusing position as a starting point.
Specifically, whether the current variable-magnification ratio meets a preset variable-magnification ratio refers to whether the current variable-magnification ratio is larger than or equal to a set variable-magnification ratio. If so, refocusing is needed, the fourth step length can be determined according to the difference between the current variable magnification ratio and the set variable magnification ratio, and the larger the difference is, the longer the fourth step length can be set relatively.
S82: and in the process that the motor drives the lens to move in a fourth step length, acquiring a fourth image definition evaluation value of each moving position corresponding to the fourth step length, and determining a fourth image definition evaluation value meeting a fourth preset condition and a corresponding fourth preferred focusing position.
Specifically, the process in which the motor drives the lens to move by the fourth step length is the process of focusing by the fourth step length, and the maximum focusing point can be found by adopting a method of changing the focusing direction by 2 times the frame number. If the peak value is not found, when the peak value reaches 10 frames, the motor is controlled to be reversed; and continuing searching, if the image is not searched yet, controlling the motor to reverse when the image reaches 20 frames, continuing to judge whether the peak value is reached, if the image is not found yet, continuing to search 40 frames and then reversing, and so on, generally finding a global maximum point in 80 frames, namely finding a maximum fourth image definition evaluation value corresponding to the fourth focusing stage and a corresponding fourth stage optimal focusing position. The fourth preset condition is that the currently obtained fourth image definition evaluation value is the maximum value of all the obtained fourth image definition evaluation values.
S83: and taking the preferred focusing position of the fourth stage as a starting point, returning to the preferred focusing position of the first stage as a starting point, and controlling the motor to drive the lens to move in a second step length.
And controlling the motor to move by a second step size smaller than the first step size so as to perform second-stage focusing on the lens.
In addition, when the pan/tilt head of the imaging device on which the lens is located rotates, it is described that the scene changes, and when the pan/tilt head stops rotating, it is necessary to refocus. When focusing, if the holder rotates again, the focusing is stopped, and when the holder stops, the focusing is restarted. In order to reduce the focusing times, when the holder rotates less, automatic focusing is not started. Therefore, in some embodiments, the focusing method further comprises: judging whether the rotation amplitude of the holder meets the preset amplitude or not, if so, returning to S21: and returning to the control motor to drive the lens to move by a first step length.
In some embodiments, the controlling the motor to move the lens by the first step length further comprises:
SX 11: and acquiring an initial potential value of the potentiometer corresponding to the initial position of the motor driven mirror moving by the first step length.
SX 12: and taking one of the maximum potential value and the minimum potential value of the potentiometer with a relatively larger difference value with the initial potential value as a target potential, and taking the corresponding motor moving direction of the potentiometer when the initial potential value approaches to the target potential as a target direction.
SX 13: and controlling the motor to drive the lens to move towards the target direction by a first step length.
Specifically, in some embodiments, the preset step size may be the first step size, and S21 further includes SX11, SX12, and SX 13.
Specifically, in some embodiments, the preset step size may be the second step size, and S41 further includes SX11, SX12, and SX 13.
Specifically, in some embodiments, the preset step size may be the third step size, and S61 further includes SX11, SX12, and SX 13.
Specifically, in some embodiments, the preset step size may be the fourth step size, and S81 further includes SX11, SX12, and SX 13.
In some embodiments, at S24: before the first image sharpness evaluation value meeting the first preset condition is selected to determine the first preferred focusing position, the focusing method further comprises the following steps: and acquiring the potential value of the potentiometer at each moving position corresponding to the first step length in the process that the motor drives the lens to move by the first step length.
S24, the selecting the first image sharpness evaluation value meeting the first preset condition to determine a first preferred focusing position includes: selecting the first image definition evaluation value meeting a first preset condition, determining a corresponding potential value according to the first image definition evaluation value meeting the first preset condition, and determining a first preferred focusing position according to the corresponding potential value.
Also, in other embodiments according to the present application, the corresponding focusing position is determined based on other image sharpness evaluation values, and a potential value corresponding to the image sharpness evaluation value may be acquired first, and then the corresponding focusing position may be determined based on the potential value corresponding to the image sharpness evaluation value.
According to the focusing method provided by the application, in some embodiments, a method of changing a rate threshold of large-step motor rotation and image definition evaluation value is combined, the global maximum value is found quickly, meanwhile, the influence of local noise is reduced, the faster focusing speed is realized, and the focusing time can be reduced from 10s to within 3 s. In addition, the large-lens focusing lens automatically triggers automatic focusing by combining the pan-tilt and scene switching under the zooming condition, so that the user experience is improved; in the final fine focusing stage, a focusing protection mechanism is designed, and the focusing stability in a complex scene is improved.
Referring to fig. 8, in some embodiments, the present application further provides a focusing apparatus. The focusing apparatus includes a movement module 101, an evaluation value acquisition module 102, a stop control module 103, a preferred focusing position determination module 104, and a target focusing position determination module 105. The movement control module 101 is used for controlling the motor to move in a first step length so as to perform first-stage focusing on the lens; an evaluation value obtaining module 102, configured to obtain, in the first-stage focusing process, a first image sharpness evaluation value of each moving position corresponding to the first step; the stop control module 103 is configured to stop the control motor from moving by a first step length when the change rate of the first image sharpness evaluation value meets a preset change rate condition; a preferred focusing position determining module 104, configured to select the first image sharpness evaluation value meeting a first preset condition according to the first image sharpness evaluation value, and determine a first preferred focusing position; and an object focusing position determining module 105, configured to determine an object focusing position of the lens according to the first preferred focusing position.
Referring to fig. 9, in some embodiments, the present application further provides a focusing apparatus, which includes a memory 202 and a processor 201. The processor 201, when executing the computer program instructions stored in the memory 202, performs the steps according to the focusing method described in any of the embodiments of the present application.
In addition, the present application also provides a computer readable storage medium storing computer program instructions; the computer program instructions, when executed by a processor, implement the steps of a focusing method according to any of the embodiments provided herein.
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 embodiments of the present invention. The detection device of the moving object comprises one or more processors, which can be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
The Memory may include a high-speed RAM (Random Access Memory) and may further include a Non-Volatile Memory (NVM), such as at least one disk Memory.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (16)

1. A method of focusing, comprising:
controlling a motor to drive a lens to move by a first step length;
acquiring a first image definition evaluation value of each moving position corresponding to the first step length in the process that the motor drives the lens to move in 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 in a first step length;
selecting the first image definition evaluation value which meets a first preset condition from the acquired first image definition evaluation values to determine a first preferred focusing position;
and determining a target focusing position of the lens according to the first preferred focusing position.
2. The method of claim 1, wherein determining the target focus position of the lens from the first preferred focus position comprises:
controlling the motor to drive the lens to move in a second step length smaller than the first step length by taking the first optimal focusing position as a starting point;
in the process that the motor drives the lens to move in the second step length, acquiring a second image definition evaluation value of each moving position corresponding to the second step length, and determining a target image definition evaluation value and a corresponding second preferred focusing position of the lens according to the second image definition evaluation value;
and determining the target focusing position of the lens according to the target image sharpness evaluation value and the second preferred focusing position.
3. The focusing method according to claim 2, wherein the acquiring a second image sharpness evaluation value for each shift position of the second step during the shift in the second step, and determining a target image sharpness evaluation value and a corresponding second preferred focusing position of the lens based on the second image sharpness evaluation value, comprises:
in the process that the motor drives the lens to move towards the first direction at the second step length, acquiring a second image definition evaluation value of each moving position corresponding to the second step length, and judging whether the change of the second image definition evaluation value meets a peak value judgment condition or not;
when the peak value judgment condition is met, controlling the motor to drive the lens to move towards a second direction by the second step length; the second direction is opposite to the first direction;
in the process that the motor drives the lens to move towards the second direction in the second step length, acquiring a second image definition evaluation value corresponding to each moving position, and selecting the second image definition evaluation value meeting a second preset condition as a candidate image definition evaluation value;
judging whether the moving direction switching times of the lens driven by the motor meet preset switching times or not;
when the preset switching times are met, stopping controlling the motor to drive the lens to move in the second step length, and selecting the candidate image definition evaluation value meeting a third preset condition as a target image definition evaluation value;
and taking the lens position corresponding to the target definition evaluation value as the second preferred focusing position.
4. The focusing method according to claim 3, wherein the determining whether the change in the second image sharpness evaluation value satisfies a peak determination condition includes:
and judging whether the second image definition evaluation value is continuously increased for a first preset time and then continuously decreased for the first preset time, and in the continuous increasing process, judging whether the change rate of the second image definition evaluation value is larger than or equal to a second preset threshold value.
5. The focusing method of claim 3, further comprising:
judging whether the motor is clamped at a position of a limiter or not in the process that the motor drives the lens to move towards the first direction at the second step length, if so, controlling the motor to drive the lens to move towards the second direction at the second step length; and/or the presence of a gas in the gas,
and in the process that the motor drives the lens to move towards the first direction by the second step length, judging whether the current moving position of the motor is at the position corresponding to the local extreme value of the second image definition evaluation value, and if so, controlling the motor to drive the lens to move towards the second direction by the second step length.
6. The focusing method according to claim 2, wherein the determining the target focusing position of the lens from the target image sharpness evaluation value and the second preferred focusing position includes:
controlling the motor to drive the lens to move in a third step length smaller than the second step length by taking the second optimal focusing position as a starting point;
acquiring a third image definition evaluation value of each moving position corresponding to a third step length in the process that the motor drives the lens to move in the third step length;
and when the relationship between the third image definition evaluation value and the target image definition evaluation value meets a first preset relationship, stopping controlling the motor to drive the lens to move in the third step length, and determining the current position of the lens as a target focusing position.
7. The focusing method of claim 6, further comprising:
in the process that the motor drives the lens to move in the third step length, whether the relation between the moving position corresponding to the third step length and the second optimal focusing position meets a second preset relation or not is judged;
and if so, stopping controlling the motor to move in the third step length, and determining the current position of the lens as a target focusing position.
8. The focusing method according to claim 2, further comprising, after determining the target focusing position of the lens:
judging whether the current variable-magnification ratio meets a preset variable-magnification ratio, if so, controlling the motor to drive the lens to sequentially move along different directions in a fourth step length and in a preset range deviating from the target focusing position by taking the target focusing position as a starting point;
in the process that the motor drives the lens to move in a fourth step length, acquiring a fourth image definition evaluation value of each moving position corresponding to the fourth step length, and determining a fourth image definition evaluation value meeting a fourth preset condition and a corresponding fourth preferred focusing position;
and returning to the starting point of the first preferred focusing position by taking the fourth preferred focusing position as a starting point, and controlling the motor to drive the lens to move in a second step length.
9. The focusing method according to any one of claims 1 to 8, further comprising:
and judging whether the rotation amplitude of the holder meets the preset amplitude or not, if so, returning to the control motor to drive the lens to move in a first step length.
10. The focusing method according to any one of claims 1 to 8, wherein controlling the motor to move the lens by a first step comprises:
acquiring a potentiometer initial potential value corresponding to an initial position where the motor drives the mirror to move in a first step length;
taking one of the maximum potential value and the minimum potential value of the potentiometer with a relatively larger difference value with the initial potential value as a target potential, and taking the corresponding motor moving direction of the potentiometer when the initial potential value approaches to the target potential as a target direction;
and controlling the motor to drive the lens to move towards the target direction by a first step length.
11. The focusing method according to any one of claims 1 to 8, wherein before the controlling the motor to move the lens by the first step length, the focusing method further comprises:
determining a focusing window according to an acquired image of a lens;
the method for obtaining the first image definition evaluation value of each moving position corresponding to a first step length in the process that the motor drives the lens to move in the first step length comprises the following steps:
and in the process that the motor drives the lens to move in a first step length, evaluating the definition of the focusing window in the collected image of each moving position corresponding to the first step length to obtain the average value of the definition of each corresponding first image.
12. The focusing method according to any one of claims 1 to 8, wherein stopping the control motor from moving the lens by a first step length when the change rate of the first image sharpness evaluation value satisfies a preset change rate condition comprises:
calculating the change rate of the first image definition evaluation value corresponding to the current moving position of the motor-driven lens relative to the first image definition evaluation value corresponding to the preset moving position of the motor-driven lens before the current moving position;
and judging whether the absolute value of the change rate is greater than or equal to a preset threshold value, if so, stopping the control motor to drive the lens to move in a first step length.
13. The focusing method according to any one of claims 1 to 8, wherein before the selection of the first image sharpness evaluation value that meets a first preset condition determines a first preferred focusing position, the focusing method further comprises:
in the process that the motor drives the lens to move in a first step length, acquiring the potential value of the potentiometer corresponding to each moving position of the first step length;
the selecting the first image sharpness evaluation value meeting a first preset condition to determine a first preferred focusing position comprises:
selecting the first image definition evaluation value which meets a first preset condition;
determining a corresponding potential value according to the first image definition evaluation value which accords with a first preset condition;
and determining a first preferred focusing position according to the corresponding potential value.
14. A focusing apparatus, comprising:
the movement control module is used for controlling the motor to drive the lens to move in a first step length;
the evaluation value acquisition module is used for acquiring a first image definition evaluation value of each moving position corresponding to the first step length in the process that the motor drives the lens to move in the first step length;
the stop control module is used for stopping the control motor to drive the lens to move in a first step length when the change rate of the first image definition evaluation value meets a preset change rate condition;
a preferred focusing position determining module, configured to select, from the acquired first image sharpness evaluation values, the first image sharpness evaluation value that meets a first preset condition to determine a first preferred focusing position;
and the target focusing position determining module is used for determining the target focusing position of the lens according to the first preferred focusing position.
15. A focusing electronic device comprising a memory and a processor;
the processor, when executing computer program instructions stored in the memory, performs the steps of the focusing method of any of claims 1 to 13.
16. A computer-readable storage medium having stored thereon computer program instructions;
the computer program instructions, when executed by a processor, implement the steps of the focusing method of any of claims 1 to 13.
CN202210217352.7A 2022-03-07 2022-03-07 Focusing method and device, electronic equipment and storage medium Pending CN114460791A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210217352.7A CN114460791A (en) 2022-03-07 2022-03-07 Focusing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210217352.7A CN114460791A (en) 2022-03-07 2022-03-07 Focusing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114460791A true CN114460791A (en) 2022-05-10

Family

ID=81418061

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210217352.7A Pending CN114460791A (en) 2022-03-07 2022-03-07 Focusing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114460791A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114979472A (en) * 2022-05-13 2022-08-30 杭州联吉技术有限公司 Automatic focusing method, device, equipment and readable storage medium
CN115661153A (en) * 2022-12-27 2023-01-31 四川中科友成科技有限公司 Automatic lens focusing control method and device suitable for photoelectric pod
CN116233604A (en) * 2023-05-08 2023-06-06 江苏慕藤光精密光学仪器有限公司 Image focusing method and device, electronic equipment and storage medium

Citations (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070212049A1 (en) * 2006-03-07 2007-09-13 Samsung Electro-Mechanics Co., Ltd. Auto-focusing method and auto-focusing apparatus using the same
CN101790043A (en) * 2009-01-22 2010-07-28 华为终端有限公司 Control method for automatic focusing and device thereof
CN101840055A (en) * 2010-05-28 2010-09-22 浙江工业大学 Video auto-focusing system based on embedded media processor
CN103048766A (en) * 2013-01-24 2013-04-17 华为技术有限公司 Automatic focusing method and automatic focusing device
KR20160131460A (en) * 2015-05-07 2016-11-16 한화테크윈 주식회사 Method to control Auto Focus
CN106921830A (en) * 2015-12-28 2017-07-04 浙江大华技术股份有限公司 A kind of method and device of automatic focusing
US20180284574A1 (en) * 2015-12-23 2018-10-04 Beijing Qihoo Techology Company Limited Method and device for camera rapid automatic focusing
CN111432125A (en) * 2020-03-31 2020-07-17 合肥英睿系统技术有限公司 Focusing method and device, electronic equipment and storage medium
CN111711759A (en) * 2020-06-29 2020-09-25 重庆紫光华山智安科技有限公司 Focusing method, device, storage medium and electronic equipment
CN111757008A (en) * 2020-07-10 2020-10-09 普联技术有限公司 Focusing method, device and computer readable storage medium
CN112203014A (en) * 2020-09-28 2021-01-08 重庆紫光华山智安科技有限公司 Flatness adjusting method of image sensor and related device
CN112601015A (en) * 2020-12-10 2021-04-02 烟台艾睿光电科技有限公司 Automatic focusing method and automatic focusing system
CN113747042A (en) * 2020-05-29 2021-12-03 杭州海康威视数字技术股份有限公司 Stepping step length control method and method for determining stepping step length of stepping motor
CN113938599A (en) * 2020-07-14 2022-01-14 浙江宇视科技有限公司 Electric lens focusing method and device, electronic equipment and storage medium
CN114061921A (en) * 2021-12-02 2022-02-18 重庆紫光华山智安科技有限公司 Return trip difference detection method and device, monitoring equipment and readable storage medium

Patent Citations (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070212049A1 (en) * 2006-03-07 2007-09-13 Samsung Electro-Mechanics Co., Ltd. Auto-focusing method and auto-focusing apparatus using the same
CN101790043A (en) * 2009-01-22 2010-07-28 华为终端有限公司 Control method for automatic focusing and device thereof
CN101840055A (en) * 2010-05-28 2010-09-22 浙江工业大学 Video auto-focusing system based on embedded media processor
CN103048766A (en) * 2013-01-24 2013-04-17 华为技术有限公司 Automatic focusing method and automatic focusing device
KR20160131460A (en) * 2015-05-07 2016-11-16 한화테크윈 주식회사 Method to control Auto Focus
US20180284574A1 (en) * 2015-12-23 2018-10-04 Beijing Qihoo Techology Company Limited Method and device for camera rapid automatic focusing
CN109660726A (en) * 2015-12-23 2019-04-19 北京奇虎科技有限公司 Camera fast automatic focusing method and device
CN106921830A (en) * 2015-12-28 2017-07-04 浙江大华技术股份有限公司 A kind of method and device of automatic focusing
CN111432125A (en) * 2020-03-31 2020-07-17 合肥英睿系统技术有限公司 Focusing method and device, electronic equipment and storage medium
CN113747042A (en) * 2020-05-29 2021-12-03 杭州海康威视数字技术股份有限公司 Stepping step length control method and method for determining stepping step length of stepping motor
CN111711759A (en) * 2020-06-29 2020-09-25 重庆紫光华山智安科技有限公司 Focusing method, device, storage medium and electronic equipment
CN111757008A (en) * 2020-07-10 2020-10-09 普联技术有限公司 Focusing method, device and computer readable storage medium
CN113938599A (en) * 2020-07-14 2022-01-14 浙江宇视科技有限公司 Electric lens focusing method and device, electronic equipment and storage medium
CN112203014A (en) * 2020-09-28 2021-01-08 重庆紫光华山智安科技有限公司 Flatness adjusting method of image sensor and related device
CN112601015A (en) * 2020-12-10 2021-04-02 烟台艾睿光电科技有限公司 Automatic focusing method and automatic focusing system
CN114061921A (en) * 2021-12-02 2022-02-18 重庆紫光华山智安科技有限公司 Return trip difference detection method and device, monitoring equipment and readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
张劲峰等: "基于函数变化率的变阈值变步长自动聚焦方法", 计算机工程, vol. 42, no. 07, pages 217 - 219 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114979472A (en) * 2022-05-13 2022-08-30 杭州联吉技术有限公司 Automatic focusing method, device, equipment and readable storage medium
CN114979472B (en) * 2022-05-13 2023-11-24 杭州联吉技术有限公司 Automatic focusing method, device, equipment and readable storage medium
CN115661153A (en) * 2022-12-27 2023-01-31 四川中科友成科技有限公司 Automatic lens focusing control method and device suitable for photoelectric pod
CN116233604A (en) * 2023-05-08 2023-06-06 江苏慕藤光精密光学仪器有限公司 Image focusing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN114460791A (en) Focusing method and device, electronic equipment and storage medium
CN111432125B (en) Focusing method and device, electronic equipment and storage medium
US8970770B2 (en) Continuous autofocus based on face detection and tracking
CN107395993B (en) Full-automatic focusing method and system
CN107888819B (en) Automatic focusing method and device
US11956536B2 (en) Methods and apparatus for defocus reduction using laser autofocus
CN110324536B (en) Image change automatic sensing focusing method for microscope camera
JP5446076B2 (en) Digital camera
CN108769533B (en) Automatic focusing method
CN104038691A (en) Auto Focus method and auto focus apparatus
CN112601006B (en) Tracking focusing method and device based on pan-tilt camera
TWI471677B (en) Auto focus method and auto focus apparatus
EP3879172B1 (en) Machine vision based intelligent focusing method for a moving head lamp
KR101784787B1 (en) Imaging device and method for automatic focus in an imaging device as well as a corresponding computer program
CN106101565B (en) Electric lens focusing method and device
CN105430277B (en) Autofocus control method and device
CN108254995B (en) Automatic focusing method and system for large zoom lens
CN113109936A (en) Microscope automatic focusing method and device based on image definition evaluation
CN112203012A (en) Image definition calculation method, automatic focusing method and system
RU2389050C1 (en) Automatic focusing method
US9357124B2 (en) Focusing control device and controlling method of the same
US10165174B2 (en) Control apparatus, image capturing apparatus, control method, and non-transitory computer-readable storage medium
CN111491105A (en) Focusing method of mobile terminal, mobile terminal and computer storage medium
US10367991B2 (en) Focus adjustment device and control method of focus adjustment device
KR100841290B1 (en) Method for controlling focus of cctv camera

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination