Automatic focusing method, lens module and imaging device
By adopting the automatic focus method of coarse adjustment first and then fine adjustment in the imaging device, the target imaging position of the lens is quickly determined using contrast calculation, and the problems of focus accuracy, speed and resource consumption in the prior art are solved, and efficient and flexible automatic focus effect is achieved.
Patent Information
- Application Number
- CN202510169626.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-14
- Publication Date
- 2025-04-11
AI Technical Summary
The existing automatic focus technology has shortcomings in accuracy, speed and resource consumption, especially when lighting conditions change, the application scenarios of PDAF are limited, while the focus process of CDAF is longer.
By controlling the lens to move stepwise from the initial scanning position in the preset direction at the first step length, the first contrast of the imaging area is calculated, and the duplicate scanning position is set according to the judgment result, and then the second contrast is calculated from the reverse direction of the duplicate scanning position at the second step length. If the preset conditions are met, the target imaging position is determined.
It realizes efficient automatic focus, reduces the time-consuming focus, is suitable for all kinds of scenes, and avoids the need to traverse all lens positions, improving focus efficiency and accuracy.
Smart Images

Figure CN119805701A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of lens imaging, and in particular to an automatic focusing method, a lens module and an imaging device. Background Art
[0002] With the development of imaging technology, the lens modules in current imaging devices (such as cameras) usually have an auto focus function (Auto Focus, AF), so that when the shooting button is pressed, the lens module can automatically focus the position of the lens according to the distance of the target to be photographed, so that the target can be clearly imaged.
[0003] At present, the most commonly used autofocus methods include PDAF (Phase Detection Auto Focus) and CDAF (Contrast Detection Auto Focus). The focusing principle of PDAF is that different areas of the photosensitive element (such as the image sensor) regularly reserve some left and right pixel pairs for phase detection, where the phase difference between the left phase pixel and the right phase pixel can measure the image clarity of the corresponding area, that is, when the phase difference between the two pixels in the same pixel pair is 0, it means that the image of the area is clear, and when the phase difference is not 0, it means that the image is blurred. The focusing principle of CDAF is to measure the image clarity by calculating the contrast or contrast of the image focus frame area. The greater the contrast, the clearer the image.
[0004] In actual application, when using the PDAF method, it is necessary to first read the information of the left and right pixel pairs in the focus area and calculate the phase difference, and then use the pre-set calibration information to obtain the motor control value required for the current phase difference to be 0, and finally control the motor movement according to the calculated motor control value to push the lens to the specified position, thereby achieving clear imaging. When using the CDAF method, first control the motor to push the lens in one direction, and use the algorithm to calculate the corresponding image contrast. In this process, the image contrast will go from small to large and then to small. Then, use the algorithm to control the motor to push the lens to a position with a larger image contrast, and move in the opposite direction to calculate the image contrast again, so as to find the position of the lens when the image contrast is the largest in the lens movement range, thereby achieving clear imaging.
[0005] Although PDAF has the advantages of high focusing accuracy and fast speed, it has a large amount of calculation and needs to store the calibration information of the motor in advance, so it consumes more hardware resources. In addition, PDAF has strict requirements on lighting conditions. If the light is weak or strong, it will affect the clarity of the image, which limits its application scenarios. CDAF needs to traverse all lens positions to calculate the contrast of each position to confirm the clearest point, and it will go through two stages of coarse scanning and fine scanning. The focusing process takes a long time. Summary of the invention
[0006] The purpose of the present invention is to provide an automatic focusing method, a lens module and an imaging device to solve the problem of how to achieve efficient automatic focusing.
[0007] In order to solve the above technical problems, the present invention provides an automatic focusing method, comprising: Control the lens to move step by step from the initial scanning position along the preset direction with a first step length, and calculate the first contrast of the imaging area corresponding to each lens position; Determining whether each calculated first contrast satisfies a first preset condition; According to the judgment result, the re-scanning position is set; Controlling the lens to move step by step from the rescanning position in the opposite direction of the preset direction with a second step length, and calculating a second contrast of the imaging area corresponding to each lens position; Determining whether each calculated second contrast satisfies a second preset condition; If the calculated second contrast satisfies the second preset condition, the lens position corresponding to the second contrast is used as the target imaging position.
[0008] Optionally, in the automatic focusing method, the method of controlling the lens to move step by step from the initial scanning position along a preset direction with a first step length, and calculating the first contrast of the imaging area corresponding to each lens position includes: Set the initial scan position; Dividing the imaging area into a number of sub-areas; Control the lens to move step by step along a preset direction from an initial scanning position with a first step length, and obtain the imaging contrast of each sub-area at the current lens position; According to the imaging contrast of all sub-areas at the current lens position, a first contrast corresponding to the current lens position is calculated.
[0009] Optionally, in the automatic focusing method, the method of calculating the first contrast corresponding to the current lens position according to the imaging contrast of all sub-areas at the current lens position includes: Setting a contrast weight for each sub-region, wherein the contrast weight of a sub-region located at the center of the imaging region is higher than the contrast weight of a sub-region located at the edge of the imaging region; The imaging contrasts of all sub-regions at the current lens position are weightedly calculated using the contrast weights to obtain a first contrast corresponding to the current lens position.
[0010] Optionally, in the automatic focusing method, the method of determining whether each calculated first contrast satisfies a first preset condition includes: If a first preset multiple of the first contrast corresponding to the current lens position is greater than the first contrast corresponding to the previous lens position and greater than the first contrast corresponding to the next lens position, it is determined that the calculated first contrast meets the first preset condition.
[0011] Optionally, in the automatic focusing method, the method of setting the rescanning position according to the judgment result includes: The next lens position after the current lens position that meets the first preset condition is used as the re-scanning position.
[0012] Optionally, in the automatic focusing method, the method of controlling the lens to move step by step from the rescanning position in a direction opposite to the preset direction with a second step length, and calculating the second contrast of the imaging area corresponding to each lens position includes: Dividing the imaging area into a number of sub-areas; Control the lens to move gradually from the rescanning position in the opposite direction of the preset direction with a second step length, and obtain the imaging contrast of each sub-area at the current lens position; According to the imaging contrast of all sub-areas at the current lens position, a second contrast corresponding to the current lens position is calculated.
[0013] Optionally, in the automatic focusing method, the method of calculating the second contrast corresponding to the current lens position according to the imaging contrast of all sub-areas at the current lens position includes: Setting a contrast weight for each sub-region, wherein the contrast weight of a sub-region located at the center of the imaging region is higher than the contrast weight of a sub-region located at the edge of the imaging region; The imaging contrasts of all sub-regions at the current lens position are weightedly calculated using the contrast weights to obtain a second contrast corresponding to the current lens position.
[0014] Optionally, in the automatic focusing method, the method of determining whether each calculated second contrast satisfies the second preset condition includes: If the second preset multiple of the second contrast corresponding to the current lens position is greater than the second contrast corresponding to the previous lens position and greater than the second contrast corresponding to the next lens position, it is determined that the calculated second contrast meets the second preset condition.
[0015] Optionally, in the automatic focusing method, the automatic focusing method further includes: If the second contrast does not meet the second preset condition after the calculation times of the second contrast reaches the preset times threshold, the target imaging position is calculated using the current lens position and the previous lens position and the next lens position that meet the first preset condition.
[0016] Optionally, in the automatic focusing method, the method of calculating the target imaging position using the current lens position and the previous lens position and the next lens position that meet the first preset condition includes: Calculate the contrast difference L between the current lens position and the previous lens position and the contrast difference R between the current lens position and the next lens position; Constructing a peak-finding function, wherein the peak-finding function is a convex function; Substitute the contrast differences L and R, the current lens position and the first step length into the peak search function to obtain the target imaging position, which is expressed as:
[0017] Among them, i represents the current camera position, s represents the step size, Indicates the target imaging position.
[0018] Optionally, in the automatic focusing method, the first step length is greater than the second step length.
[0019] In order to solve the above technical problems, the present invention further provides a lens module for implementing the automatic focusing method as described in any one of the above items, wherein the lens module comprises: A lens, used to receive light to form an optical path; A photosensitive element, comprising an imaging area, wherein the imaging area is used to receive the light transmitted by the lens to form an image; A motor, used for driving the lens to move so as to change the distance between the lens and the photosensitive element; The controller is used to calculate the contrast and make a judgment according to the image formed in the imaging area, and control the motor to drive the lens to move.
[0020] In order to solve the above technical problem, the present invention further provides an imaging device, which includes the lens module as described above.
[0021] The automatic focusing method, lens module and imaging device provided by the present invention include: controlling the lens to move step by step along a preset direction from the initial scanning position with a first step length, and calculating the first contrast corresponding to the imaging area at each lens position; judging whether each calculated first contrast satisfies the first preset condition; setting the re-scanning position according to the judgment result; controlling the lens to move step by step along the reverse direction of the preset direction from the re-scanning position with a second step length, and calculating the second contrast corresponding to the imaging area at each lens position; judging whether each calculated second contrast satisfies the second preset condition; if the calculated second contrast satisfies the second preset condition, the lens position corresponding to the second contrast is used as the target imaging position. By calculating the first contrast and judging whether the first preset condition is met, the range of the imaging focal length can be quickly determined, and further calculating the second contrast and judging whether the second preset condition is met can quickly determine the focal length, that is, the target imaging position of the lens. Since the focusing process does not need to traverse all lens positions, and the step length can be flexibly adjusted according to the shooting scene, it can not only effectively reduce the time consumption of focusing, but also be applicable to various scenes, solving the problem of how to achieve efficient automatic focusing. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A flowchart of the automatic focusing method provided in this embodiment; Figure 2 A schematic diagram of contrast weight setting provided in this embodiment; Figure 3 A schematic diagram of a fitted peak-finding function curve provided in this embodiment; Figure 4 A schematic diagram of the structure of the lens module provided in this embodiment; The descriptions of the reference numerals are as follows: 101-lens; 102-photosensitive element; 103-motor; 104-controller. DETAILED DESCRIPTION
[0023] The following is a further detailed description of the automatic focusing method, lens module, and imaging device proposed in the present invention in conjunction with the accompanying drawings and specific embodiments. It should be noted that the accompanying drawings are all in a very simplified form and use non-precise proportions, which are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention. In addition, the structure shown in the accompanying drawings is often a part of the actual structure. In particular, the emphasis of each accompanying drawing is different, and sometimes different proportions are used.
[0024] It should be noted that the terms "first", "second", etc. in the specification, claims and drawings of the present invention are used to distinguish similar objects in order to describe the embodiments of the present invention, rather than to describe a specific order or sequence. It should be understood that the structures used in this way can be interchanged under appropriate circumstances. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0025] This embodiment provides an automatic focusing method, such as Figure 1 As shown, including: S1, controlling the lens to move step by step from the initial scanning position along a preset direction with a first step length, and calculating a first contrast of the imaging area corresponding to each lens position; S2, determining whether each calculated first contrast satisfies a first preset condition; S3, setting the rescanning position according to the judgment result; S4, controlling the lens to move gradually from the rescanning position in a direction opposite to the preset direction with a second step length, and calculating a second contrast of the imaging area corresponding to each lens position; S5, determining whether each calculated second contrast satisfies a second preset condition; S6: If the calculated second contrast satisfies a second preset condition, the lens position corresponding to the second contrast is used as the target imaging position.
[0026] The automatic focusing method, lens module, and imaging device provided in this embodiment can quickly determine the range of the imaging focal length by calculating the first contrast and judging whether the first preset condition is met, and further calculate the second contrast and judge whether the second preset condition is met to quickly determine the focal length, that is, the target imaging position of the lens. Since the focusing process does not need to traverse all lens positions and the step length can be flexibly adjusted according to the shooting scene, it can not only effectively reduce the time spent on focusing, but also be applicable to various scenes, solving the problem of how to achieve efficient automatic focusing.
[0027] Specifically, in this embodiment, in step S1, the method of controlling the lens to move step by step from the initial scanning position along the preset direction with a first step length, and calculating the first contrast of the imaging area corresponding to each lens position includes: S11, setting the initial scanning position.
[0028] Considering that in the actual shooting process, there is usually a certain distance between the lens and the photosensitive element, and the initial position of the lens is usually at the focal position when shooting a distant environment (parallel light) to ensure fast focusing. Therefore, a preliminary scanning position can be set so that the autofocus process is performed directly from the preliminary scanning position, without having to be performed from the end closest to or farthest from the photosensitive element, thereby saving focusing time.
[0029] In actual application, the initial scan position needs to be determined based on the movement direction and focal position of the lens when focusing. For example, if the lens starts to move away from the photosensitive element, the initial scan position can be set on the side where the focal point is close to the photosensitive element, thereby saving focusing time while scanning the focal position to ensure that the automatic focusing process can find the target imaging position of the lens.
[0030] S12, dividing the imaging area into a plurality of sub-areas.
[0031] Considering that in the actual shooting process, the focus shooting is usually carried out on a certain area of the imaging area of the photosensitive element to ensure that the area where the key shooting elements are located can be clearly imaged. Therefore, the imaging area of the photosensitive element can be divided into several sub-areas, so that when calculating the contrast later, the target imaging position of the lens can be adjusted according to the shooting requirements to ensure that the key elements in the final image are clear.
[0032] In actual application, the division of sub-regions can be comprehensively determined based on factors such as the size of the captured image and the range of clear imaging, including the size and position of the sub-regions. Of course, in order to facilitate subsequent calculations, the size of the sub-regions can be set to a uniform size, and the sub-regions are adjacent to each other.
[0033] S13, controlling the lens to move step by step from the initial scanning position along a preset direction with a first step length, and obtaining the imaging contrast of each sub-area at the current lens position.
[0034] The calculation method of the imaging contrast of each sub-region is well known to those skilled in the art, and will not be described in detail in this application. In this application, the calculation method of the contrast in the existing CDAF method can be selected for calculation.
[0035] S14, calculating a first contrast corresponding to the current lens position according to the imaging contrasts of all sub-areas at the current lens position.
[0036] In this embodiment, first, a contrast weight is set for each sub-region, wherein the contrast weight of the sub-region located at the center of the imaging region is higher than the contrast weight of the sub-region located at the edge of the imaging region.
[0037] For example, the imaging area is divided into 5×5 sub-areas. Figure 2 As shown, when the center of the imaging area is taken as the focus area, the contrast weight of the sub-area located in the center can be set to 3 (highest), the contrast weights of the 8 sub-areas adjacent to the center sub-area can be set to 2, and the contrast weights of the 16 sub-areas at the outermost edge can be set to 1 (lowest), thereby ensuring that the central area is considered more when calculating the target imaging position of the lens, so that the central area has higher clarity in the final imaging.
[0038] Of course, in other embodiments, different contrast weights may be assigned to sub-areas at different positions according to the focus area, and the contrast weight value of each focus area may be flexibly set.
[0039] Then, the contrast weight is used to perform weighted calculation on the imaging contrasts of all sub-regions at the current lens position to obtain a first contrast corresponding to the current lens position.
[0040] It should be noted that, in the same focusing process, when performing the first contrast calculation for each lens position, the contrast weights of the sub-regions should be consistent to ensure the consistency of the first contrast calculation results.
[0041] Further, in this embodiment, in step S2, the method of determining whether each calculated first contrast satisfies the first preset condition includes: If a first preset multiple of the first contrast corresponding to the current lens position is greater than the first contrast corresponding to the previous lens position and greater than the first contrast corresponding to the next lens position, it is determined that the calculated first contrast meets the first preset condition. The value of the first preset multiple is greater than 0 and less than 1.
[0042] In a specific embodiment, assuming that the current lens position is i, the first step length is 1, the first preset multiple is 0.75, the first contrast of the current lens position is recorded as d1(i), the first contrast of the previous lens position is recorded as d1(i-1), and the first contrast of the next lens position is recorded as d1(i+1). Then, if 0.75d1(i)>d1(i-1) and 0.75d1(i)>d1(i+1), it is judged that d1(i) meets the first preset condition.
[0043] Of course, in other embodiments, the values of the first preset magnification and the first step length can be determined comprehensively according to the focusing range of the lens and the requirements of imaging clarity, and the present application does not impose any limitation on this.
[0044] At this point, it can be determined that the target imaging position of the lens is between i-1 and i+1. So far, the coarse adjustment process of focusing is completed.
[0045] Furthermore, in this embodiment, in step S3, a rescanning position is set according to the judgment result.
[0046] Specifically, since the target imaging position of the lens is determined to be between i-1 and i+1 when the lens is coarsely adjusted along the preset direction, in order to reduce the amount of calculation as much as possible and speed up the focusing speed, in this embodiment, the subsequent lens position of the current lens position that meets the first preset condition is used as the re-scanning position, that is, the i+1 position is used as the re-scanning position.
[0047] Furthermore, in this embodiment, in step S4, the lens is controlled to move step by step from the rescanning position in a direction opposite to the preset direction with a second step length, and a second contrast of the imaging area corresponding to each lens position is calculated.
[0048] Similar to step S1, step S4 specifically includes: S41, dividing the imaging area into a plurality of sub-areas.
[0049] In practical applications, in order to simplify the calculation process and ensure the consistency of calculation, the sub-region division method in step S12 can be used, that is, the sub-regions divided in step S12 are still used for subsequent calculations.
[0050] S42, controlling the lens to move gradually from the rescanning position in a direction opposite to the preset direction with a second step length, and obtaining the imaging contrast of each sub-area at the current lens position.
[0051] Since the target imaging position of the lens needs to be precisely confirmed in this step, the second step length should be smaller than the first step length. In addition, the imaging contrast calculation method used in this step can be consistent with the imaging contrast calculation method in step S13, thereby effectively reducing the hardware resources consumed by the storage algorithm.
[0052] In a specific embodiment, when the first step size is set to 1, the second step size can be set to 0.25.
[0053] S43, calculating a second contrast corresponding to the current lens position according to the imaging contrasts of all sub-areas at the current lens position.
[0054] In this embodiment, first, a contrast weight is set for each sub-region, wherein the contrast weight of the sub-region located at the center of the imaging region is higher than the contrast weight of the sub-region located at the edge of the imaging region. In practical applications, the contrast weight set in this step may be the same as the contrast weight set in step S14, thereby ensuring the consistency of the two contrast calculation results.
[0055] Then, the contrast weight is used to perform weighted calculation on the imaging contrasts of all sub-regions at the current lens position to obtain a second contrast corresponding to the current lens position.
[0056] Further, in this embodiment, in step S5, the method of determining whether each calculated second contrast satisfies the second preset condition includes: If the second preset multiple of the second contrast corresponding to the current lens position is greater than the second contrast corresponding to the previous lens position and greater than the second contrast corresponding to the next lens position, it is determined that the calculated second contrast meets the second preset condition. The value of the second preset multiple is greater than 0 and less than 1.
[0057] In a specific embodiment, assuming that the current lens position is i, the second step length is 0.25, the second preset multiple is 0.75, the second contrast of the current lens position is recorded as d2(i), the second contrast of the previous lens position is recorded as d2(i+0.25), and the second contrast of the next lens position is recorded as d2(i-0.25), then, if 0.75d2(i)>d2(i-0.25), and 0.75d2(i)>d2(i+0.25), it is judged that d2(i) meets the second preset condition. It should be noted that, since the lens starts from the rescanning position and proceeds in the opposite direction of the preset direction when calculating the second contrast, the previous position of the current lens position is i+0.25, and the next position is i-0.25.
[0058] Of course, in other embodiments, the values of the second preset magnification and the second step length can be determined comprehensively according to the focusing range of the lens and the requirements of imaging clarity, and the present application does not impose any limitation on this.
[0059] At this point, it can be determined that the target imaging position of the lens is between i-0.25 and i+0.25. Since the second step length is small, the imaging clarity of the current lens position determined can usually meet the requirements, and the fine adjustment process of focusing is completed.
[0060] S6: If the calculated second contrast satisfies a second preset condition, the lens position corresponding to the second contrast is used as the target imaging position.
[0061] Since the calculated contrast is positively correlated with the image clarity, that is, when the image clarity is optimal, the contrast is the highest, and the corresponding lens position at this time is the imaging focal length position. Therefore, through the above steps, the lens position (imaging focal length position) when the contrast is the largest (best clarity) can be obtained, and this lens position is used as the target imaging position to obtain the best shooting effect.
[0062] At this point, the entire autofocus process is completed. By first coarse adjustment and then fine adjustment, the lens position corresponding to the point with the clearest imaging can be found in a "hill climbing" manner. Unlike the existing CDAF method, in this embodiment, the coarse adjustment process does not need to traverse all positions of the lens, thereby saving a lot of time and improving focusing efficiency; moreover, in this embodiment, when comparing contrast, the current lens position is scaled using the first preset multiple and the second preset multiple, so that not only the range of the lens target imaging position can be determined more quickly, but also the size of the determined range can be reduced as much as possible, thereby improving the focusing efficiency while improving the focusing accuracy.
[0063] In addition, in order to further improve the efficiency of focusing, in this embodiment, the automatic focusing method further includes: S7: If the second contrast does not satisfy the second preset condition after the calculation times of the second contrast reaches the preset times threshold, the target imaging position is calculated using the current lens position and the previous lens position and the next lens position that satisfy the first preset condition.
[0064] For example, when the second contrast is calculated five times (the lens position is gradually changed five times during the fine-tuning process), the point with the largest contrast is still not found. Then, in order to save focusing time, no gradual contrast comparison is performed. Instead, the target imaging position is calculated using the current lens position that meets the first preset condition and its previous lens position and next lens position.
[0065] Specifically, considering that the lens position and imaging clarity (contrast) conform to the characteristics of a convex function (quadratic function), in this embodiment, a convex function can be fitted using the current lens position that meets the first preset condition and its previous lens position and next lens position, so as to obtain the target imaging position by taking the maximum value using the convex function.
[0066] In practical applications, such as Figure 3 As shown, let the quadratic function is a peak-finding function, where (h, k) represents the maximum value of the quadratic function, h represents the target imaging position of the lens, and k represents the maximum value of the first contrast.
[0067] In the coarse adjustment process, the current lens position satisfying the first preset condition is i, and the first contrast at this time is ; The previous position of the current lens position is is, and the first contrast at this time is ; The next position after the current lens position is i+s, and the first contrast at this time is , where s is the first step length.
[0068] Since (is, )、(i, ) and (i+s, ) all satisfy the peak-finding function Therefore, these three points can be brought into the peak-finding function to obtain the coefficients to get the value of h.
[0069] In addition, since (is, )、(i, ) and (i+s, ), so the contrast difference L between the current lens position and its previous lens position and the contrast difference R between the current lens position and its subsequent lens position can be calculated, that is, , By transforming the equation, , , that is, the coordinates of the three points become (is, )、(i, ) and (i+s, ).
[0070] At this time, the transformed three-point coordinates can be brought into the peak-finding function to solve the target imaging position, which is expressed as:
[0071] Among them, i represents the current camera position, s represents the step size, Indicates the target imaging position.
[0072] In this way, by using three points for function fitting, the target imaging position can be quickly obtained, thereby improving the focusing efficiency.
[0073] This embodiment also provides a lens module for implementing the automatic focusing method as described above. Figure 4 As shown, the lens module includes: A lens 101, used for receiving light to form an optical path; The photosensitive element 102 includes an imaging area, and the imaging area is used to receive the light transmitted by the lens 101 to form an image; A motor 103, used for driving the lens 101 to move so as to change the distance between the lens 101 and the photosensitive element 102; The controller 104 is used to calculate and judge the contrast according to the image formed in the imaging area, and control the motor 103 to drive the lens 101 to move.
[0074] The lens module provided in this embodiment does not need to traverse all lens positions during the focusing process and can flexibly adjust the step size according to the shooting scene. This can not only effectively reduce the focusing time, but also be applicable to various scenes, solving the problem of how to achieve efficient automatic focusing.
[0075] In practical applications, the lens 101 may be a lens group composed of a plurality of lenses; the photosensitive element 102 may be an image sensor; the positional relationship and connection relationship among the lens 101, the photosensitive element 102, the motor 103 and the controller 104, the mechanical structure and the circuit design are well known to those skilled in the art and will not be elaborated in this application.
[0076] Furthermore, this embodiment further provides an imaging device, comprising the lens module as described above.
[0077] In practical applications, imaging devices include but are not limited to cameras, video cameras, monitors, etc.
[0078] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other. In addition, the different parts between the various embodiments can also be used in combination with each other, and the present invention is not limited to this.
[0079] The automatic focusing method, lens module, and imaging device provided in this embodiment include: controlling the lens to move step by step along a preset direction from the initial scanning position with a first step length, and calculating the first contrast corresponding to the imaging area at each lens position; judging whether each calculated first contrast satisfies the first preset condition; setting the re-scanning position according to the judgment result; controlling the lens to move step by step along the reverse direction of the preset direction from the re-scanning position with a second step length, and calculating the second contrast corresponding to the imaging area at each lens position; judging whether each calculated second contrast satisfies the second preset condition; if the calculated second contrast satisfies the second preset condition, the lens position corresponding to the second contrast is used as the target imaging position. By calculating the first contrast and judging whether the first preset condition is met, the range of the imaging focal length can be quickly determined, and further calculating the second contrast and judging whether the second preset condition is met can quickly determine the focal length, that is, the target imaging position of the lens. Since the focusing process does not need to traverse all lens positions, and the step length can be flexibly adjusted according to the shooting scene, it can not only effectively reduce the time consumption of focusing, but also be applicable to various scenes, solving the problem of how to achieve efficient automatic focusing.
[0080] The above description is only a description of the preferred embodiments of the present invention, and is not intended to limit the scope of the present invention. Any changes or modifications made by a person skilled in the art in the field of the present invention based on the above disclosure shall fall within the scope of protection of the claims.
Claims
1. An automatic focusing method, characterized in that: include: Control the lens to move step by step from the initial scanning position along the preset direction with a first step length, and calculate the first contrast of the imaging area corresponding to each lens position; Determining whether each calculated first contrast satisfies a first preset condition; According to the judgment result, the re-scanning position is set; Controlling the lens to move step by step from the rescanning position in the opposite direction of the preset direction with a second step length, and calculating a second contrast of the imaging area corresponding to each lens position; Determining whether each calculated second contrast satisfies a second preset condition; If the calculated second contrast satisfies the second preset condition, the lens position corresponding to the second contrast is used as the target imaging position.
2. The automatic focusing method according to claim 1, characterized in that: The method of controlling the lens to move step by step from the initial scanning position along a preset direction with a first step length and calculating the first contrast of the imaging area corresponding to each lens position includes: Set the initial scan position; Dividing the imaging area into a number of sub-areas; Control the lens to move step by step along a preset direction from an initial scanning position with a first step length, and obtain the imaging contrast of each sub-area at the current lens position; According to the imaging contrast of all sub-areas at the current lens position, a first contrast corresponding to the current lens position is calculated.
3. The automatic focusing method according to claim 2, characterized in that: The method for calculating the first contrast corresponding to the current lens position according to the imaging contrast of all sub-areas at the current lens position includes: Setting a contrast weight for each sub-region, wherein the contrast weight of a sub-region located at the center of the imaging region is higher than the contrast weight of a sub-region located at the edge of the imaging region; The imaging contrasts of all sub-regions at the current lens position are weightedly calculated using the contrast weights to obtain a first contrast corresponding to the current lens position.
4. The automatic focusing method according to claim 1, characterized in that: The method for determining whether each calculated first contrast satisfies a first preset condition comprises: If a first preset multiple of the first contrast corresponding to the current lens position is greater than the first contrast corresponding to the previous lens position and greater than the first contrast corresponding to the next lens position, it is determined that the calculated first contrast meets the first preset condition.
5. The automatic focusing method according to claim 4, characterized in that: The method for setting the rescanning position according to the judgment result includes: The next lens position after the current lens position that meets the first preset condition is used as the re-scanning position.
6. The automatic focusing method according to claim 1, characterized in that: The method of controlling the lens to move step by step from the rescanning position in the opposite direction of the preset direction with a second step length and calculating the second contrast of the imaging area corresponding to each lens position includes: Dividing the imaging area into a number of sub-areas; Control the lens to move gradually from the rescanning position in the opposite direction of the preset direction with a second step length, and obtain the imaging contrast of each sub-area at the current lens position; According to the imaging contrast of all sub-areas at the current lens position, a second contrast corresponding to the current lens position is calculated.
7. The automatic focusing method according to claim 6, characterized in that: The method for calculating the second contrast corresponding to the current lens position according to the imaging contrast of all sub-areas at the current lens position includes: Setting a contrast weight for each sub-region, wherein the contrast weight of a sub-region located at the center of the imaging region is higher than the contrast weight of a sub-region located at the edge of the imaging region; The imaging contrasts of all sub-regions at the current lens position are weightedly calculated using the contrast weights to obtain a second contrast corresponding to the current lens position.
8. The automatic focusing method according to claim 1, characterized in that: The method for determining whether each calculated second contrast satisfies the second preset condition comprises: If the second preset multiple of the second contrast corresponding to the current lens position is greater than the second contrast corresponding to the previous lens position and greater than the second contrast corresponding to the next lens position, it is determined that the calculated second contrast meets the second preset condition.
9. The automatic focusing method according to claim 4, characterized in that: The automatic focusing method also includes: If the second contrast does not meet the second preset condition after the calculation times of the second contrast reaches the preset times threshold, the target imaging position is calculated using the current lens position and the previous lens position and the next lens position that meet the first preset condition.
10. The automatic focusing method according to claim 9, characterized in that: The method for calculating the target imaging position by using the current lens position and the previous lens position and the next lens position that meet the first preset condition comprises: Calculate the contrast difference L between the current lens position and the previous lens position and the contrast difference R between the current lens position and the next lens position; Constructing a peak-finding function, wherein the peak-finding function is a convex function; Substitute the contrast differences L and R, the current lens position and the first step length into the peak search function to obtain the target imaging position, which is expressed as: Among them, i represents the current camera position, s represents the step size, Indicates the target imaging position.
11. The automatic focusing method according to claim 1, characterized in that: The first step length is greater than the second step length.
12. A lens module, used to implement the automatic focusing method according to any one of claims 1 to 11, characterized in that: The lens module comprises: A lens, used to receive light to form an optical path; A photosensitive element, comprising an imaging area, wherein the imaging area is used to receive the light transmitted by the lens to form an image; A motor, used for driving the lens to move so as to change the distance between the lens and the photosensitive element; The controller is used to calculate the contrast and make a judgment according to the image formed in the imaging area, and control the motor to drive the lens to move.
13. An imaging device, characterized in that: Comprising the lens module as described in claim 12.