Focusing method and device, electronic equipment and storage medium
By determining the sharpness monotonicity or fitting curve of the initial sampling point in the autofocus method, the target focus is quickly locked, solving the problem of slow focusing speed in traditional methods and achieving a highly efficient and accurate focusing process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU SHIYUAN ELECTRONICS CO LTD
- Filing Date
- 2023-08-16
- Publication Date
- 2026-04-28
AI Technical Summary
Traditional autofocus methods are slow, especially hill-climbing search and variable step size hill-climbing search methods, which are inefficient in finding the focus point.
By determining at least three initial sampling points within the target focal length range, it is determined whether the sharpness has monotonicity. If so, the target adjustment step size is determined based on the initial sampling point with the highest sharpness. If not, the target focus fitting curve is determined to quickly lock the target focus.
While ensuring focusing accuracy, it significantly improves focusing speed, reduces computational load, and increases focusing efficiency.
Smart Images

Figure CN119496979B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a focusing method, apparatus, electronic device and storage medium. Background Technology
[0002] Currently, traditional autofocus search methods often employ hill-climbing or variable-step hill-climbing methods to find the optimal focus position. An ideal focus evaluation function curve exhibits a parabolic shape, with its peak corresponding to the optimal imaging position, and the function monotonically decreasing as it moves away from the optimal point. Taking the variable-step hill-climbing algorithm as an example, at the start of focusing, a focus direction and a relatively large step size are set. The focus evaluation function value is calculated while acquiring images. When the evaluation value of the latest acquired image is lower than that of the previous image, the focus direction is changed. After surpassing the peak again, the step size is reduced, eventually finding the optimal lens position. This makes autofocus relatively slow in traditional focusing methods. Summary of the Invention
[0003] This application provides a focusing method, apparatus, electronic device, and storage medium that can determine a corresponding focusing strategy using a few sampling points and based on the monotonicity relationship of sharpness between these sampling points. This achieves both accurate focusing and rapid locking of the target focus position, thereby improving focusing speed. The technical solution is as follows:
[0004] In a first aspect, embodiments of this application provide a focusing method, the method comprising:
[0005] According to preset rules, at least three initial sampling points and the corresponding sharpness of the above three initial sampling points are determined from the target focal length range;
[0006] Determine whether the sharpness corresponding to the above at least 3 initial sampling points has monotonicity;
[0007] If so, the target adjustment step size is determined based on the initial sampling point with the highest sharpness among the above at least 3 initial sampling points, and the target focus is determined based on the above target adjustment step size;
[0008] If not, then the target focus fitting curve is determined based on the above at least 3 initial sampling points and the sharpness corresponding to the above at least 3 initial sampling points, and the target focus is determined based on the above target focus fitting curve.
[0009] In one possible implementation, the aforementioned target adjustment step size includes a first target adjustment step size;
[0010] The above-mentioned determination of the target focus based on the target adjustment step size includes:
[0011] When the sharpness corresponding to the above at least 3 initial sampling points decreases monotonically, the first sampling point is obtained by subtracting the first target adjustment step size from the initial sampling point with the highest sharpness among the above at least 3 initial sampling points, and the sharpness corresponding to the above first sampling point is determined.
[0012] The first sampling point is obtained by subtracting the first target adjustment step size from the first sampling point, and the sharpness corresponding to the second sampling point is determined.
[0013] Determine whether the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, update the first sampling point to the second sampling point, and repeat the steps of subtracting the first target adjustment step size from the first sampling point to obtain the second sampling point and determining the sharpness corresponding to the second sampling point, until there are consecutive target times when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point. Then, determine the first sampling point corresponding to the first occurrence when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point as the target focus.
[0014] In one possible implementation, the aforementioned target adjustment step size includes a second target adjustment step size;
[0015] The above-mentioned determination of the target focus based on the target adjustment step size includes:
[0016] When the sharpness of the above at least 3 initial sampling points increases monotonically, the third sampling point is obtained by adding the first initial sampling point with the highest sharpness among the above at least 3 initial sampling points to the second target adjustment step size, and the sharpness corresponding to the third sampling point is determined.
[0017] The third sampling point is added to the second target adjustment step size to obtain the fourth sampling point, and the sharpness corresponding to the fourth sampling point is determined.
[0018] Determine whether the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point, update the third sampling point to the fourth sampling point, and repeat the steps of adding the third sampling point to the second target adjustment step to obtain the fourth sampling point and determining the sharpness corresponding to the fourth sampling point, until there are consecutive target times when the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point. Then, determine the third sampling point corresponding to the first occurrence when the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point as the target focus.
[0019] In one possible implementation, before adding the initial sampling point with the highest sharpness among the at least three initial sampling points to the second target adjustment step size to obtain the third sampling point, and before determining the sharpness 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 highest corresponding sharpness among the above at least 3 initial sampling points is greater than a preset difference value;
[0021] The above-mentioned method of adding the initial sampling point with the highest corresponding sharpness among the above-mentioned at least three initial sampling points to the above-mentioned second target adjustment step size to obtain the third sampling point, and determining the sharpness corresponding to the above-mentioned third sampling point, includes:
[0022] If not, the third sampling point is obtained by adding the first sampling point with the highest sharpness among the above at least 3 initial sampling points, and the sharpness corresponding to the third sampling point is determined.
[0023] In one possible implementation, the target adjustment step size further includes a third target adjustment step size; the third target adjustment step size is greater than the second target adjustment step size, and less than or equal to the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness 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 highest corresponding sharpness among the at least three initial sampling points is greater than a preset difference, the above method further includes:
[0025] If so, the above-mentioned at least 3 initial sampling points are respectively added to the above-mentioned third target adjustment step size to obtain at least 3 new sampling points, and the sharpness corresponding to the above-mentioned at least 3 new sampling points is determined;
[0026] Update the above at least 3 initial sampling points to the above at least 3 new sampling points, and perform the above step of determining whether the sharpness corresponding to the above at least 3 initial sampling points has monotonicity again.
[0027] In one possible implementation, the number of initial sampling points is at least four; the determination of the target focus based on the target focus fitting curve includes:
[0028] The target extreme point corresponding to the above target focus fitting curve is determined; the above target focus fitting curve is obtained by solving the quadratic equation system using the least squares method based on at least 4 initial sampling points;
[0029] The target focus is determined based on the aforementioned target extreme points.
[0030] In one possible implementation, determining the target focus based on the aforementioned target extreme point includes:
[0031] Subtract the preset step size from the above target extreme point to obtain the fifth sampling point;
[0032] The sixth sampling point is obtained by adding the fourth target adjustment step size to the fifth sampling point, and the sharpness corresponding to the sixth sampling point is determined.
[0033] Determine whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point, update the fifth sampling point to the sixth sampling point, and repeat the steps of adding the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point and determining the sharpness corresponding to the sixth sampling point, until a consecutive target number of times the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point occurs. Then, determine the fifth sampling point corresponding to the first occurrence of whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point as the target focus.
[0034] Secondly, embodiments of this application provide a focusing device, which includes:
[0035] The first determining module is used to determine at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from the target focal length range according to preset rules;
[0036] The first judgment module is used to determine whether the sharpness corresponding to the above at least 3 initial sampling points has monotonicity;
[0037] The second determining module is used to determine the corresponding target adjustment step size based on the initial sampling point with the largest corresponding sharpness among the above at least 3 initial sampling points when the sharpness corresponding to the above at least 3 initial sampling points is monotonic, and to determine the target focus based on the target adjustment step size.
[0038] The third determining module is used to determine the corresponding target focus fitting curve based on the at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points when the sharpness corresponding to the at least three initial sampling points does not have monotonicity, and to determine the target focus based on the target focus fitting curve.
[0039] In one possible implementation, the aforementioned target adjustment step size includes a first target adjustment step size;
[0040] The second determining module mentioned above includes:
[0041] The first determining unit is used to obtain a first sampling point by subtracting the first target adjustment step size from the initial sampling point with the highest corresponding sharpness among the at least three initial sampling points when the sharpness corresponding to the at least three initial sampling points decreases monotonically, and to determine the sharpness corresponding to the first sampling point.
[0042] The second determining unit is used to subtract the first target adjustment step size from the first sampling point to obtain the second sampling point, and to determine the sharpness corresponding to the second sampling point.
[0043] The third determining unit is used to determine whether the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, update the first sampling point to the second sampling point, and execute again the steps of subtracting the first target adjustment step size from the first sampling point to obtain the second sampling point and determining the sharpness corresponding to the second sampling point, until there are consecutive target times when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, and then the first sampling point corresponding to the first occurrence when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point is determined as the target focus.
[0044] In one possible implementation, the aforementioned target adjustment step size includes a second target adjustment step size;
[0045] The second determining module mentioned above includes:
[0046] The fourth determining unit is used to, when the sharpness corresponding to the above at least 3 initial sampling points increases monotonically, add the above second target adjustment step size to the initial sampling point with the largest sharpness among the above at least 3 initial sampling points to obtain the third sampling point, and determine the sharpness corresponding to the above third sampling point.
[0047] The fifth determining unit is used to add the third sampling point to the second target adjustment step size to obtain the fourth sampling point, and to determine the sharpness corresponding to the fourth sampling point.
[0048] The sixth determining unit is used to determine whether the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point, update the third sampling point to the fourth sampling point, and execute again the steps of adding the third sampling point to the second target adjustment step size to obtain the fourth sampling point and determining the sharpness corresponding to the fourth sampling point, until the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point for a consecutive target number of times, and then determine the third sampling point corresponding to the first occurrence of the sharpness corresponding to the third sampling point being greater than the sharpness corresponding to the fourth sampling point as the target focus.
[0049] In one possible implementation, the focusing device further includes:
[0050] The second judgment module is used to determine whether the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the above at least 3 initial sampling points is greater than a preset difference value.
[0051] The fourth determining unit mentioned above is specifically used for:
[0052] If not, the third sampling point is obtained by adding the first sampling point with the highest sharpness among the above at least 3 initial sampling points, and the sharpness corresponding to the third sampling point is determined.
[0053] In one possible implementation, the target adjustment step size further includes a third target adjustment step size; the third target adjustment step size is greater than the second target adjustment step size, and less than or equal to the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the at least three initial sampling points.
[0054] The aforementioned focusing device also includes:
[0055] The fourth determining module is used to, if so, add the third target adjustment step size to the above-mentioned at least 3 initial sampling points to obtain at least 3 corresponding new sampling points, and to determine the sharpness corresponding to the above-mentioned at least 3 new sampling points;
[0056] The update module is used to update the above-mentioned at least 3 initial sampling points to the above-mentioned at least 3 new sampling points, and to perform the above-mentioned step of determining whether the sharpness corresponding to the above-mentioned at least 3 initial sampling points has monotonicity again.
[0057] In one possible implementation, the number of initial sampling points is at least four; the third determining module includes:
[0058] The seventh determining unit is used to determine the target extreme point corresponding to the above target focus fitting curve; the above target focus fitting curve is obtained by solving a system of quadratic equations using the least squares method based on at least 4 of the above initial sampling points;
[0059] The eighth determining unit is used to determine the target focus based on the aforementioned target extreme points.
[0060] In one possible implementation, the eighth determining unit is specifically used for:
[0061] Subtract a preset step size from the target extreme point to obtain the fifth sampling point; add the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point, and determine the sharpness corresponding to the sixth sampling point; determine whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point, and update the fifth sampling point to the sixth sampling point, and repeat the steps of adding the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point and determining the sharpness corresponding to the sixth sampling point, until a consecutive target number of times the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point occurs, and the fifth sampling point corresponding to the first occurrence of whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point is determined as the target focus.
[0062] Thirdly, embodiments of this application provide an electronic device, including: a processor and a memory; wherein the memory stores a computer program, the computer program being adapted to be loaded by the processor and executed by the processor to perform the method steps provided by the first aspect of the embodiments of this application or any possible implementation thereof.
[0063] Fourthly, embodiments of this application provide a computer storage medium storing a plurality of instructions, which are adapted to be loaded by a processor and executed by the method steps provided in the first aspect of the embodiments of this application or any possible implementation thereof.
[0064] The beneficial effects of the technical solutions provided in some embodiments of this application include at least the following:
[0065] In one or more embodiments of this application, at least three initial sampling points and the corresponding sharpness of the at least three initial sampling points are determined from the target focal length range according to preset rules, and it is determined whether the sharpness corresponding to the at least three initial sampling points has monotonicity; if so, the corresponding target adjustment step size is determined based on the initial sampling point with the largest corresponding sharpness among the at least three initial sampling points, and the target focus is determined based on the target adjustment step size; if not, the 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. In this way, the corresponding focusing strategy can be determined by using a few sampling points and according to the monotonicity relationship of the sharpness between each sampling point, so as to ensure accurate focusing while quickly locking the target focus position and improving focusing speed.
[0066] The above description is merely an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0067] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0068] Figure 1 A schematic diagram of the structure of the execution body of a focusing method provided in an exemplary embodiment of this application;
[0069] Figure 2 A schematic diagram illustrating the relationship between motor position and corresponding focal length image sharpness, provided as an exemplary embodiment of this application;
[0070] Figure 3 A flowchart illustrating a focusing method provided for an exemplary embodiment of this application;
[0071] Figure 4 A schematic diagram illustrating an implementation process for determining a target focus, provided as an exemplary embodiment of this application;
[0072] Figure 5 A schematic diagram illustrating another implementation process for determining the target focus, provided as an exemplary embodiment of this application;
[0073] Figure 6 A schematic diagram illustrating another implementation process for determining the target focus, provided as an exemplary embodiment of this application;
[0074] Figure 7 A schematic diagram illustrating another implementation process for determining the target focus, provided as an exemplary embodiment of this application;
[0075] Figure 8 A schematic diagram illustrating another implementation process for determining the target focus, provided as an exemplary embodiment of this application;
[0076] Figure 9 A schematic diagram of a focusing device provided for an exemplary embodiment of this application;
[0077] Figure 10 This is a schematic diagram of the structure of an electronic device provided as an exemplary embodiment of this application. Detailed Implementation
[0078] To make the features and advantages of this application more apparent and understandable, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0079] The terms "first," "second," "third," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0080] Please refer to the following. Figure 1 This is a schematic diagram of the structure of the execution body of a focusing method provided in an exemplary embodiment of this application. Figure 1 As shown, this focusing method can be, but is not limited to, executed on a camera. The camera includes a motor 110, and its focusing principle involves setting the motor position to obtain the sharpness of the image at the current focal length. If the current sharpness is greater than a certain threshold, focusing is triggered. The focusing process involves zooming in and out with the camera, obtaining a series of values (sharpness), and then finding the maximum value from these data. The motor position corresponding to the maximum value is the current focus point. Due to the image imaging principle, for example... Figure 2 As shown, the relationship between the motor position (focus) and the image sharpness at the corresponding focal length (focus curve) always exhibits a parabolic or normal distribution. Therefore, during a complete focusing process, the motor 110 will run through the entire range. For example, if the motor position (corresponding focal length) needs to be adjusted from large to small or from small to large, the image at the corresponding focal length will also change from "blurred" to "sharp" and then back to "blurred," thus finding the motor position (focus) corresponding to the maximum sharpness.
[0081] It is understood that the focusing method provided in the embodiments of this application can be executed by a camera device including a motor, or by other devices connected to the aforementioned camera device, and the embodiments of this application do not limit this.
[0082] Next, combine Figure 1 and Figure 2 This document describes the focusing method provided in the embodiments of this application. Please refer to [reference needed] for details. Figure 3 This is a flowchart illustrating a focusing method provided in an exemplary embodiment of this application. Figure 3 As shown, this focusing method includes the following steps:
[0083] S301, determine at least 3 initial sampling points and the sharpness corresponding to at least 3 initial sampling points from the target focal length range according to preset rules.
[0084] Specifically, the aforementioned initial sampling points are the initial sampling positions of the camera motor, corresponding to the initial focal length of the camera. These at least three initial sampling points can be obtained by gradually increasing the minimum focal length of the camera by a certain step size, or by gradually subtracting the maximum focal length of the camera by a certain step size, or simply set according to the actual situation of the camera and user experience. The focal length distance between two adjacent initial sampling points among the aforementioned at least three initial sampling points can be equal or unequal; this embodiment does not limit this. After determining the initial sampling points of the camera motor, an initial sampling image can be captured based on these initial sampling points, and the sharpness corresponding to these initial sampling points can be calculated based on the initial sampling image.
[0085] For example, when the camera is powered on or receives a focus command triggered by the user, the first initial sampling point x1 can be obtained by adding K1 to the minimum focal length point; the second initial sampling point x2 can be obtained by adding K2 to the first initial sampling point; the third initial sampling point x3 can be obtained by adding K3 to the second initial sampling point; and the fourth initial sampling point x4 can be obtained by adding K4 to the third initial sampling point. The corresponding sharpness y1, y2, y3, and y4 are then obtained from these initial sampling images. K1, K2, K3, and K4 are all constants and can be partially or completely the same, or all different. The specific settings can be determined according to the actual situation, and this embodiment does not limit this.
[0086] Understandably, in order to ensure the effectiveness of the initial sampling points, the target focal length range can be the actual adjustable focal length range of the camera; in order to further ensure focusing efficiency and avoid the problem that the focal length distance between the initial sampling points is too large, which would make the focusing process more complicated and affect the focusing efficiency, the target focal length range can be any focal length range within the actual adjustable focal length range of the camera where the length between the left and right focal lengths is less than the target length.
[0087] Understandably, the aforementioned at least three initial sampling points can include, but are not limited to, three, four, or five initial sampling points. To a certain extent, the fewer the number of initial sampling points, the less computation is involved in the focusing process, and the higher the focusing efficiency; conversely, the more initial sampling points, the greater the precision of the focus, 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 will change only slightly, but the focusing efficiency will decrease significantly.
[0088] S302, determine whether the sharpness corresponding to at least 3 initial sampling points has monotonicity.
[0089] Specifically, after determining at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points, it is possible to determine whether the sharpness corresponding to the at least three initial sampling points has monotonicity, and then determine the corresponding target focusing strategy based on the monotonicity of the sharpness corresponding to the at least three initial sampling points.
[0090] S303, if so, then determine the corresponding target adjustment step size based on the initial sampling point with the highest sharpness among at least 3 initial sampling points, and determine the target focus based on the target adjustment step size.
[0091] Specifically, the target focal point is the motor position (focal point) with the highest sharpness within the focal length range corresponding to the camera. Given that the sharpness corresponding to at least three initial sampling points exhibits monotonicity, since all three initial sampling points are within the target focal length range (i.e., the initial sampling points are close together), it can be assumed that these three initial sampling points are located on the same side of the focal point corresponding to the camera's maximum sharpness, for example, but not limited to, all located on... Figure 2 The rising or falling edge of the curve shown can be used to determine the target adjustment step size based on the initial sampling point with the highest sharpness among at least three initial sampling points. Thus, when the sharpness corresponding to at least three initial sampling points is monotonic, focusing can be achieved by adjusting the step size of the initial sampling point with the highest sharpness among at least three initial sampling points. This reduces the amount of calculation in the focusing process, improves focusing efficiency, and ensures focusing accuracy.
[0092] S304, if not, then determine the corresponding target focus fitting curve based on at least 3 initial sampling points and the sharpness corresponding to at least 3 initial sampling points, and determine the target focus based on the target focus fitting curve.
[0093] Specifically, if the sharpness corresponding to at least three initial sampling points is not monotonic, then these at least three initial sampling points can be considered to be located on either side of the focal point corresponding to the camera's maximum sharpness, for example, but not limited to, located on... Figure 2 The rising and falling edges of the curve shown can be used to determine the corresponding target focus fitting curve based on at least 3 initial sampling points and the sharpness corresponding to at least 3 initial sampling points. Thus, when the sharpness corresponding to 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 focusing efficiency.
[0094] Understandably, when the sharpness corresponding to at least three initial sampling points is monotonic, for focusing methods that determine the target focus fitting curve based on at least three initial sampling points and their corresponding sharpness, adjusting the step size of the initial sampling point with the highest sharpness among the at least three initial sampling points yields higher accuracy and better focusing results. Even when the sharpness corresponding to at least three initial sampling points is not monotonic, focusing can still be achieved, but not limited to, by adjusting the step size of the initial sampling point with the highest sharpness among the at least three initial sampling points. However, since it cannot be determined whether the initial sampling point with the highest sharpness is located on the rising or falling edge of the focus curve, it requires left or right adjustment. Compared to directly fitting the focus curve, this adjustment process is longer and the focusing efficiency is lower.
[0095] In this embodiment, at least three initial sampling points and the corresponding sharpness of the at least three initial sampling points can be determined from the target focal length range according to preset rules. Based on the monotonicity relationship between the sharpness of 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 size or target focus fitting curve). Thus, it is possible to determine the corresponding focusing strategy through a few sampling points and according to the monotonicity relationship between the corresponding sharpness of each sampling point, so as to ensure accurate focusing while quickly locking the target focus position and improving focusing speed.
[0096] Optionally, if the sharpness corresponding to at least three initial sampling points is monotonic, the above target adjustment step size includes a first target adjustment step size. For example... Figure 4 As shown, in S303 above, the implementation process of determining the target focus based on the target adjustment step size may include:
[0097] S401, when the sharpness corresponding to at least 3 initial sampling points decreases monotonically, subtract the first target adjustment step size from the initial sampling point with the highest sharpness among the at least 3 initial sampling points to obtain the first sampling point, and determine the sharpness corresponding to the first sampling point.
[0098] Specifically, if the sharpness of at least three initial sampling points monotonically decreases, it can be assumed that all three initial sampling points are located to the right of the focal point corresponding to the camera's maximum sharpness, i.e., they are all located on the descending edge of the focus curve. Therefore, the initial sampling point with the highest sharpness among the at least three initial sampling points needs to be subtracted by the first target adjustment step size. This involves shifting the initial sampling point with the highest sharpness to the left, bringing it closer to the focal point corresponding to the camera's maximum sharpness, thus obtaining the first sampling point. Then, sampling is performed based on this first sampling point; that is, the motor is positioned at the first sampling point to capture the first sampled image, and the sharpness corresponding to the first sampling point is calculated.
[0099] S402, subtract the first target adjustment step size from the first sampling point to obtain the second sampling point, and determine the sharpness corresponding to the second sampling point.
[0100] Specifically, the implementation process of S402 is similar to the implementation process of S401 above, which involves subtracting the first target adjustment step size from the initial sampling point with the highest sharpness among at least three initial sampling points to obtain the first sampling point, and determining the sharpness corresponding to the first sampling point. It will not be described again here.
[0101] S403, determine whether the resolution corresponding to the first sampling point is greater than the resolution corresponding to the second sampling point, and update the first sampling point to the second sampling point.
[0102] Specifically, after determining the first sampling point located to the left of the initial sampling point with the highest corresponding sharpness among at least three initial sampling points, and the second sampling point located to the left of the first sampling point, it can be determined whether the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, and the number of times this is done can be counted. If yes, it means that the second sampling point may have already crossed the focus corresponding to the camera's maximum sharpness and is located to its left; if no, it means that the second sampling point may not have crossed the focus corresponding to the camera's maximum sharpness and is still located to its right.
[0103] S404, determine whether there is a situation where the sharpness of the first sampling point of a consecutive target is greater than the sharpness of the second sampling point.
[0104] Specifically, the aforementioned target number can be, but is not limited to, 2 times, 3 times, etc.
[0105] S405, if so, the first sampling point corresponding to the first sampling point when the sharpness is greater than that of the second sampling point is determined as the target focus.
[0106] Specifically, to avoid the possibility that the sharpness of the first sampling point is greater than that of the second sampling point due to randomness and instability during the sampling process, and thus mistakenly believing that the second sampling point has passed the focus corresponding to the maximum sharpness of the camera and is located to its left, after updating the first sampling point to the second sampling point, if there is no consecutive target-level occurrence of the first sampling point having a sharpness greater than that of the second sampling point, the above-mentioned S402 can be executed again to obtain the second sampling point by subtracting the first target adjustment step from the first sampling point, and to determine the sharpness corresponding to the second sampling point. This process continues until there is a consecutive target-level occurrence of the first sampling point having a sharpness greater than that of the second sampling point. Only then will the first sampling point corresponding to the first occurrence of the first sampling point having a sharpness greater than that of the second sampling point be determined as the target focus, thereby avoiding the influence of randomness and instability during the sampling process on the focusing result and improving the accuracy and stability of focusing.
[0107] Optionally, if the sharpness corresponding to at least three initial sampling points is monotonic, the above-mentioned target adjustment step size includes a second target adjustment step size. This second target adjustment step size may be the same as or different from the first target adjustment step size; the embodiments of this application do not limit this. Figure 5 As shown, in S303 above, the implementation process of determining the target focus based on the target adjustment step size may include:
[0108] S501, when the sharpness corresponding to at least 3 initial sampling points increases monotonically, add the second target adjustment step size to the initial sampling point with the largest sharpness among the at least 3 initial sampling points to obtain the third sampling point, and determine the sharpness corresponding to the third sampling point.
[0109] Specifically, if the sharpness of at least three initial sampling points monotonically increases, it can be assumed that all three initial sampling points are located to the left of the focal point corresponding to the camera's maximum sharpness, i.e., they are all located on the rising edge of the focus curve. Therefore, a second target adjustment step needs to be added to the initial sampling point with the highest sharpness among the at least three initial sampling points. This means shifting the initial sampling point with the highest sharpness to the right, bringing it closer to the focal point corresponding to the camera's maximum sharpness, to obtain the third sampling point. Then, sampling is performed based on this third sampling point; that is, the motor is positioned at the third sampling point to capture a third sampled image, and the sharpness corresponding to this third sampling point is calculated.
[0110] S502, add the second target adjustment step size to the third sampling point to obtain the fourth sampling point, and determine the sharpness corresponding to the fourth sampling point.
[0111] Specifically, the implementation process of S502 is similar to the implementation process of S501 above, which involves adding the first sample point with the highest sharpness among at least three initial sample points to obtain the third sample point and determining the sharpness corresponding to the third sample point. It will not be described in detail here.
[0112] S503, determine whether the sharpness corresponding to the third sampling point is greater than the sharpness 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 to the right of the initial sampling point with the highest corresponding sharpness among at least three initial sampling points, and the fourth sampling point located to the right of the third sampling point, it can be determined whether the sharpness corresponding to the third sampling point is greater than that corresponding to the fourth sampling point, and the number of times this is done can be counted. If yes, it means that the fourth sampling point may have already crossed the focus corresponding to the camera's maximum sharpness and is located to its right; if no, it means that the fourth sampling point may not have crossed the focus corresponding to the camera's maximum sharpness and is still located to its left.
[0114] S504, determine whether there is a situation where the sharpness of the third sampling point of a consecutive target is greater than the sharpness of the fourth sampling point.
[0115] Specifically, the aforementioned target number can be, but is not limited to, 2 times, 3 times, etc.
[0116] S505, if so, the third sampling point corresponding to the first occurrence where the sharpness of the third sampling point is greater than that of the fourth sampling point is determined as the target focus.
[0117] Specifically, to avoid the possibility that the sharpness of the third sampling point is greater than that of the fourth sampling point due to randomness and instability during the sampling process, and thus mistakenly believing that the fourth sampling point has passed the focus corresponding to the maximum sharpness of the camera and is located to its right, after updating the third sampling point to the fourth sampling point, if there is no consecutive occurrence of the sharpness of the target's second third sampling point being greater than that of the fourth sampling point, the above S502 can be executed again to obtain the fourth sampling point by adding the second target adjustment step size to the third sampling point, and to determine the sharpness corresponding to the fourth sampling point. This process continues until there is a consecutive occurrence of the sharpness of the target's second third sampling point being greater than that of the fourth sampling point. Only then will the third sampling point corresponding to the first occurrence of the sharpness of the third sampling point being greater than that of the fourth sampling point be determined as the target focus, thereby avoiding the influence of randomness and instability during the sampling process on the focusing result and improving the accuracy and stability of focusing.
[0118] Optionally, when the sharpness corresponding to at least three initial sampling points is monotonic, the target adjustment step size may include a second target adjustment step size and a third target adjustment step size. The second target adjustment step size may be the same as or different from the first target adjustment step size, and this embodiment does not limit this. The second target adjustment step size may be, but is not limited to, 1, 0.5, etc., and may be, but is not limited to, 2, 4, etc. The third target adjustment step size is greater than the second target adjustment step size and less than or equal to the focal length difference between the camera's maximum focal length point and the initial sampling point with the highest sharpness among the at least three initial sampling points. Figure 6 As shown, in S303 above, the implementation process of determining the target focus based on the target adjustment step size may include:
[0119] S601, under the condition that the sharpness corresponding to at least 3 initial sampling points increases monotonically, determine whether the focal length difference between the maximum focal length point and the initial sampling point with the highest sharpness among the at least 3 initial sampling points is greater than a preset difference value.
[0120] Specifically, if the sharpness of at least three initial sampling points increases monotonically, it can be assumed that all three initial sampling points are located to the left of the focal point corresponding to the maximum sharpness of the camera, i.e., 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 the excessively large distance between the initial sampling point with the highest sharpness among the at least three initial sampling points and the focal point corresponding to the maximum sharpness of the camera and the excessively small adjustment step, it can be determined first whether the focal length difference between the maximum focal length point of the camera and the initial sampling point with the highest sharpness among the at least three initial sampling points is greater than the preset difference value. If yes, it means that the distance between the initial sampling point with the highest corresponding sharpness and the focus corresponding to the camera's maximum sharpness may be relatively far, and the initial sampling point with the highest corresponding sharpness still has a lot of adjustment space. In this case, it can be adjusted by a larger third target adjustment step, i.e., executing S607 below, thereby improving the focusing speed. If no, it means that the distance between the initial sampling point with the highest corresponding sharpness and the focus corresponding to the camera's maximum sharpness may be relatively close, and the initial sampling point with the highest corresponding sharpness has a small adjustment space. In this case, it only needs to be adjusted by a smaller second target adjustment step, i.e., executing S602 below, which can ensure both focusing speed and focusing accuracy.
[0121] S602, if not, then add the third sampling point with the highest corresponding sharpness among the at least 3 initial sampling points to the second target adjustment step size to obtain the third sampling point, and determine the sharpness 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 size to the third sampling point to obtain the fourth sampling point, and determine the sharpness corresponding to the fourth sampling point.
[0124] Specifically, S603 is the same as S502, and will not be repeated here.
[0125] S604, determine whether the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point, and update the third sampling point to the fourth sampling point.
[0126] Specifically, S604 is the same as S503, and will not be repeated here.
[0127] S605, determine whether there is a situation where the sharpness of the third sampling point of a consecutive target is greater than the sharpness of the fourth sampling point.
[0128] Specifically, S605 is the same as S504, and will not be repeated here.
[0129] S606, if so, the third sampling point corresponding to the first occurrence where the sharpness of the third sampling point is greater than that of the fourth sampling point is determined as the target focus.
[0130] Specifically, S606 is the same as S505, which will not be repeated here.
[0131] Please continue to refer to the following. Figure 6 ,like Figure 6 As shown in S601, when the sharpness corresponding to at least 3 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 highest sharpness among the at least 3 initial sampling points is greater than a preset difference, the focusing method further includes:
[0132] S607, if so, then add the third target adjustment step size to each of the at least 3 initial sampling points to obtain at least 3 new sampling points, and determine the sharpness corresponding to the at least 3 new sampling points.
[0133] Specifically, if the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the at least 3 initial sampling points is greater than a preset difference, it means that the distance between the initial sampling point with the highest corresponding sharpness and the focal point corresponding to the camera's maximum sharpness may be far, and the initial sampling point with the highest corresponding sharpness still has a lot of adjustment space. In order to improve the focusing speed, a larger third target adjustment step size can be used to resample based on the above at least 3 initial sampling points, that is, to move all the above at least 3 initial sampling points to the right by the third target adjustment step size to obtain the corresponding at least 3 new sampling points.
[0134] S608 updates at least 3 initial sampling points to at least 3 new sampling points.
[0135] Specifically, after obtaining the corresponding at least three new sampling points, it is also necessary to update the at least three initial sampling points to the at least three new sampling points as described above and execute the above S302 again, and determine whether the sharpness corresponding to the at least three initial sampling points has monotonicity, so as to quickly and accurately complete the focusing.
[0136] Optionally, in the case where the sharpness corresponding to the at least three initial sampling points does not have monotonicity, such as Figure 7 shown, in the above S304, the implementation process of determining the target focus based on the target focus fitting curve may include:
[0137] S701, determine the target extreme point corresponding to the target focus fitting curve, and the target focus fitting curve is obtained by solving a quadratic equation system using the least squares method based on at least four initial sampling points.
[0138] Specifically, in order to ensure the accuracy of the target focus fitting curve and avoid the problem that the focusing accuracy is affected by incorrect sampling of a certain initial sampling point, the target focus 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 four initial sampling points and the sharpness corresponding to each of the at least four initial sampling points.
[0139] Exemplarily, if four initial sampling points x1, x2, x3, x4 are determined, and x1 < x2 < x3 < x4, and their corresponding sharpness are y1, y2, y3, y4 respectively. If when y1 < y2 <y3>y4 or y1 <y2>If y3 > y4, then we get four points: (x1, y1), (x2, y2), (x3, y3), and (x4, y4). We can fit these points using a system of quadratic equations to obtain the following system of equations:
[0140]
[0141] Then, the above system of equations is solved using the least squares method to obtain the three constant parameters a, b, and c. The corresponding extreme points of the target are then determined using the resulting fitting equation system (target focusing fitting curve).
[0142] Understandably, the target focus fitting curve mentioned above can also be obtained by directly solving the quadratic equation system based on 3 initial sampling points. The target focus fitting curve obtained by solving the quadratic equation system using the least squares method based on at least 4 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 system based on only 3 initial sampling points.
[0143] S702, determine the target focus based on the target extreme point.
[0144] Optionally, after determining the target extreme point corresponding to the target focus fitting curve, the target extreme point can be directly determined as the target focus of the camera, but is not limited to this.
[0145] Optionally, to further improve focusing accuracy and reduce the error between the target's extreme point and the focus corresponding to the camera's actual maximum sharpness, such as... Figure 8 As shown, the implementation process of S702 above, which determines the target focus based on the target extreme point, may include:
[0146] S801, subtract the preset step size from the target extreme point to obtain the fifth sampling point.
[0147] Specifically, the preset step size can be preset according to the focusing accuracy required by the user, and this application embodiment does not limit this.
[0148] S802, add the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point, and determine the sharpness corresponding to the sixth sampling point.
[0149] Specifically, the adjustment step size for the fourth target is greater than 0 and less than the difference between the fifth sampling point and the camera's maximum focal length. To a certain extent, the smaller the adjustment step size for the fourth target, the higher the corresponding focusing accuracy.
[0150] S803, determine whether the resolution corresponding to the fifth sampling point is greater than the resolution corresponding to the sixth sampling point, and update the fifth sampling point to the sixth sampling point.
[0151] Specifically, it can be determined whether the sharpness corresponding to the fifth sampling point located to the left of the target extreme point is greater than the sharpness corresponding to the sixth sampling point located to the right of the fifth sampling point, and the number of times this occurs can be counted. If yes, it means that the sixth sampling point may have already crossed the focus corresponding to the maximum sharpness of the camera and is located to its right; if no, it means that the sixth sampling point may not have crossed the focus corresponding to the maximum sharpness of the camera and is still located to its left.
[0152] S804, determine whether there is a situation where the sharpness corresponding to the fifth sampling point of a consecutive target is greater than the sharpness corresponding to the sixth sampling point.
[0153] S805, if so, determine the fifth sampling point as the target focus when the sharpness of the fifth sampling point is greater than that of the sixth sampling point for the first time.
[0154] Specifically, to avoid the possibility that the sharpness of the fifth sampling point is greater than that of the sixth sampling point due to randomness and instability during the sampling process, and thus mistakenly believing that the sixth sampling point has passed the focus corresponding to the maximum sharpness of the camera and is located to its right, S802 can be executed again if there is no consecutive target sub-sharpness of the fifth sampling point being greater than that of the sixth sampling point. This involves adding the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point, and determining the sharpness of the sixth sampling point. This process continues until there is a consecutive target sub-sharpness of the fifth sampling point being greater than that of the sixth sampling point. Only then will the fifth sampling point corresponding to the first occurrence of the fifth sampling point being greater than that of the sixth sampling point be determined as the target focus. This avoids the impact of randomness and instability during the sampling process on the focusing results, improving both the accuracy and stability of focusing, and also improving the precision of focusing.
[0155] Please refer to the following. Figure 9 This is a schematic diagram of a focusing device provided in an exemplary embodiment of this application. Figure 9 As shown, the focusing device 900 includes:
[0156] The first determining 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 the target focal length range according to preset rules.
[0157] The first judgment module 920 is used to determine whether the sharpness corresponding to the above at least 3 initial sampling points has monotonicity;
[0158] The second determining module 930 is used to determine the corresponding target adjustment step size based on the initial sampling point with the largest corresponding sharpness among the above at least 3 initial sampling points when the sharpness corresponding to the above at least 3 initial sampling points is monotonic, and to determine the target focus based on the target adjustment step size.
[0159] The third determining module 940 is used to determine the corresponding target focus fitting curve based on the at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points when the sharpness corresponding to the at least three initial sampling points does not have monotonicity, and to determine the target focus based on the target focus fitting curve.
[0160] In one possible implementation, the aforementioned target adjustment step size includes a first target adjustment step size;
[0161] The second determining module 930 mentioned above includes:
[0162] The first determining unit is used to obtain a first sampling point by subtracting the first target adjustment step size from the initial sampling point with the highest corresponding sharpness among the at least three initial sampling points when the sharpness corresponding to the at least three initial sampling points decreases monotonically, and to determine the sharpness corresponding to the first sampling point.
[0163] The second determining unit is used to subtract the first target adjustment step size from the first sampling point to obtain the second sampling point, and to determine the sharpness corresponding to the second sampling point.
[0164] The third determining unit is used to determine whether the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, update the first sampling point to the second sampling point, and execute again the steps of subtracting the first target adjustment step size from the first sampling point to obtain the second sampling point and determining the sharpness corresponding to the second sampling point, until there are consecutive target times when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, and then the first sampling point corresponding to the first occurrence when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point is determined as the target focus.
[0165] In one possible implementation, the aforementioned target adjustment step size includes a second target adjustment step size;
[0166] The second determining module 930 mentioned above includes:
[0167] The fourth determining unit is used to, when the sharpness corresponding to the above at least 3 initial sampling points increases monotonically, add the above second target adjustment step size to the initial sampling point with the largest sharpness among the above at least 3 initial sampling points to obtain the third sampling point, and determine the sharpness corresponding to the above third sampling point.
[0168] The fifth determining unit is used to add the third sampling point to the second target adjustment step size to obtain the fourth sampling point, and to determine the sharpness corresponding to the fourth sampling point.
[0169] The sixth determining unit is used to determine whether the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point, update the third sampling point to the fourth sampling point, and execute again the steps of adding the third sampling point to the second target adjustment step size to obtain the fourth sampling point and determining the sharpness corresponding to the fourth sampling point, until the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point for a consecutive target number of times, and then determine the third sampling point corresponding to the first occurrence of the sharpness corresponding to the third sampling point being greater than the sharpness corresponding to the fourth sampling point as the target focus.
[0170] In one possible implementation, the focusing device 900 further includes:
[0171] The second judgment module is used to determine whether the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the above at least 3 initial sampling points is greater than a preset difference value.
[0172] The fourth determining unit mentioned above is specifically used for:
[0173] If not, the third sampling point is obtained by adding the first sampling point with the highest sharpness among the above at least 3 initial sampling points, and the sharpness corresponding to the third sampling point is determined.
[0174] In one possible implementation, the target adjustment step size further includes a third target adjustment step size; the third target adjustment step size is greater than the second target adjustment step size, and less than or equal to the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the at least three initial sampling points.
[0175] The aforementioned focusing device 900 also includes:
[0176] The fourth determining module is used to, if so, add the third target adjustment step size to the above-mentioned at least 3 initial sampling points to obtain at least 3 corresponding new sampling points, and to determine the sharpness corresponding to the above-mentioned at least 3 new sampling points;
[0177] The update module is used to update the above-mentioned at least 3 initial sampling points to the above-mentioned at least 3 new sampling points, and to perform the above-mentioned step of determining whether the sharpness corresponding to the above-mentioned at least 3 initial sampling points has monotonicity again.
[0178] In one possible implementation, the number of initial sampling points is at least four; the third determining module 940 includes:
[0179] The seventh determining unit is used to determine the target extreme point corresponding to the above target focusing fitting curve; the above target focusing fitting curve is obtained by solving a system of quadratic equations using the least squares method;
[0180] The eighth determining unit is used to determine the target focus based on the aforementioned target extreme points.
[0181] In one possible implementation, the eighth determining unit is specifically used for:
[0182] Subtract a preset step size from the target extreme point to obtain the fifth sampling point; add the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point, and determine the sharpness corresponding to the sixth sampling point; determine whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point, and update the fifth sampling point to the sixth sampling point, and repeat the steps of adding the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point and determining the sharpness corresponding to the sixth sampling point, until a consecutive target number of times the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point occurs, and the fifth sampling point corresponding to the first occurrence of whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point is determined as the target focus.
[0183] The division of modules in the above-described focusing device is for illustrative purposes only. In other embodiments, the focusing device can be divided into different modules as needed to complete all or part of the functions of the focusing device. The implementation of each module in the focusing device provided in this application embodiment can be in the form of a computer program. This computer program can run on a camera, terminal, or server. The program modules constituted by this computer program can be stored in the memory of the camera, terminal, or server. When the computer program is executed by a processor, it implements all or part of the steps of the focusing method described in this application embodiment.
[0184] Please see below. Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 10 As shown, the electronic device 1000 includes: at least one processor 1010, at least one communication bus 1020, user interface 1030, at least one network interface 1040, and memory 1050.
[0185] The communication bus 1020 can be used to realize the connection and communication of the above components.
[0186] The user interface 1030 may include a display screen and a 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, etc.
[0188] The processor 1010 may include one or more processing cores. The processor 1010 connects to various parts within the electronic device 1000 using various interfaces and lines. It 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 by calling data stored in the memory 1050. Optionally, the processor 1010 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 1010 may integrate one or more of the following: a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), and a modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor 1010.
[0189] The memory 1050 may include random access memory (RAM) or read-only memory (ROM). Optionally, the memory 1050 may include a non-transitory computer-readable medium. The memory 1050 can be used to store instructions, programs, code, 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-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. The memory 1050 may also be at least one storage device located remotely from the aforementioned processor 1010. Figure 10 As shown, the memory 1050, which serves 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 can be used to call program instructions stored in the memory 1050 and perform the following operations:
[0191] According to preset rules, at least three initial sampling points and the corresponding sharpness of the above three initial sampling points are determined from the target focal length range.
[0192] Determine whether the sharpness corresponding to the above at least 3 initial sampling points has monotonicity;
[0193] If so, the target adjustment step size is determined based on the initial sampling point with the highest sharpness among the above at least 3 initial sampling points, and the target focus is determined based on the above target adjustment step size.
[0194] If not, then the target focus fitting curve is determined based on the above at least 3 initial sampling points and the sharpness corresponding to the above at least 3 initial sampling points, and the target focus is determined based on the above target focus fitting curve.
[0195] In some possible embodiments, the target adjustment step size described above includes a first target adjustment step size;
[0196] When the processor 1010 executes the above-mentioned determination of the target focus based on the target adjustment step size, it is specifically used to perform the following:
[0197] When the sharpness of the above at least 3 initial sampling points decreases monotonically, the first sampling point is obtained by subtracting the first target adjustment step size from the initial sampling point with the highest sharpness among the above at least 3 initial sampling points, and the sharpness corresponding to the above first sampling point is determined.
[0198] The first sampling point is obtained by subtracting the first target adjustment step size from the first sampling point, and the sharpness corresponding to the second sampling point is determined.
[0199] Determine whether the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, update the first sampling point to the second sampling point, and repeat the steps of subtracting the first target adjustment step size from the first sampling point to obtain the second sampling point and determining the sharpness corresponding to the second sampling point, until there are consecutive target times when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point. Then, determine the first sampling point corresponding to the first occurrence when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point as the target focus.
[0200] In some possible embodiments, the target adjustment step size described above includes a second target adjustment step size;
[0201] When the processor 1010 executes the above-mentioned determination of the target focus based on the target adjustment step size, it is specifically used to perform the following:
[0202] Given that the sharpness of the above at least 3 initial sampling points increases monotonically, the third sampling point is obtained by adding the first initial sampling point with the highest sharpness among the above at least 3 initial sampling points to the second target adjustment step size, and the sharpness corresponding to the third sampling point is determined.
[0203] The third sampling point is added to the second target adjustment step size to obtain the fourth sampling point, and the sharpness corresponding to the fourth sampling point is determined.
[0204] Determine whether the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point, update the third sampling point to the fourth sampling point, and repeat the steps of adding the third sampling point to the second target adjustment step to obtain the fourth sampling point and determining the sharpness corresponding to the fourth sampling point, until there are consecutive target times when the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point. Then, determine the third sampling point corresponding to the first occurrence when the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point as the target focus.
[0205] In some possible embodiments, before the processor 1010 performs the above-described steps of adding the initial sampling point with the highest corresponding sharpness among the at least three initial sampling points to obtain the third sampling point, and determining the sharpness corresponding to the third sampling point, it is further configured to perform:
[0206] Determine whether the focal length difference between the maximum focal length point and the initial sampling point with the highest sharpness among the above at least 3 initial sampling points is greater than a preset difference value.
[0207] When the processor 1010 executes the above-mentioned process of adding the first sample point with the highest sharpness among the at least three initial sample points to the second target adjustment step size to obtain the third sample point, and determining the sharpness corresponding to the third sample point, it specifically performs the following:
[0208] If not, the third sampling point is obtained by adding the first sampling point with the highest sharpness among the above at least 3 initial sampling points, and the sharpness corresponding to the third sampling point is determined.
[0209] In some possible embodiments, the target adjustment step size further includes a third target adjustment step size; the third target adjustment step size is greater than the second target adjustment step size and less than or equal to the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the at least three initial sampling points.
[0210] After the processor 1010 performs the above-mentioned determination of whether the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the above-mentioned at least 3 initial sampling points is greater than a preset difference value, it is also used to perform:
[0211] If so, the above-mentioned at least 3 initial sampling points are respectively added to the above-mentioned third target adjustment step size to obtain at least 3 new sampling points, and the sharpness corresponding to the above-mentioned at least 3 new sampling points is determined.
[0212] Update the above at least 3 initial sampling points to the above at least 3 new sampling points, and perform the above step of determining whether the sharpness corresponding to the above at least 3 initial sampling points has monotonicity again.
[0213] In some possible embodiments, the number of initial sampling points is at least four; when the processor 1010 executes the above-mentioned determination of the target focus based on the target focus fitting curve, it is specifically used to perform:
[0214] Determine the target extreme point corresponding to the above target focus fitting curve; the above target focus fitting curve is obtained by solving the quadratic equation system using the least squares method based on at least 4 initial sampling points.
[0215] The target focus is determined based on the aforementioned target extreme points.
[0216] In some possible embodiments, when the processor 1010 performs the above-described determination of the target focus based on the target extreme 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 point.
[0218] The sixth sampling point is obtained by adding the fourth target adjustment step size to the fifth sampling point, and the sharpness corresponding to the sixth sampling point is determined.
[0219] Determine whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point, update the fifth sampling point to the sixth sampling point, and repeat the steps of adding the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point and determining the sharpness corresponding to the sixth sampling point, until a consecutive target number of times the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point occurs. Then, determine the fifth sampling point corresponding to the first occurrence of whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point as the target focus.
[0220] This application also provides a computer storage medium storing instructions that, when run on a computer or processor, cause the computer or processor to perform one or more steps of any of the above methods. If the constituent modules of the above-described focusing device are implemented as software functional units and sold or used as independent products, they can be stored in the storage medium.
[0221] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially as 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, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0222] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks. Unless otherwise specified, the technical features of this embodiment and its implementation can be combined arbitrarily.
[0223] The embodiments described above are merely preferred embodiments of this application and are not intended to limit the scope of this application. Any modifications and improvements made by those skilled in the art to the technical solutions of this application without departing from the spirit of this application should fall within the protection scope defined by the claims of this application.
Claims
1. A focusing method, characterized in that, The method includes: According to preset rules, at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points are determined from the target focal length range; Determine whether the sharpness corresponding to the at least 3 initial sampling points has monotonicity; If so, the target adjustment step size is determined based on the initial sampling point with the highest sharpness among the at least 3 initial sampling points, and the target focus is determined based on the target adjustment step size; If not, then the corresponding target focus fitting curve is determined based on the at least 3 initial sampling points and the sharpness corresponding to the at least 3 initial sampling points, and the target focus is determined based on the target focus fitting curve; Wherein, when the sharpness corresponding to the at least 3 initial sampling points monotonically decreases, the target adjustment step size includes a first target adjustment step size; the step of determining the target focus based on the target adjustment step size includes: When the sharpness corresponding to the at least 3 initial sampling points decreases monotonically, the first target adjustment step size is subtracted from the initial sampling point with the highest sharpness among the at least 3 initial sampling points to obtain the first sampling point, and the sharpness corresponding to the first sampling point is determined. Subtract the first target adjustment step size from the first sampling point to obtain the second sampling point, and determine the sharpness corresponding to the second sampling point; Determine whether the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, update the first sampling point to the second sampling point, and repeat the steps of subtracting the first target adjustment step size from the first sampling point to obtain the second sampling point and determining the sharpness corresponding to the second sampling point, until there are consecutive target times when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point. Then, determine the first sampling point corresponding to the first occurrence when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point as the target focus.
2. The method as described in claim 1, characterized in that, When the sharpness corresponding to the at least 3 initial sampling points increases monotonically, the target adjustment step size includes a second target adjustment step size; The step of determining the target focus based on the target adjustment step size includes: When the sharpness corresponding to the at least 3 initial sampling points increases monotonically, the third sampling point is obtained by adding the second target adjustment step size to the initial sampling point with the highest sharpness among the at least 3 initial sampling points, and the sharpness corresponding to the third sampling point is determined. The third sampling point is added to the second target adjustment step size to obtain the fourth sampling point, and the sharpness corresponding to the fourth sampling point is determined. Determine whether the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point, update the third sampling point to the fourth sampling point, and repeat the steps of adding the second target adjustment step size to the third sampling point to obtain the fourth sampling point and determining the sharpness corresponding to the fourth sampling point, until there are consecutive target times when the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point. Then, determine the third sampling point corresponding to the first occurrence when the sharpness corresponding to the third sampling point is greater than the sharpness corresponding to the fourth sampling point as the target focus.
3. The method as described in claim 2, characterized in that, Before adding the first initial sampling point with the highest sharpness among the at least three initial sampling points to the second target adjustment step size to obtain the third sampling point, and before determining the sharpness 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 highest corresponding sharpness among the at least 3 initial sampling points is greater than a preset difference value; The step of adding the first initial sampling point with the highest corresponding sharpness among the at least three initial sampling points to the second target adjustment step size to obtain a third sampling point, and determining the sharpness corresponding to the third sampling point, includes: If not, the third sampling point is obtained by adding the second target adjustment step size to the initial sampling point with the highest corresponding sharpness among the at least 3 initial sampling points, and the sharpness corresponding to the third sampling point is determined.
4. The method as described in claim 3, characterized in that, The target adjustment step size also includes a third target adjustment step size; the third target adjustment step size is greater than the second target adjustment step size, and less than or equal to the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the at least 3 initial sampling points; After determining whether the focal length difference between the maximum focal length point and the initial sampling point with the highest corresponding sharpness among the at least three initial sampling points is greater than a preset difference, the method further includes: If so, the at least three initial sampling points are respectively added to the third target adjustment step size to obtain at least three new sampling points, and the sharpness corresponding to the at least three new sampling points is determined; 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 has monotonicity is performed again.
5. The method as described in claim 1, characterized in that, The number of initial sampling points is at least 4; determining the target focus based on the target focus fitting curve includes: Determine the target extreme point corresponding to the target focus fitting curve; the target focus fitting curve is obtained by solving a system of quadratic equations using the least squares method based on at least four initial sampling points; The target focus is determined based on the target extreme point.
6. The method as described in claim 5, characterized in that, Determining the target focus based on the target extreme point includes: The fifth sampling point is obtained by subtracting the preset step size from the target extreme point; The fifth sampling point is added to the fourth target adjustment step size to obtain the sixth sampling point, and the sharpness corresponding to the sixth sampling point is determined; Determine whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point, update the fifth sampling point to the sixth sampling point, and repeat the steps of adding the fourth target adjustment step size to the fifth sampling point to obtain the sixth sampling point and determining the sharpness corresponding to the sixth sampling point, until a consecutive target number of times the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point occurs. Then, determine the fifth sampling point corresponding to the first occurrence of whether the sharpness corresponding to the fifth sampling point is greater than the sharpness corresponding to the sixth sampling point as the target focus.
7. A focusing device, characterized in that, The focusing device includes: The first determining module is used to determine at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points from the target focal length range according to preset rules; The first judgment module is used to determine whether the sharpness corresponding to the at least 3 initial sampling points has monotonicity; The second determining module is used to determine the corresponding target adjustment step size based on the initial sampling point with the largest corresponding sharpness among the at least three initial sampling points when the sharpness corresponding to the at least three initial sampling points is monotonic, and to determine the target focus based on the target adjustment step size; The third determining module is used to determine the corresponding target focus fitting curve based on the at least three initial sampling points and the sharpness corresponding to the at least three initial sampling points when the sharpness corresponding to the at least three initial sampling points does not have monotonicity, and to determine the target focus based on the target focus fitting curve. Wherein, when the sharpness corresponding to the at least 3 initial sampling points decreases monotonically, the target adjustment step size includes a first target adjustment step size; The step of determining the target focus based on the target adjustment step size includes: When the sharpness corresponding to the at least 3 initial sampling points decreases monotonically, the first target adjustment step size is subtracted from the initial sampling point with the highest sharpness among the at least 3 initial sampling points to obtain the first sampling point, and the sharpness corresponding to the first sampling point is determined. Subtract the first target adjustment step size from the first sampling point to obtain the second sampling point, and determine the sharpness corresponding to the second sampling point; Determine whether the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point, update the first sampling point to the second sampling point, and repeat the steps of subtracting the first target adjustment step size from the first sampling point to obtain the second sampling point and determining the sharpness corresponding to the second sampling point, until there are consecutive target times when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point. Then, determine the first sampling point corresponding to the first occurrence when the sharpness corresponding to the first sampling point is greater than the sharpness corresponding to the second sampling point as the target focus.
8. An electronic device, characterized in that, include: A processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and executed the method steps as claimed in any one of claims 1-6.
9. A computer storage medium, characterized in that, The computer storage medium stores a plurality of instructions adapted for loading by a processor and executing the method steps as claimed in any one of claims 1-6.
Citation Information
Patent Citations
Focusing device and method for adjusting laser focal length
CN107009023A
Focusing curve establishing method and device
CN111147732A