Focusing method and device, electronic equipment and storage medium

By determining the focus strategy using a few sampling points and sharpness monotonic relationships during autofocus, the problem of slow speed of traditional focusing methods is solved, and fast and accurate focusing is achieved.

CN119496979AActive Publication Date: 2025-02-21GUANGZHOU SHIYUAN ELECTRONICS CO LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202311037952.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-16
Publication Date
2025-02-21
Estimated Expiration
2043-08-16

AI Technical Summary

Technical Problem

The traditional autofocus search method is slow and it is difficult to quickly lock the target focus position.

Method used

Through a few sampling points, the corresponding focus strategy is determined based on the monotonic relationship of clarity between each sampling point, including determining the target focus based on the target adjustment step or the target focus fit curve.

Benefits of technology

While ensuring accurate focus, it can quickly lock the target focus position and improve the focus speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119496979A_ABST
    Figure CN119496979A_ABST
Patent Text Reader

Abstract

The invention discloses a focusing method and device, electronic equipment and a storage medium. The method comprises the following steps: determining at least three initial sampling points and the definition of the at least three initial sampling points from a target focal length range according to a preset rule; judging whether the definitions corresponding to the at least three initial sampling points have monotonicity or not; if yes, determining a corresponding target adjustment step length based on the initial sampling point with the maximum corresponding definition in the at least three initial sampling points, and determining a target focus based on the target adjustment step length; and if not, a target focusing fitting curve is determined based on the at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points, and a target focus is determined based on the target focusing fitting curve, so that a corresponding focusing strategy can be determined through a few sampling points according to the monotonic relation of the sharpness among the sampling points. While the focusing accuracy is ensured, the target focus position can be quickly locked, and the focusing speed is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a focusing method, device, electronic device and storage medium. Background Art

[0002] At present, traditional autofocus search methods often use hill climbing search method or variable step-size hill climbing search method to find the quasi-focus position. The ideal focus evaluation function curve is a parabola shape. When reaching the peak, it corresponds to the optimal imaging position. When leaving the optimal point, the function decreases monotonically. Taking the variable step-size hill climbing search algorithm as an example, when focusing starts, the focus direction and a larger step size are set. The focus evaluation function value is calculated while acquiring the image. When the evaluation value of the latest acquired image is less than the evaluation value of the previous image, the focus direction is changed; when crossing the peak again, the step size is reduced, and the optimal lens position is finally found. This makes the autofocus speed slower in the traditional focus method. Summary of the invention

[0003] The embodiments of the present application provide a focusing method, device, electronic device and storage medium, which can determine the corresponding focusing strategy through a small number of sampling points and according to the monotonic relationship of the clarity between the sampling points, so as to ensure accurate focusing and quickly lock the target focus position, thereby improving the focusing speed. The technical solution is as follows:

[0004] In a first aspect, an embodiment of the present application provides a focusing method, the method comprising:

[0005] Determine at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from within the target focal length range according to a preset rule;

[0006] Determine whether the clarity corresponding to the at least three initial sampling points is monotonic;

[0007] If yes, determining the corresponding target adjustment step length based on the initial sampling point with the largest corresponding clarity among the at least three initial sampling points, and determining the target focus based on the target adjustment step length;

[0008] If not, a corresponding target focus fitting curve is determined based on the at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points, and the target focus is determined based on the target focus fitting curve.

[0009] In a possible implementation, the target adjustment step size includes a first target adjustment step size;

[0010] The above-mentioned determining the target focus based on the above-mentioned target adjustment step size includes:

[0011] In the case where the clarity corresponding to the at least three initial sampling points decreases monotonically, subtracting the first target adjustment step from the initial sampling point with the largest clarity among the at least three initial sampling points to obtain a first sampling point, and determining the clarity corresponding to the first sampling point;

[0012] Subtracting the first target adjustment step from the first sampling point to obtain a second sampling point, and determining the clarity corresponding to the second sampling point;

[0013] It is determined whether the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point, and the first sampling point is updated to the second sampling point, and the steps of subtracting the first target adjustment step from the first sampling point to obtain the second sampling point and determining the clarity corresponding to the second sampling point are performed again, until the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point for consecutive target times, and the first sampling point corresponding to the first occurrence of the clarity corresponding to the first sampling point greater than the clarity corresponding to the second sampling point is determined as the target focus.

[0014] In a possible implementation, the target adjustment step size includes a second target adjustment step size;

[0015] The above-mentioned determining the target focus based on the above-mentioned target adjustment step size includes:

[0016] In the case where the clarity corresponding to the at least three initial sampling points increases monotonically, adding the second target adjustment step to the initial sampling point with the largest clarity among the at least three initial sampling points to obtain a third sampling point, and determining the clarity corresponding to the third sampling point;

[0017] Adding the third sampling point to the second target adjustment step to obtain a fourth sampling point, and determining the clarity corresponding to the fourth sampling point;

[0018] It is determined whether the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point, and the third sampling point is updated to the fourth sampling point. The steps of adding the second target adjustment step to the third sampling point to obtain the fourth sampling point and determining the clarity corresponding to the fourth sampling point are performed again until the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point for consecutive target times. The third sampling point corresponding to the first occurrence of the clarity corresponding to the third sampling point being greater than the clarity corresponding to the fourth sampling point is determined as the target focus.

[0019] In a possible implementation, before adding the second target adjustment step to the initial sampling point with the largest clarity among the at least three initial sampling points to obtain a third sampling point, and determining the clarity corresponding to the third sampling point, the method further includes:

[0020] Determine whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points is greater than a preset difference;

[0021] The step of adding the second target adjustment step to the initial sampling point with the largest corresponding definition among the at least three initial sampling points to obtain a third sampling point, and determining the definition corresponding to the third sampling point, includes:

[0022] If not, then the initial sampling point with the largest corresponding definition among the at least three initial sampling points is added with the second target adjustment step to obtain a third sampling point, and the definition corresponding to the third sampling point is determined.

[0023] In a possible implementation, the target adjustment step further includes a third target adjustment step; the third target adjustment step is greater than the second target adjustment step, and is less than or equal to a focal difference between the maximum focal point and an initial sampling point with the largest corresponding clarity among the at least three initial sampling points;

[0024] After determining whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points is greater than a preset difference, the method further includes:

[0025] If yes, then respectively adding the third target adjustment step to the at least three initial sampling points to obtain corresponding at least three new sampling points, and determining the sharpness corresponding to the at least three new sampling points;

[0026] The at least three initial sampling points are updated to the at least three new sampling points, and the step of determining whether the sharpness corresponding to the at least three initial sampling points is monotonic is performed again.

[0027] In a possible implementation, the number of the initial sampling points is at least 4; and the step of determining the target focus based on the target focus fitting curve includes:

[0028] Determine the target extreme value point corresponding to the target focus fitting curve; the target focus fitting curve is obtained by solving a quadratic equation group using a least squares method based on at least 4 initial sampling points;

[0029] The target focus is determined based on the above target extreme point.

[0030] In a possible implementation, determining the target focus based on the target extreme point includes:

[0031] Subtract the preset step size from the above target extreme point to obtain the fifth sampling point;

[0032] Adding the fourth target adjustment step length to the fifth sampling point obtains a sixth sampling point, and determining the clarity corresponding to the sixth sampling point;

[0033] It is determined whether the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point, and the fifth sampling point is updated to the sixth sampling point. The steps of adding the fourth target adjustment step to the fifth sampling point to obtain the sixth sampling point and determining the clarity corresponding to the sixth sampling point are performed again until the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point for consecutive target times. The fifth sampling point corresponding to the first occurrence of the clarity corresponding to the fifth sampling point being greater than the clarity corresponding to the sixth sampling point is determined as the target focus.

[0034] In a second aspect, an embodiment of the present application provides a focusing device, the focusing device comprising:

[0035] A first determination module is used to determine at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from within the target focal length range according to a preset rule;

[0036] A first judging module is used to judge whether the clarity corresponding to the at least three initial sampling points is monotonic;

[0037] A second determination module is configured to determine a corresponding target adjustment step length based on an initial sampling point having the largest corresponding clarity among the at least three initial sampling points when the clarity corresponding to the at least three initial sampling points is monotonic, and determine a target focus based on the target adjustment step length;

[0038] The third determination module is used to determine the corresponding target focus fitting curve based on the at least three initial sampling points and the clarity corresponding to the at least three initial sampling points when the clarity corresponding to the at least three initial sampling points is not monotonic, and determine the target focus based on the target focus fitting curve.

[0039] In a possible implementation, the target adjustment step size includes a first target adjustment step size;

[0040] The second determination module includes:

[0041] A first determining unit is configured to obtain a first sampling point by subtracting the first target adjustment step from an initial sampling point having the largest clarity among the at least three initial sampling points, and determine the clarity corresponding to the first sampling point, when the clarity corresponding to the at least three initial sampling points decreases monotonically;

[0042] A second determining unit, configured to obtain a second sampling point by subtracting the first target adjustment step from the first sampling point, and determine a definition corresponding to the second sampling point;

[0043] A third determining unit is configured to determine whether the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point, and to update the first sampling point to the second sampling point, and to perform again the steps of subtracting the first target adjustment step from the first sampling point to obtain the second sampling point, and to determine the clarity corresponding to the second sampling point, until the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point for a target number of consecutive times, and then determine the first sampling point corresponding to the first occurrence of the clarity corresponding to the first sampling point greater than the clarity corresponding to the second sampling point as the target focus.

[0044] In a possible implementation, the target adjustment step size includes a second target adjustment step size;

[0045] The second determination module includes:

[0046] a fourth determining unit, configured to, when the sharpnesses corresponding to the at least three initial sampling points increase monotonically, add the second target adjustment step to an initial sampling point having the largest sharpness among the at least three initial sampling points to obtain a third sampling point, and determine the sharpness corresponding to the third sampling point;

[0047] a fifth determining unit, configured to add the second target adjustment step to the third sampling point to obtain a fourth sampling point, and determine a definition corresponding to the fourth sampling point;

[0048] a sixth determining unit, configured to determine whether the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point, and to update the third sampling point to the fourth sampling point, and to perform again the steps of adding the second target adjustment step to the third sampling point to obtain the fourth sampling point, and to determine the clarity corresponding to the fourth sampling point, until the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point for a target number of consecutive times, and then determine the third sampling point corresponding to the first occurrence of the clarity corresponding to the third sampling point greater than the clarity corresponding to the fourth sampling point as the target focus.

[0049] In a possible implementation, the focusing device further includes:

[0050] A second judgment module is used to judge whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points is greater than a preset difference value;

[0051] The fourth determining unit is specifically used for:

[0052] If not, then the initial sampling point with the largest corresponding definition among the at least three initial sampling points is added with the second target adjustment step to obtain a third sampling point, and the definition corresponding to the third sampling point is determined.

[0053] In a possible implementation, the target adjustment step further includes a third target adjustment step; the third target adjustment step is greater than the second target adjustment step, and is less than or equal to a focal difference between the maximum focal point and an initial sampling point with the largest corresponding clarity among the at least three initial sampling points;

[0054] The focusing device further comprises:

[0055] a fourth determination module, configured to, if yes, add the third target adjustment step to the at least three initial sampling points to obtain corresponding at least three new sampling points, and determine the sharpness corresponding to the at least three new sampling points;

[0056] An updating module is used to update the at least three initial sampling points to the at least three new sampling points, and to perform again the step of determining whether the sharpness corresponding to the at least three initial sampling points is monotonic.

[0057] In a possible implementation, the number of the initial sampling points is at least 4; and the third determination module includes:

[0058] A seventh determination unit is used to determine a target extreme value point corresponding to the target focus fitting curve; the target focus fitting curve is obtained by solving a quadratic equation group using a least squares method based on at least four of the initial sampling points;

[0059] An eighth determination unit is used to determine a target focus based on the target extreme point.

[0060] In a possible implementation manner, the eighth determining unit is specifically configured to:

[0061] The target extreme point is subtracted from the preset step length to obtain a fifth sampling point; the fifth sampling point is added with the fourth target adjustment step length to obtain a sixth sampling point, and the clarity corresponding to the sixth sampling point is determined; it is determined whether the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point, and the fifth sampling point is updated to the sixth sampling point, and the steps of adding the fourth target adjustment step length to the fifth sampling point to obtain the sixth sampling point and determining the clarity corresponding to the sixth sampling point are performed again, until the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point for consecutive target times, the fifth sampling point corresponding to the first occurrence of the clarity corresponding to the fifth sampling point being greater than the clarity corresponding to the sixth sampling point is determined as the target focus.

[0062] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps provided by the first aspect of the embodiment of the present application or any possible implementation method of the first aspect.

[0063] In a fourth aspect, an embodiment of the present application provides a computer storage medium, which stores multiple instructions, and the instructions are suitable for being loaded by a processor and executing the method steps provided by the first aspect of the embodiment of the present application or any possible implementation of the first aspect.

[0064] The beneficial effects brought about by the technical solutions provided by some embodiments of the present application include at least:

[0065] In one or more embodiments of the present application, at least three initial sampling points and the clarity corresponding to the at least three initial sampling points are determined from the target focal length range according to a preset rule, and it is determined whether the clarity corresponding to the at least three initial sampling points is monotonic; if so, the corresponding target adjustment step is determined based on the initial sampling point with the largest corresponding clarity among the at least three initial sampling points, and the target focus is determined based on the target adjustment step; if not, a target focus fitting curve is determined based on the at least three initial sampling points and the clarity corresponding to the at least three initial sampling points, and the target focus is determined based on the target focus fitting curve, so that the corresponding focus strategy can be determined by a small number of sampling points according to the monotonic relationship of the clarity between the sampling points, so that while ensuring accurate focus, the target focus position can be quickly locked to improve the focusing speed.

[0066] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0068] Figure 1 A schematic structural diagram of an execution body of a focusing method provided by an exemplary embodiment of the present application;

[0069] Figure 2 A schematic diagram of the relationship between a motor position and a corresponding focal length image clarity provided by an exemplary embodiment of the present application;

[0070] Figure 3 A flowchart of a focusing method provided by an exemplary embodiment of the present application;

[0071] Figure 4 A schematic diagram of an implementation flow of determining a target focus provided by an exemplary embodiment of the present application;

[0072] Figure 5 A schematic diagram of another implementation flow of determining a target focus provided by an exemplary embodiment of the present application;

[0073] Figure 6 A schematic diagram of another implementation flow of determining a target focus provided by an exemplary embodiment of the present application;

[0074] Figure 7 A schematic diagram of another implementation flow of determining a target focus provided by an exemplary embodiment of the present application;

[0075] Figure 8 A schematic diagram of another implementation flow of determining a target focus provided by an exemplary embodiment of the present application;

[0076] Fig. 9 A schematic structural diagram of a focusing device provided by an exemplary embodiment of the present application;

[0077] Fig.10 A schematic structural diagram of an electronic device provided as an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0078] In order to make the features and advantages of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0079] The terms "first", "second", "third", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" 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 limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0080] Please refer to the following Figure 1 , which is a schematic diagram of the structure of an execution body of a focusing method provided by an exemplary embodiment of the present application. Figure 1 As shown, the focusing method can be executed on a camera but is not limited to it. The camera includes a motor 110, and its focusing principle is to set the motor position of the camera, obtain the clarity of the current focal length picture, and trigger the focus when the current clarity is greater than a certain threshold. The focusing process is to pull the focal length of the camera once, and obtain a series of values ​​(clarity), and then find the maximum value from these data. The motor position corresponding to the maximum value is the current focus. Due to the principle of image imaging, for example Figure 2 As shown, the relationship between the motor position (focus) and the corresponding focal length picture clarity (focus curve) always presents a parabola or normal distribution shape. Therefore, in a complete focusing process, the motor 110 will run the entire range. For example, the motor position (corresponding focal length) needs to be adjusted from large to small or from small to large, and the corresponding focal length picture will also change from "blurred" to "clear" and then to "blurred", so as to find the motor position (focus) corresponding to the maximum clarity.

[0081] It can be understood that the focusing method provided in the embodiment of the present application can be executed by a camera device including a motor, and can also be executed by other devices connected to the above-mentioned camera device, and the embodiment of the present application is not limited to this.

[0082] Next, combine Figure 1 and Figure 2 , introduces the focusing method provided by the embodiment of the present application. For details, please refer to Figure 3 , which is a flowchart of a focusing method provided by an exemplary embodiment of the present application. Figure 3 As shown, the focusing method includes the following steps:

[0083] S301, determining at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from within a target focal length range according to a preset rule.

[0084] Specifically, the above-mentioned initial sampling point is the initial sampling position of the camera motor, corresponding to the initial focal length of the camera. The above-mentioned at least three initial sampling points can be obtained by gradually increasing a certain step length based on the minimum focal length corresponding to the camera, or gradually subtracting a certain step length based on the maximum focal length corresponding to the camera, or only need to be set according to the actual situation of the camera and user experience. The focal length distance between two adjacent initial sampling points in the above-mentioned at least three initial sampling points can be equal or unequal, and the embodiments of the present application are not limited to this. After determining the initial sampling point of the camera motor, the corresponding initial sampling image can be obtained by shooting based on the initial sampling point, and the clarity corresponding to the initial sampling point can be calculated based on the initial sampling image.

[0085] Exemplarily, when the camera is turned on or receives a focus command triggered by the user, the first initial sampling point x1 can be obtained from the minimum focal point plus K1, the second initial sampling point x2 can be obtained from the first initial sampling point plus K2, the third initial sampling point x3 can be obtained from the second initial sampling point plus K3, and the fourth initial sampling point x4 can be obtained from the third initial sampling point plus K4, and the corresponding sharpness y1, y2, y3, y4 can be obtained through the respective corresponding initial sampling images. The above K1, K2, K3, and K4 are all constants, which can be partially or completely the same, or can be different, and can be set according to actual conditions, and the embodiments of the present application do not limit this.

[0086] It can be understood that in order to ensure the effectiveness of the initial sampling points, the above-mentioned target focal length range can be the focal length range that the camera can actually adjust; in order to further ensure the focusing efficiency and avoid as much as possible the problem that the focal length distance between the initial sampling points is too large, which makes the focusing process more complicated and affects the focusing efficiency, the above-mentioned target focal length range can be any focal length range within the focal length range that the camera can actually adjust, in which the length between the focal lengths at the left and right ends is less than the target length.

[0087] It can be understood that the at least three initial sampling points may include, but are not limited to, 3, 4, 5 initial sampling points, etc. To a certain extent, the fewer the number of initial sampling points, the less the amount of calculation involved in the focusing process, and the higher the focusing efficiency; to a certain extent, the more the number of initial sampling points, the greater the fineness corresponding to the focusing, and the higher the focusing accuracy. When the number of initial sampling points exceeds a certain value, the focusing accuracy will no longer change or change slightly, but the focusing efficiency will be greatly reduced.

[0088] S302: Determine whether the sharpness corresponding to at least three initial sampling points is monotonic.

[0089] Specifically, after determining at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points, it can be determined whether they are monotonic based on the size relationship between the sharpness corresponding to the at least three initial sampling points, and then the corresponding target focusing strategy can be determined according to the monotonicity of the sharpness corresponding to the at least three initial sampling points.

[0090] S303: If yes, determine the corresponding target adjustment step length based on the initial sampling point with the largest corresponding clarity among the at least three initial sampling points, and determine the target focus based on the target adjustment step length.

[0091] Specifically, the target focus is the motor position (focus) with the maximum clarity within the focal length range of the camera. When the clarity corresponding to the at least three initial sampling points is monotonic, since the at least three initial sampling points are all within the target focal length range, that is, the initial sampling points are close to each other, it can be considered that the at least three initial sampling points are located on the same side of the focus corresponding to the maximum clarity of the camera, for example but not limited to being located at Figure 2 The rising edge or falling edge of the curve shown in the figure can determine the corresponding target adjustment step size based on the initial sampling point with the largest corresponding clarity among the at least three initial sampling points. Therefore, when the clarity corresponding to the at least three initial sampling points is monotonic, focusing can be achieved by adjusting the step size of the initial sampling point with the largest corresponding clarity among the at least three initial sampling points, which not only reduces the amount of calculation in the focusing process, improves the focusing efficiency, but also ensures the focusing accuracy.

[0092] S304: If not, determine a corresponding target focus fitting curve based on at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points, and determine the target focus based on the target focus fitting curve.

[0093] Specifically, when the resolutions corresponding to at least three initial sampling points are not monotonic, it can be considered that the at least three initial sampling points are located on both sides of the focus corresponding to the maximum resolution of the camera, for example but not limited to, respectively located at Figure 2 The rising edge and the falling edge of the curve shown in the figure can determine the corresponding target focus fitting curve based on at least 3 initial sampling points and the clarity corresponding to the at least 3 initial sampling points. Therefore, when the clarity corresponding to the at least 3 initial sampling points is not monotonic, focusing can be achieved by fitting the focus curve, which can ensure the accuracy of focusing and improve the focusing efficiency.

[0094] It can be understood that, in the case where the clarity corresponding to at least three initial sampling points is monotonic, for the method of achieving focusing by determining the corresponding target focus fitting curve based on at least three initial sampling points and the clarity corresponding to at least three initial sampling points, the method of achieving focusing by adjusting the step size of the initial sampling point with the largest clarity among at least three initial sampling points is more accurate and has a better focusing effect. In the case where the clarity corresponding to at least three initial sampling points is not monotonic, focusing can also be achieved by, but not limited to, adjusting the step size of the initial sampling point with the largest clarity among at least three initial sampling points. However, since it is not possible to determine whether the initial sampling point with the largest clarity among at least three initial sampling points is located at the rising edge or the falling edge of the focus curve, it needs to be adjusted left and right. Compared with achieving focusing directly by fitting the focus curve, the adjustment process is longer and the focusing efficiency is lower.

[0095] In an embodiment of the present application, at least three initial sampling points and the clarity corresponding to the at least three initial sampling points can be determined from the target focal length range according to a preset rule, and based on the monotonic relationship between the clarity corresponding to the at least three initial sampling points, the corresponding target focusing strategy is determined. Finally, the target focus is determined directly based on the target focusing strategy (target adjustment step or target focus fitting curve), so that the corresponding focusing strategy can be determined through a small number of sampling points and according to the monotonic relationship between the corresponding clarity between each sampling point, so as to ensure accurate focusing while quickly locking the target focus position and improving the focusing speed.

[0096] Optionally, when the sharpness corresponding to at least three initial sampling points is monotonic, the target adjustment step size includes a first target adjustment step size. Figure 4 As shown, in the above S303, the implementation process of determining the target focus based on the target adjustment step may include:

[0097] S401, when the clarity corresponding to at least three initial sampling points decreases monotonically, subtracting a first target adjustment step from an initial sampling point having the largest clarity among the at least three initial sampling points to obtain a first sampling point, and determining the clarity corresponding to the first sampling point.

[0098] Specifically, when the clarity corresponding to at least three initial sampling points decreases monotonically, it can be considered that the at least three initial sampling points are all located on the right side of the focus corresponding to the maximum clarity of the camera, that is, they are all located on the falling edge of the focus curve, and it is necessary to subtract the first target adjustment step from the initial sampling point corresponding to the maximum clarity among the at least three initial sampling points, that is, to move the initial sampling point corresponding to the maximum clarity to the left so that it is close to the focus corresponding to the maximum clarity of the camera, and obtain the first sampling point. Then, sampling is performed based on the first sampling point, that is, the motor is located at the first sampling point to shoot a first sampling image, and the clarity corresponding to the first sampling point is calculated.

[0099] S402: Subtract the first target adjustment step from the first sampling point to obtain a second sampling point, and determine the definition corresponding to the second sampling point.

[0100] Specifically, the implementation process of the above S402 is similar to the implementation process of obtaining the first sampling point by subtracting the first target adjustment step from the initial sampling point with the largest corresponding clarity among at least three initial sampling points in the above S401, and determining the clarity corresponding to the first sampling point, which will not be repeated here.

[0101] S403, determining whether the definition corresponding to the first sampling point is greater than the definition corresponding to the second sampling point, and updating the first sampling point to the second sampling point.

[0102] Specifically, after determining the first sampling point located on the left side of the initial sampling point with the largest corresponding definition among the at least three initial sampling points and the second sampling point located on the left side of the first sampling point, it can be determined whether the definition corresponding to the first sampling point is greater than the definition corresponding to the second sampling point, and the number of times can be counted. If so, it means that the second sampling point may have passed the focus corresponding to the maximum definition of the camera and is located on the left side thereof; if not, it means that the second sampling point may not have passed the focus corresponding to the maximum definition of the camera and is still located on the right side thereof.

[0103] S404, determining whether the definition corresponding to the first sampling point of the consecutive target times is greater than the definition corresponding to the second sampling point.

[0104] Specifically, the target number of times may be, but is not limited to, 2 times, 3 times, etc.

[0105] S405: If yes, determine the first sampling point corresponding to the first occurrence of the clarity corresponding to the first sampling point greater than the clarity corresponding to the second sampling point as the target focus.

[0106] Specifically, in order to avoid the situation that the definition corresponding to the first sampling point is greater than the definition corresponding to the second sampling point due to the contingency and instability in the sampling process, and the second sampling point is mistakenly believed to have passed the focus corresponding to the maximum definition of the camera and is located on the left side thereof, after the first sampling point is updated to the second sampling point, the above S402 can be performed again to obtain the second sampling point by subtracting the first target adjustment step from the first sampling point, and to determine the definition corresponding to the second sampling point, if there is no consecutive target time when the definition corresponding to the first sampling point is greater than the definition corresponding to the second sampling point. Only when there is a consecutive target time when the definition corresponding to the first sampling point is greater than the definition corresponding to the second sampling point, the first sampling point corresponding to the first time when the definition corresponding to the first sampling point is greater than the definition corresponding to the second sampling point is determined as the target focus, thereby avoiding the influence of the contingency and instability in the sampling process on the focusing result, and improving the accuracy and stability of focusing.

[0107] Optionally, when the clarity corresponding to at least three initial sampling points is monotonic, the target adjustment step size includes a second target adjustment step size, and the second target adjustment step size may be the same as or different from the first target adjustment step size, which is not limited in this embodiment of the present application. Figure 5 As shown, in the above S303, the implementation process of determining the target focus based on the target adjustment step may include:

[0108] S501, when the clarity corresponding to at least three initial sampling points increases monotonically, adding a second target adjustment step to an initial sampling point having the largest clarity among the at least three initial sampling points to obtain a third sampling point, and determining the clarity corresponding to the third sampling point.

[0109] Specifically, when the clarity corresponding to at least three initial sampling points increases monotonically, it can be considered that the at least three initial sampling points are all located on the left side of the focus corresponding to the maximum clarity of the camera, that is, they are all located on the rising edge of the focus curve, and it is necessary to add the second target adjustment step to the initial sampling point with the maximum clarity among the at least three initial sampling points, that is, to move the initial sampling point with the maximum clarity to the right, so that it is close to the focus corresponding to the maximum clarity of the camera, and obtain the third sampling point. Then, sampling is performed based on the third sampling point, that is, the motor is located at the third sampling point to shoot a third sampling image, and the clarity corresponding to the third sampling point is calculated.

[0110] S502: Add the second target adjustment step length to the third sampling point to obtain a fourth sampling point, and determine the definition corresponding to the fourth sampling point.

[0111] Specifically, the implementation process of the above S502 is similar to the implementation process of adding the second target adjustment step to the initial sampling point with the largest corresponding clarity among at least three initial sampling points to obtain the third sampling point, and determining the clarity corresponding to the third sampling point in the above S501, and will not be repeated here.

[0112] S503: Determine whether the definition corresponding to the third sampling point is greater than the definition corresponding to the fourth sampling point, and update the third sampling point to the fourth sampling point.

[0113] Specifically, after determining the third sampling point located on the right side of the initial sampling point with the largest definition among the at least three initial sampling points, and the fourth sampling point located on the right side of the third sampling point, it can be determined whether the definition corresponding to the third sampling point is greater than the definition corresponding to the fourth sampling point, and the number of times can be counted. If so, it means that the fourth sampling point may have passed the focus corresponding to the maximum definition of the camera and is located on the right side thereof; if not, it means that the fourth sampling point may not have passed the focus corresponding to the maximum definition of the camera and is still located on the left side thereof.

[0114] S504, determining whether the definition corresponding to the third sampling point of the consecutive target is greater than the definition corresponding to the fourth sampling point.

[0115] Specifically, the target number of times may be, but is not limited to, 2 times, 3 times, etc.

[0116] S505: If yes, determine the third sampling point corresponding to the first occurrence of the third sampling point having a definition greater than that corresponding to the fourth sampling point as the target focus.

[0117] Specifically, in order to avoid the situation that the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point due to the contingency and instability in the sampling process, and the fourth sampling point is mistakenly believed to have passed the focus corresponding to the maximum clarity of the camera and is located on the right side thereof, after the third sampling point is updated to the fourth sampling point, the above S502 can be performed again to add the second target adjustment step to the third sampling point to obtain the fourth sampling point, and to determine the clarity corresponding to the fourth sampling point, if there is no continuous target time when the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point. Only when there is a continuous target time when the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point, the third sampling point corresponding to the first time when the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point is determined as the target focus, thereby avoiding the influence of the contingency and instability in the sampling process on the focusing result, and improving the accuracy and stability of focusing.

[0118] Optionally, when the clarity corresponding to at least three initial sampling points is monotonic, the target adjustment step may include a second target adjustment step and a third target adjustment step. The second target adjustment step may be the same as or different from the first target adjustment step, and the embodiment of the present application does not limit this. The second target adjustment step may be, but is not limited to, 1, 0.5, etc., and the third target adjustment step may be, but is not limited to, 2, 4, etc. The third target adjustment step is greater than the second target adjustment step, and is less than or equal to the focal length difference between the maximum focal length point of the camera and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points. Figure 6 As shown, in the above S303, the implementation process of determining the target focus based on the target adjustment step may include:

[0119] S601: When the sharpness corresponding to at least three initial sampling points increases monotonically, determine whether the focal length difference between the maximum focal length point and the initial sampling point with the largest sharpness among the at least three initial sampling points is greater than a preset difference.

[0120] Specifically, when the clarity corresponding to at least three initial sampling points increases monotonically, it can be considered that the at least three initial sampling points are all located on the left side of the focus corresponding to the maximum clarity of the camera, that is, they are all located on the rising edge of the focus curve. In order to ensure the focusing speed and avoid the problem of slow focusing speed caused by too large a distance between the initial sampling point with the largest clarity among the at least three initial sampling points and the focus corresponding to the maximum clarity of the camera and too small an adjustment step, it can be determined whether the focal length difference between the maximum focal length point of the camera and the initial sampling point with the largest clarity among the at least three initial sampling points is greater than a preset difference. If so, it means that the distance between the initial sampling point corresponding to the maximum definition and the focus corresponding to the maximum definition of the camera may be far, and the initial sampling point corresponding to the maximum definition still has a large adjustment space, and it can be adjusted by a larger third target adjustment step, that is, execute the following S607, so as to improve the focusing speed; if not, it means that the distance between the initial sampling point corresponding to the maximum definition and the focus corresponding to the maximum definition of the camera may be close, and the initial sampling point corresponding to the maximum definition has a small adjustment space, and it only needs to be adjusted by a smaller second target adjustment step, that is, execute the following S602, which can ensure both the focusing speed and the focusing accuracy.

[0121] S602: If not, add the second target adjustment step to the initial sampling point with the largest corresponding definition among the at least three initial sampling points to obtain a third sampling point, and determine the definition corresponding to the third sampling point.

[0122] Specifically, the implementation process of S602 is similar to that of S501, and will not be described in detail here.

[0123] S603: Add the second target adjustment step length to the third sampling point to obtain a fourth sampling point, and determine the definition corresponding to the fourth sampling point.

[0124] Specifically, S603 is consistent with S502 and will not be described in detail here.

[0125] S604: Determine whether the definition corresponding to the third sampling point is greater than the definition corresponding to the fourth sampling point, and update the third sampling point to the fourth sampling point.

[0126] Specifically, S604 is consistent with S503 and will not be described in detail here.

[0127] S605, determining whether the definition corresponding to the third sampling point of the consecutive target is greater than the definition corresponding to the fourth sampling point.

[0128] Specifically, S605 is consistent with S504 and will not be described in detail here.

[0129] S606: If yes, determine the third sampling point corresponding to the first occurrence of the third sampling point having a definition greater than that corresponding to the fourth sampling point as the target focus.

[0130] Specifically, S606 is consistent with S505 and will not be described in detail here.

[0131] Please continue to refer to Figure 6 ,like Figure 6 As shown, in S601, when the sharpness corresponding to at least three initial sampling points increases monotonically, after determining whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding sharpness among the at least three initial sampling points is greater than a preset difference, the focusing method further includes:

[0132] S607: If yes, then respectively add the third target adjustment step to the at least three initial sampling points to obtain corresponding at least three new sampling points, and determine the sharpness corresponding to the at least three new sampling points.

[0133] Specifically, if the focal length difference between the maximum focal length point and the initial sampling point with the largest clarity among the at least three initial sampling points is greater than the preset difference, it means that the distance between the initial sampling point with the largest clarity and the focus corresponding to the maximum clarity of the camera may be far, and the initial sampling point with the largest clarity still has a large adjustment space. In order to improve the focusing speed, resampling can be performed based on the at least three initial sampling points with a larger third target adjustment step, that is, the at least three initial sampling points are all moved to the right by the third target adjustment step to obtain the corresponding at least three new sampling points.

[0134] S608: Update at least three initial sampling points to at least three new sampling points.

[0135] Specifically, after obtaining at least 3 corresponding new sampling points, it is also necessary to perform the step of updating at least 3 initial sampling points to the at least 3 new sampling points and then executing the above S302 again to determine whether the clarity corresponding to the at least 3 initial sampling points is monotonic, so as to complete the focusing quickly and accurately.

[0136] Optionally, in the case where the clarity corresponding to the at least 3 initial sampling points is not monotonic, as Figure 7 shown, in the above S304, the implementation process of determining the target focus based on the target focusing fitting curve may include:

[0137] S701, determining the target extreme point corresponding to the target focusing fitting curve, where the target focusing fitting curve is obtained by solving a quadratic equation system using the least squares method based on at least 4 initial sampling points.

[0138] Specifically, to ensure the accuracy of the target focusing fitting curve and avoid the problem that the focusing accuracy is affected by incorrect sampling of a certain initial sampling point, the target focusing fitting curve may but is not limited to be obtained by solving a quadratic equation system using the least squares method based on the at least 4 initial sampling points and the clarity corresponding to each of the at least 4 initial sampling points.

[0139] Exemplarily, if four initial sampling points x1, x2, x3, x4 are determined, and x1 < x2 < x3 < x4, which respectively correspond to the clarity y1, y2, y3, y4. If y1 < y2 <y3>y4 or y1 <y2>y3>y4, then we get four points (x1,y1), (x2,y2), (x3,y3), (x4,y4). The following set of equations can be obtained by fitting the quadratic equations:

[0140]

[0141] Then, the least square method is used to solve the above equations to obtain the three constant parameters a, b, and c, and the corresponding target extreme point is obtained through the obtained fitting equation group (target focus fitting curve)

[0142] It can be understood that the above-mentioned target focus fitting curve can also be obtained by directly solving the quadratic equation group based on the three initial sampling points. The target focus fitting curve obtained by solving the quadratic equation group using the least squares method based on at least four initial sampling points is more accurate and has a better focusing effect than the target focus fitting curve obtained by directly solving the quadratic equation group based only on the three initial sampling points.

[0143] S702, determining a target focus based on the target extreme point.

[0144] Optionally, after determining the target extreme value point corresponding to the target focus fitting curve, the target extreme value point may be directly determined as the target focus corresponding to the camera, but is not limited to being determined.

[0145] Optionally, in order to further improve the accuracy of focusing, the error between the target extreme point and the focus corresponding to the actual maximum definition of the camera is reduced, such as Figure 8 As shown, the implementation process of the above S702, determining the target focus based on the target extreme point, may include:

[0146] S801, subtracting a preset step size from the target extreme point to obtain a fifth sampling point.

[0147] Specifically, the above-mentioned preset step size can be preset according to the focusing accuracy required by the user, and the embodiments of the present application are not limited to this.

[0148] S802: Add the fourth target adjustment step length to the fifth sampling point to obtain a sixth sampling point, and determine the definition corresponding to the sixth sampling point.

[0149] Specifically, the fourth target adjustment step is greater than 0 and less than the difference between the fifth sampling point and the maximum focal length point of the camera. To a certain extent, the smaller the fourth target adjustment step is, the higher the corresponding focusing accuracy is.

[0150] S803, determining whether the definition corresponding to the fifth sampling point is greater than the definition corresponding to the sixth sampling point, and updating the fifth sampling point to the sixth sampling point.

[0151] Specifically, it can be determined whether the definition corresponding to the fifth sampling point located on the left side of the target extreme point is greater than the definition corresponding to the sixth sampling point located on the right side of the fifth sampling point, and the number of times can be counted. If so, it means that the sixth sampling point may have passed the focus corresponding to the maximum definition of the camera and is located on the right side thereof; if not, it means that the sixth sampling point may not have passed the focus corresponding to the maximum definition of the camera and is still located on the left side thereof.

[0152] S804, determining whether the definition corresponding to the fifth sampling point of the consecutive target is greater than the definition corresponding to the sixth sampling point.

[0153] S805: If yes, determine the fifth sampling point corresponding to the first appearance of the fifth sampling point as the target focus when the clarity is greater than the clarity of the sixth sampling point.

[0154] Specifically, in order to avoid the situation that the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point due to the contingency and instability in the sampling process, and the sixth sampling point is mistakenly believed to have passed the focus corresponding to the maximum clarity of the camera and is located on the right side thereof, it is also possible to perform the above S802 again when the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point for a continuous target time, and to add the fourth target adjustment step to the fifth sampling point to obtain the sixth sampling point, and to determine the clarity corresponding to the sixth sampling point, until the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point for a continuous target time. Only then will the fifth sampling point corresponding to the first occurrence of the clarity corresponding to the fifth sampling point being greater than the clarity corresponding to the sixth sampling point be determined as the target focus, thereby avoiding the influence of the contingency and instability in the sampling process on the focusing result, improving the accuracy and stability of focusing, and improving the precision of focusing.

[0155] Please refer to the following Fig. 9 , which is a schematic diagram of the structure of a focusing device provided by an exemplary embodiment of the present application. Fig. 9 As shown, the focusing device 900 includes:

[0156] A first determination module 910 is used to determine at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from within the target focal length range according to a preset rule;

[0157] A first judging module 920 is used to judge whether the sharpness corresponding to the at least three initial sampling points is monotonic;

[0158] A second determination module 930 is configured to determine a corresponding target adjustment step length based on an initial sampling point having the largest corresponding clarity among the at least three initial sampling points when the clarity corresponding to the at least three initial sampling points is monotonic, and determine a target focus based on the target adjustment step length;

[0159] The third determination module 940 is used to determine a corresponding target focus fitting curve based on the at least three initial sampling points and the clarity corresponding to the at least three initial sampling points when the clarity corresponding to the at least three initial sampling points is not monotonic, and determine the target focus based on the target focus fitting curve.

[0160] In a possible implementation, the target adjustment step size includes a first target adjustment step size;

[0161] The second determining module 930 includes:

[0162] A first determining unit is configured to obtain a first sampling point by subtracting the first target adjustment step from an initial sampling point having the largest clarity among the at least three initial sampling points, and determine the clarity corresponding to the first sampling point, when the clarity corresponding to the at least three initial sampling points decreases monotonically;

[0163] A second determining unit, configured to obtain a second sampling point by subtracting the first target adjustment step from the first sampling point, and determine a definition corresponding to the second sampling point;

[0164] A third determining unit is configured to determine whether the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point, and to update the first sampling point to the second sampling point, and to perform again the steps of subtracting the first target adjustment step from the first sampling point to obtain the second sampling point, and to determine the clarity corresponding to the second sampling point, until the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point for a target number of consecutive times, and then determine the first sampling point corresponding to the first occurrence of the clarity corresponding to the first sampling point greater than the clarity corresponding to the second sampling point as the target focus.

[0165] In a possible implementation, the target adjustment step size includes a second target adjustment step size;

[0166] The second determining module 930 includes:

[0167] a fourth determining unit, configured to, when the sharpnesses corresponding to the at least three initial sampling points increase monotonically, add the second target adjustment step to an initial sampling point having the largest sharpness among the at least three initial sampling points to obtain a third sampling point, and determine the sharpness corresponding to the third sampling point;

[0168] a fifth determining unit, configured to add the second target adjustment step to the third sampling point to obtain a fourth sampling point, and determine a definition corresponding to the fourth sampling point;

[0169] a sixth determining unit, configured to determine whether the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point, and to update the third sampling point to the fourth sampling point, and to perform again the steps of adding the second target adjustment step to the third sampling point to obtain the fourth sampling point, and to determine the clarity corresponding to the fourth sampling point, until the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point for a target number of consecutive times, and then determine the third sampling point corresponding to the first occurrence of the clarity corresponding to the third sampling point greater than the clarity corresponding to the fourth sampling point as the target focus.

[0170] In a possible implementation, the focusing device 900 further includes:

[0171] A second judgment module is used to judge whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points is greater than a preset difference value;

[0172] The fourth determining unit is specifically used for:

[0173] If not, then the initial sampling point with the largest corresponding definition among the at least three initial sampling points is added with the second target adjustment step to obtain a third sampling point, and the definition corresponding to the third sampling point is determined.

[0174] In a possible implementation, the target adjustment step further includes a third target adjustment step; the third target adjustment step is greater than the second target adjustment step, and is less than or equal to a focal difference between the maximum focal point and an initial sampling point with the largest corresponding clarity among the at least three initial sampling points;

[0175] The focusing device 900 further includes:

[0176] a fourth determination module, configured to, if yes, add the third target adjustment step to the at least three initial sampling points to obtain corresponding at least three new sampling points, and determine the sharpness corresponding to the at least three new sampling points;

[0177] An updating module is used to update the at least three initial sampling points to the at least three new sampling points, and to perform again the step of determining whether the sharpness corresponding to the at least three initial sampling points is monotonic.

[0178] In a possible implementation, the number of the initial sampling points is at least 4; and the third determination module 940 includes:

[0179] A seventh determination unit is used to determine a target extreme value point corresponding to the target focus fitting curve; the target focus fitting curve is obtained by solving a quadratic equation group using a least squares method;

[0180] An eighth determination unit is used to determine a target focus based on the target extreme point.

[0181] In a possible implementation manner, the eighth determining unit is specifically configured to:

[0182] The target extreme point is subtracted from the preset step length to obtain a fifth sampling point; the fifth sampling point is added with the fourth target adjustment step length to obtain a sixth sampling point, and the clarity corresponding to the sixth sampling point is determined; it is determined whether the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point, and the fifth sampling point is updated to the sixth sampling point, and the steps of adding the fourth target adjustment step length to the fifth sampling point to obtain the sixth sampling point and determining the clarity corresponding to the sixth sampling point are performed again, until the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point for consecutive target times, the fifth sampling point corresponding to the first occurrence of the clarity corresponding to the fifth sampling point being greater than the clarity corresponding to the sixth sampling point is determined as the target focus.

[0183] The division of the modules in the above-mentioned focusing device is only for illustration. In other embodiments, the focusing device can be divided into different modules as needed to complete all or part of the functions of the above-mentioned focusing device. The implementation of each module in the focusing device provided in the embodiment of the present application can be in the form of a computer program. The computer program can be run on a camera, a terminal, or a server. The program modules constituted by the computer program can be stored in the memory of the camera, a terminal, or a server. When the computer program is executed by the processor, all or part of the steps of the focusing method described in the embodiment of the present application are implemented.

[0184] See next Fig.10 , which is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig.10 As shown, the electronic device 1000 includes: at least one processor 1010 , at least one communication bus 1020 , a user interface 1030 , at least one network interface 1040 , and a memory 1050 .

[0185] The communication bus 1020 may be used to realize the connection and communication among the above-mentioned components.

[0186] The user interface 1030 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 1030 may also include a standard wired interface and a wireless interface.

[0187] The network interface 1040 may include a Bluetooth module, a Near Field Communication (NFC) module, a Wireless Fidelity (Wi-Fi) module, and the like.

[0188] Among them, the processor 1010 may include one or more processing cores. The processor 1010 uses various interfaces and lines to connect various parts within the entire electronic device 1000, and executes various functions and processes data of the routing electronic device 1000 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1050, and calling data stored in the memory 1050. Optionally, the processor 1010 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1010 can integrate one or more combinations of a processor (Central Processing Unit, CPU), a graphics processor (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1010, and it can be implemented separately through a chip.

[0189] Among them, the memory 1050 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory, ROM). Optionally, the memory 1050 includes a non-transitory computer-readable medium. The memory 1050 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1050 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a determination function, a focus function, a judgment function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1050 may also be at least one storage device located away from the aforementioned processor 1010. As Fig.10 As shown, the memory 1050 as a computer storage medium may include an operating system, a network communication module, a user interface module, and program instructions.

[0190] Specifically, the processor 1010 may be used to call the program instructions stored in the memory 1050, and specifically perform the following operations:

[0191] At least three initial sampling points and the sharpness corresponding to the at least three initial sampling points are determined from within the target focal length range according to a preset rule.

[0192] Determine whether the clarity corresponding to the at least three initial sampling points is monotonic;

[0193] If yes, then the corresponding target adjustment step is determined based on the initial sampling point with the largest corresponding clarity among the at least three initial sampling points, and the target focus is determined based on the target adjustment step.

[0194] If not, a corresponding target focus fitting curve is determined based on the at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points, and the target focus is determined based on the target focus fitting curve.

[0195] In some possible embodiments, the target adjustment step size includes a first target adjustment step size;

[0196] When the processor 1010 performs the above-mentioned determination of the target focus based on the above-mentioned target adjustment step, it is specifically used to perform:

[0197] In the case where the clarity corresponding to the at least three initial sampling points decreases monotonically, the first sampling point is obtained by subtracting the first target adjustment step from the initial sampling point having the largest clarity among the at least three initial sampling points, and the clarity corresponding to the first sampling point is determined.

[0198] The first target adjustment step is subtracted from the first sampling point to obtain a second sampling point, and the definition corresponding to the second sampling point is determined.

[0199] It is determined whether the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point, and the first sampling point is updated to the second sampling point, and the steps of subtracting the first target adjustment step from the first sampling point to obtain the second sampling point and determining the clarity corresponding to the second sampling point are performed again, until the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point for consecutive target times, and the first sampling point corresponding to the first occurrence of the clarity corresponding to the first sampling point greater than the clarity corresponding to the second sampling point is determined as the target focus.

[0200] In some possible embodiments, the target adjustment step size includes a second target adjustment step size;

[0201] When the processor 1010 performs the above-mentioned determination of the target focus based on the above-mentioned target adjustment step, it is specifically used to perform:

[0202] In the case where the clarity corresponding to the at least three initial sampling points increases monotonically, the initial sampling point with the largest clarity among the at least three initial sampling points is added to the second target adjustment step to obtain a third sampling point, and the clarity corresponding to the third sampling point is determined.

[0203] The third sampling point is added to the second target adjustment step to obtain a fourth sampling point, and the definition corresponding to the fourth sampling point is determined.

[0204] It is determined whether the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point, and the third sampling point is updated to the fourth sampling point. The steps of adding the second target adjustment step to the third sampling point to obtain the fourth sampling point and determining the clarity corresponding to the fourth sampling point are performed again until the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point for consecutive target times. The third sampling point corresponding to the first occurrence of the clarity corresponding to the third sampling point being greater than the clarity corresponding to the fourth sampling point is determined as the target focus.

[0205] In some possible embodiments, before the processor 1010 performs the steps of adding the second target adjustment step to the initial sampling point having the largest definition among the at least three initial sampling points to obtain the third sampling point and determining the definition corresponding to the third sampling point, it is further configured to perform:

[0206] It is determined whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points is greater than a preset difference.

[0207] When the processor 1010 performs the steps of adding the initial sampling point having the largest definition among the at least three initial sampling points to the second target adjustment step to obtain the third sampling point, and determining the definition corresponding to the third sampling point, the processor 1010 is specifically configured to perform:

[0208] If not, then the initial sampling point with the largest corresponding definition among the at least three initial sampling points is added with the second target adjustment step to obtain a third sampling point, and the definition corresponding to the third sampling point is determined.

[0209] In some possible embodiments, the target adjustment step further includes a third target adjustment step; the third target adjustment step is greater than the second target adjustment step, and is less than or equal to the focal difference between the maximum focal point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points;

[0210] After executing the above determination of whether the focal length difference between the maximum focal length point and the initial sampling point with the maximum clarity among the at least three initial sampling points is greater than a preset difference value, the processor 1010 is further configured to execute:

[0211] If so, the third target adjustment step is added to the at least three initial sampling points to obtain corresponding at least three new sampling points, and the sharpness corresponding to the at least three new sampling points is determined.

[0212] The at least three initial sampling points are updated to the at least three new sampling points, and the step of determining whether the sharpness corresponding to the at least three initial sampling points is monotonic is performed again.

[0213] In some possible embodiments, the number of the initial sampling points is at least 4; when the processor 1010 performs the determination of the target focus based on the target focus fitting curve, it is specifically used to perform:

[0214] Determine the target extreme value point corresponding to the target focus fitting curve; the target focus fitting curve is obtained by solving a quadratic equation group using a least squares method based on at least 4 initial sampling points.

[0215] The target focus is determined based on the above target extreme point.

[0216] In some possible embodiments, when the processor 1010 performs the above-mentioned determination of the target focus based on the above-mentioned target extreme value point, it is specifically used to perform:

[0217] The fifth sampling point is obtained by subtracting the preset step size from the above target extreme value point.

[0218] The fifth sampling point is added to the fourth target adjustment step to obtain a sixth sampling point, and the definition corresponding to the sixth sampling point is determined.

[0219] It is determined whether the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point, and the fifth sampling point is updated to the sixth sampling point. The steps of adding the fourth target adjustment step to the fifth sampling point to obtain the sixth sampling point and determining the clarity corresponding to the sixth sampling point are performed again until the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point for consecutive target times. The fifth sampling point corresponding to the first occurrence of the clarity corresponding to the fifth sampling point being greater than the clarity corresponding to the sixth sampling point is determined as the target focus.

[0220] The embodiment of the present application also provides a computer storage medium, which stores instructions, and when the instructions are executed on a computer or a processor, the computer or the processor executes one or more steps in any of the above methods. If the components of the above focusing device are implemented in the form of software functional units and sold or used as independent products, they can be stored in the storage medium.

[0221] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, a computer, a server or a data center to another website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state drive (SSD)), etc.

[0222] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes. In the absence of conflict, the technical features in this embodiment and the implementation scheme can be combined arbitrarily.

[0223] The embodiments described above are merely preferred embodiments of the present application and are not intended to limit the scope of the present application. Without departing from the design spirit of the present application, various modifications and improvements made to the technical solutions of the present application by ordinary technicians in this field should fall within the protection scope determined by the claims of the present application.

Claims

1. A focusing method, characterized in that: The method comprises: Determine at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from within the target focal length range according to a preset rule; Determining whether the clarity corresponding to the at least three initial sampling points is monotonic; If yes, determining a corresponding target adjustment step length based on the initial sampling point with the largest corresponding clarity among the at least three initial sampling points, and determining a target focus based on the target adjustment step length; If not, a corresponding target focus fitting curve is determined based on the at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points, and the target focus is determined based on the target focus fitting curve.

2. The method according to claim 1, characterized in that The target adjustment step length includes a first target adjustment step length; The determining the target focus based on the target adjustment step size comprises: In a case where the clarity corresponding to the at least three initial sampling points decreases monotonically, subtracting the first target adjustment step from the initial sampling point having the largest clarity among the at least three initial sampling points to obtain a first sampling point, and determining the clarity corresponding to the first sampling point; subtracting the first target adjustment step from the first sampling point to obtain a second sampling point, and determining a definition corresponding to the second sampling point; It is determined whether the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point, and the first sampling point is updated to the second sampling point, and the steps of subtracting the first target adjustment step from the first sampling point to obtain the second sampling point and determining the clarity corresponding to the second sampling point are performed again, until the clarity corresponding to the first sampling point is greater than the clarity corresponding to the second sampling point for consecutive target times, and the first sampling point corresponding to the first occurrence of the clarity corresponding to the first sampling point greater than the clarity corresponding to the second sampling point is determined as the target focus.

3. The method according to claim 1, characterized in that The target adjustment step size includes a second target adjustment step size; The determining the target focus based on the target adjustment step size comprises: In a case where the clarity corresponding to the at least three initial sampling points increases monotonically, adding the second target adjustment step to the initial sampling point having the largest clarity among the at least three initial sampling points to obtain a third sampling point, and determining the clarity corresponding to the third sampling point; adding the second target adjustment step to the third sampling point to obtain a fourth sampling point, and determining the clarity corresponding to the fourth sampling point; It is determined whether the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point, and the third sampling point is updated to the fourth sampling point, and the steps of adding the second target adjustment step to the third sampling point to obtain the fourth sampling point and determining the clarity corresponding to the fourth sampling point are performed again, until the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point for consecutive target times, and the third sampling point corresponding to the first time the clarity corresponding to the third sampling point is greater than the clarity corresponding to the fourth sampling point is determined as the target focus.

4. The method according to claim 3, characterized in that Before obtaining a third sampling point by adding the second target adjustment step to the initial sampling point having the largest corresponding definition among the at least three initial sampling points and determining the definition corresponding to the third sampling point, the method further includes: Determine whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points is greater than a preset difference; The step of adding the second target adjustment step to the initial sampling point with the largest corresponding definition among the at least three initial sampling points to obtain a third sampling point, and determining the definition corresponding to the third sampling point, comprises: If not, then the initial sampling point with the largest corresponding definition among the at least three initial sampling points is added with the second target adjustment step to obtain a third sampling point, and the definition corresponding to the third sampling point is determined.

5. The method according to claim 4, characterized in that The target adjustment step also includes a third target adjustment step; the third target adjustment step is greater than the second target adjustment step, and is less than or equal to the focal difference between the maximum focal point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points; After determining whether the focal length difference between the maximum focal length point and the initial sampling point with the largest corresponding clarity among the at least three initial sampling points is greater than a preset difference value, the method further includes: If yes, then respectively adding the third target adjustment step to the at least three initial sampling points to obtain corresponding at least three new sampling points, and determining the sharpness corresponding to the at least three new sampling points; The at least three initial sampling points are updated to the at least three new sampling points, and the step of determining whether the sharpness corresponding to the at least three initial sampling points is monotonic is performed again.

6. The method according to claim 1, characterized in that The number of the initial sampling points is at least 4; and determining the target focus based on the target focus fitting curve comprises: Determining a target extreme value point corresponding to the target focus fitting curve; the target focus fitting curve is obtained by solving a quadratic equation group using a least squares method based on at least four of the initial sampling points; A target focus is determined based on the target extreme point.

7. The method according to claim 6, characterized in that The determining of the target focus based on the target extreme point comprises: Subtract a preset step size from the target extreme point to obtain a fifth sampling point; Adding a fourth target adjustment step to the fifth sampling point obtains a sixth sampling point, and determining a definition corresponding to the sixth sampling point; It is determined whether the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point, and the fifth sampling point is updated to the sixth sampling point, and the steps of adding the fourth target adjustment step to the fifth sampling point to obtain the sixth sampling point and determining the clarity corresponding to the sixth sampling point are performed again, until the clarity corresponding to the fifth sampling point is greater than the clarity corresponding to the sixth sampling point for consecutive target times, and the fifth sampling point corresponding to the first occurrence of the clarity corresponding to the fifth sampling point being greater than the clarity corresponding to the sixth sampling point is determined as the target focus.

8. A focusing device, characterized in that: The focusing device comprises: A first determination module, configured to determine at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from within a target focal length range according to a preset rule; A first judging module is used to judge whether the clarity corresponding to the at least three initial sampling points is monotonic; A second determination module is configured to determine a corresponding target adjustment step length based on an initial sampling point having the largest corresponding clarity among the at least three initial sampling points when the clarity corresponding to the at least three initial sampling points is monotonic, and determine a target focus based on the target adjustment step length; The third determination module is used to determine a corresponding target focus fitting curve based on the at least three initial sampling points and the clarity corresponding to the at least three initial sampling points when the clarity corresponding to the at least three initial sampling points is not monotonic, and determine the target focus based on the target focus fitting curve.

9. An electronic device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 7.

10. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, which are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Focusing device and method for adjusting laser focal length

    CN107009023A

  • Focusing curve establishing method and device

    CN111147732A

  • Focusing method, camera device, unmanned aerial vehicle and storage medium

    CN114845050A

  • Automatic focusing method, apparatus and device based on electron beam measurement device, and storage medium

    WO2023133729A1