Focusing method, device, apparatus and readable storage medium
By determining the fine focus range based on the target object distance in the focusing method and combining adaptive adjustment and micro-motion focusing technology, the problems of slow focusing speed and poor quality in the existing technology are solved, and a fast and accurate focusing effect is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU SHIYUAN ELECTRONICS CO LTD
- Filing Date
- 2023-09-25
- Publication Date
- 2026-05-12
Smart Images

Figure CN119697492B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of camera technology, and in particular to a focusing method, apparatus, device, and readable storage medium. Background Technology
[0002] Focusing refers to the process by which an electronic device adjusts the distance between the lens and the imaging plane based on the object distance to achieve a sharp image of the subject. The object distance refers to the distance between the lens and the subject being photographed.
[0003] The focus value (FV) search method is a common focusing technique. When the lens of an electronic device is pointed at the object being photographed, the motor within the lens module drives the lens to move gradually from bottom to top, capturing multiple images. During this process, the electronic device calculates and records the FV corresponding to each image, generating a curve showing the relationship between the image FV and the lens position. The peak of this curve is then used as the focus position of the electronic device.
[0004] In the above focusing methods, the search range is related to the total focusing range of the motor. The larger the total focusing range, the larger the search range and the longer the search time, resulting in a slow focusing speed, which in turn leads to a slow shooting speed. Summary of the Invention
[0005] This application provides a focusing method, apparatus, device, and readable storage medium. By determining a first focusing range for fine-grained searching based on the target object distance, and adjusting the motor according to the first focusing range, the focusing speed is improved while reducing the search range.
[0006] In a first aspect, embodiments of this application provide a focusing method, including:
[0007] Determine the focus area of the current frame image, which is an image within the field of view of the lens module of the electronic device;
[0008] The first focusing range of the motor is determined by querying the target object distance mapping table. The motor is used to drive the lens module. The target object distance is used to indicate the distance between the target object corresponding to the focusing area and the lens module. The mapping table is used to indicate the offset corresponding to different object distances.
[0009] The motor is adjusted according to the first focus range to search for the focus position of the electronic device. The step size within the first focus range is less than a preset step size, and the step size outside the first focus range is greater than or equal to the preset step size.
[0010] Secondly, embodiments of this application provide a focusing device, comprising:
[0011] The determining module is used to determine the focus area of the current frame image, which is an image within the field of view of the lens module of the electronic device;
[0012] The processing module is used to determine the first focusing range of the motor by querying a mapping table based on the target object distance. The motor is used to drive the lens module. The target object distance is used to indicate the distance between the target object corresponding to the focusing area and the lens module. The mapping table is used to indicate the offset corresponding to different object distances.
[0013] The focusing module is used to adjust the motor according to the first focusing range to search for the focusing position of the electronic device, wherein the step size within the first focusing range is less than a preset step size, and the step size outside the first focusing range is greater than or equal to the preset step size.
[0014] Thirdly, embodiments of this application provide an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it causes the electronic device to implement the method described in the first aspect or various possible implementations of the first aspect.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer instructions, which, when executed by a processor, are used to implement the method described in the first aspect or various possible implementations of the first aspect.
[0016] Fifthly, embodiments of this application provide a computer program product comprising a computing program, wherein when the computer program is executed by a processor, it implements the method described in the first aspect or various possible implementations of the first aspect.
[0017] The focusing method, apparatus, device, and readable storage medium provided in this application embodiment pre-program the first motor value corresponding to the farthest object distance of the lens module and the second motor value corresponding to the closest object distance on the electronic device, and stores the offset corresponding to different object distances. During shooting, the electronic device determines the focus area of the current frame image within the field of view of the lens module, determines an offset by querying a mapping table based on the target object distance between the target object corresponding to the focus area and the lens module, and determines a first focus range based on the offset and the first motor value or the second motor value. Within the first focus range, the motor is adjusted with a smaller step size, and outside the first range, the motor is adjusted with a larger step size, which reduces the number of searches to a certain extent and shortens the focusing time, thereby achieving the purpose of improving the focusing speed. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying 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.
[0019] Figure 1 This is a schematic diagram illustrating the imaging principle to which the focusing method provided in the embodiments of this application applies;
[0020] Figure 2 This is a schematic diagram of an electronic device used to perform the focusing method provided in the embodiments of this application;
[0021] Figure 3 This is a flowchart of the focusing method provided in the embodiments of this application;
[0022] Figure 4 This is a flowchart of the focusing method for searching the focus position provided in the embodiments of this application;
[0023] Figure 5 This is a schematic diagram of the rule search process in the focusing method provided in the embodiments of this application;
[0024] Figure 6 A schematic diagram of a focusing device provided in an embodiment of this application;
[0025] Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0026] In scenarios such as photography, video recording, and video conferencing, electronic devices need to focus on the subject to ensure a clear image. The maximum f / V search method is a common focusing technique. In this method, the motor is driven from its minimum position, and adjusted in equal steps until it reaches its maximum position. During this adjustment, the motor drives the lens to move gradually from bottom to top, acquiring multiple images. The electronic device calculates and records the f / V corresponding to each image, generating a curve showing the relationship between the image f / V and the lens position. Finally, the peak of the curve is taken as the focus position of the electronic device.
[0027] The motor has an adjustable range. When the motor's adjustable range is too large, the search time for the maximum aperture (FV) becomes too long, resulting in a slow focusing speed. Furthermore, performing only one search can easily lead to finding the wrong maximum FV, resulting in poor focusing quality and unsatisfactory focusing performance.
[0028] Based on this, embodiments of this application provide a focusing method, apparatus, device, and readable storage medium. By determining a first focusing range for fine-grained searching based on the target object distance, and adjusting the motor according to the first focusing range to achieve rapid focusing, the focusing speed is improved while reducing the search range.
[0029] Figure 1 This is a schematic diagram illustrating the imaging principle to which the focusing method provided in the embodiments of this application applies. Please refer to... Figure 1 Imagine a large tree within the field of view of a lens module. The distance between the tree and the lens module is the object distance. The distance from the optical center of the lens module to the image sensor is the image distance. The image sensor is the point where the image is formed, and the plane on which the image sensor is located is the image plane. The distance from the optical center of the lens module to the focal point is the focal length. Focusing refers to adjusting the distance between the lens module and the image plane based on the object distance to achieve a sharp image of the subject.
[0030] The focusing method provided in this application can be applied to electronic devices such as smart interactive flat panels, cameras, personal computers, tablets, wearable devices, vehicle terminals, and monitoring equipment.
[0031] Figure 2 This is a schematic diagram of an electronic device used to perform the focusing method provided in the embodiments of this application. Please refer to... Figure 2 The electronic device 200 is equipped with a lens module 21. The focusing method described in this embodiment can be implemented by application software (APP) or a processor in the electronic device 200. The lens module 21, also known as a camera, is capable of capturing images or videos.
[0032] Typically, the voice coil motor (VCM) of an electronic device includes a coil, a magnet assembly, and a spring. Focusing is achieved by locking the lens module 21 into the VCM. A permanent magnetic field is used to change the current in the motor's coil, controlling the position of the spring and moving the lens to change the image distance, thus achieving autofocus. Focusing refers to the process of changing the focal length to make the image sharp.
[0033] In this application embodiment, the electronic device structure is optimized in some ways, including but not limited to using variable zoom length, adaptive adjustment, and micro-motion focusing, so as to focus more efficiently, quickly and accurately.
[0034] Variable zoom length refers to the lens module employing a variable zoom length to improve image quality at different focal lengths and enable more precise focus adjustments. Different imaging effects can be switched by changing the structure and magnification of the lens module. When it is necessary to change the overall focus range, the position of the optical focus is altered by adjusting the zoom length, thereby achieving more accurate and efficient focusing.
[0035] Adaptive focusing technology automatically adjusts the focusing distance for different parts of the target object to achieve more accurate and efficient focusing. By analyzing factors such as the shooting environment, the angle and position changes of the object, and combining intelligent algorithms for adaptive adjustment, the focal length can be changed anytime and anywhere, resulting in more accurate and efficient focusing.
[0036] Micro-focus technology is a technique that achieves more accurate focusing by making minute adjustments to the focus position of the camera lens. It utilizes the lens module's adjustment mechanism to slightly move the focusing lens element, thus precisely adjusting the focus point. Furthermore, micro-focus combines variable zoom length and adaptive adjustment technology to quickly change the focus center point through minute focus adjustments, adapting to various scenarios and requirements.
[0037] Figure 3 This is a flowchart of the focusing method provided in an embodiment of this application. The executing entity of this embodiment is an electronic device, which has a lens module. The motor can be mounted on the electronic device or on the lens module. This embodiment includes:
[0038] 301. Determine the focus area of the current frame image, wherein the current frame image is an image within the field of view of the lens module of the electronic device.
[0039] In this embodiment, the image within the field of view of the lens module is the preview image within the viewfinder of the lens module. The electronic device determines the target object from the current frame image through image segmentation, feature extraction, etc., and determines the focus area for each target object.
[0040] Taking a video conferencing scenario as an example, if the current frame contains 10 participants, meaning there are 10 target objects in the current frame, the electronic device determines a focus area for each target object. For instance, the electronic device identifies the area where each participant's head is located, resulting in 10 bounding boxes, or 10 focus areas.
[0041] 302. Determine the first focusing range of the motor by consulting the mapping table based on the target object distance.
[0042] The motor is used to drive the lens module, the target object distance is used to indicate the distance between the target object corresponding to the focus area and the lens module, and the mapping table is used to indicate the offset corresponding to different object distances, as well as the first motor value corresponding to the farthest object distance of the lens module and the second motor value corresponding to the nearest object distance.
[0043] In this embodiment, the farthest object distance and the closest object distance differ between lens modules from different manufacturers and models. The farthest object distance refers to the farthest distance that the lens module can capture; the closest object distance refers to the shortest distance that the lens module can capture.
[0044] Different manufacturers and models of lens modules have motors with different adjustable ranges. For example, the adjustable range is [0, 500], [0, 600], etc. A motor has a total focus range, which is one end of the adjustable range. For example, the adjustable range is [0, 500], and the total focus range is [100, 460]. A total focus range has two endpoints, namely the minimum position and the maximum position of the motor. The minimum position represents the position of the motor when adjusting it to make the image of the subject sharpest at the farthest object distance, i.e., the first motor value. The maximum position represents the position of the motor when adjusting it to make the image of the subject sharpest at the closest object distance, i.e., the second motor value. In the embodiments of this application, different motor values represent adjusting the motor to different positions.
[0045] For example, if the focusing range of the motor in lens module A is 100-460, then the minimum position is 100 and the maximum position is 460. That is to say, the first motor value corresponding to the farthest object distance is 100, and the second motor value corresponding to the closest object distance is 460.
[0046] For example, if the focusing range of the motor in lens module B is 200-518, then the minimum position is 200 and the maximum position is 518. In other words, the value of the first motor corresponding to the farthest object distance is 200, and the value of the second motor corresponding to the closest object distance is 518.
[0047] In this embodiment, the electronic device pre-programs the first motor value corresponding to the farthest object distance of the lens module and the second motor value corresponding to the closest object distance. Additionally, the electronic device pre-stores a mapping table, which indicates the offset corresponding to different object distances, as well as the first and second motor values of the lens module.
[0048] The following section provides a detailed explanation of the mapping table, using an example where the lens module's farthest object distance is 10 meters and its closest object distance is 0.5 meters, with the first motor value corresponding to 10 meters and the second motor value corresponding to 0.5 meters pre-programmed onto the electronic device. For an example, please refer to Table 1.
[0049] Table 1
[0050] Object distance Offset 10 meters 0 5 meters 17 3 meters 39 1.8 meters 76 1.2 meters 122 0.9 meters 168 0.7 meters 222 0.5 meters 318
[0051] Please refer to Table 1, using 10 meters as the reference standard, meaning the offset corresponding to 10 meters is 0. Different object distances correspond to different offsets. The offset differences for larger object distances are small, while the offset differences for smaller object distances are larger. For example, the offset for 10 meters is 0, and the offset for 5 meters is 17, a relatively small difference of 17. The offset for 0.7 meters is 222, and the offset for 0.5 meters is 318, a relatively large difference of 96.
[0052] When the electronic device obtains the target object distance, it can determine an offset by looking up a table based on the target object distance.
[0053] For example, if the target distance is 3 meters, the offset is 39. Assuming the first motor value corresponding to a maximum target distance of 10 meters is 200, then the motor value corresponding to 3 meters is approximately 200 + 39 = 239. The electronic device then determines a first focus range based on the motor value 239 corresponding to 3 meters. For example, the first focus range might be [200, 339]. Where 339 = 239 + 100.
[0054] For example, if the target distance is 4 meters, which is between 3 meters and 5 meters, the electronic device determines a first focus range based on the motor value 239 corresponding to 3 meters. For instance, the first focus range can be set to [200, 239].
[0055] 303. Adjust the motor according to the first focus range to search for the focus position of the electronic device, wherein the step size within the first focus range is less than a preset step size, and the step size outside the first focus range is greater than or equal to the preset step size.
[0056] In this embodiment, the first focus range is a fine focus range, meaning that when the motor is within the first focus range, it is adjusted with small step sizes. During the motor adjustment process, the electronic device adjusts the motor with small step sizes within the first focus range (i.e., the step size within the first focus range is less than a preset step size); outside the first focus range, it adjusts with larger step sizes (i.e., the step size is greater than or equal to the preset step size). For example, the electronic device starts adjusting the motor from its smallest position with a large step size. After a period of time, when the motor reaches the first focus range, the electronic device adjusts the motor with smaller step sizes.
[0057] In traditional focusing methods, motor adjustment typically starts from the minimum position and proceeds in equal steps until the maximum position is reached. This involves searching for many points. Clearly, in this embodiment, adjustment is performed with smaller steps within the first focusing range and larger steps outside the first focusing range, rather than using equal step adjustment.
[0058] The focusing method provided in this application involves pre-programming the first motor value corresponding to the farthest object distance of the lens module and the second motor value corresponding to the closest object distance on the electronic device, and storing the offset corresponding to different object distances. During shooting, the electronic device determines the focus area of the current frame image within the field of view of the lens module, determines an offset by querying a mapping table based on the target object distance between the target object corresponding to the focus area and the lens module, and determines a first focus range based on the offset and the first motor value or the second motor value. Within the first focus range, the motor is adjusted with a smaller step size, and outside the first range, the motor is adjusted with a larger step size. This reduces the number of searches to a certain extent, shortens the focusing time, and thus improves the focusing speed.
[0059] In the above embodiments, since the first motor value corresponding to the farthest object distance of 10 meters and the second motor value corresponding to the closest object distance are known, when the target object distance is the farthest object distance, the electronic device determines the focus position as the position of the lens module when the motor value is the first motor value.
[0060] When the target object distance is the closest object distance, the electronic device determines the focus position as: the position of the lens module when the motor value is the second motor value.
[0061] When the target object distance is neither the farthest nor the closest object distance, the electronic device queries a mapping table based on the target object distance to determine the first focusing range of the motor. In determining the first focusing range, the electronic device first determines a first object distance and a second object distance based on the target object distance. The first object distance is either the farthest or the closest object distance, and the target object distance is between the first and second object distances. Then, the electronic device determines the first focusing range based on the offset corresponding to the second object distance and the motor value corresponding to the first object distance.
[0062] Please refer to Table 1. Taking the first object distance as the farthest object distance as an example, when a target object distance exists in Table 1, such as when the target object distance is 5 meters, the electronic device determines the second object distance to be 3 meters. The offset corresponding to 3 meters is 39. Assuming that the motor value corresponding to the farthest object distance of 10 meters is 200, that is, the first motor value is 200, then the first focus range is [200, 239], 239 = 200 + 39.
[0063] When the first object distance is the closest object distance, if a target object distance exists in Table 1, such as 0.7 meters, the electronic device determines the second object distance to be 0.9 meters, and the offset corresponding to 0.9 meters is 168. Assuming the motor value corresponding to the closest object distance of 0.5 meters is 518, that is, the second motor value is 518, then the first focusing range is [350, 518], where 350 = 518 - 168.
[0064] It should be noted that, while this example illustrates how an electronic device determines the first focus range by looking up the table and then adjusts the motor to search for the focus position when a target object distance exists in Table 1, this embodiment is not limited to this. In other feasible implementations, after the electronic device looks up the mapping table to determine the offset corresponding to the target object distance, it can determine the motor value when the object distance is the target object distance based on the motor value corresponding to the first object distance and the offset corresponding to the target object distance. The lens position corresponding to this motor value is then used as the focus position. For example, if the first object distance is 10 meters, the target object distance is 5 meters, the offset corresponding to 5 meters is 17, and the first motor value is 200, then the motor value corresponding to 5 meters is 217. The electronic device uses the lens position corresponding to the motor value 217 as the focus position.
[0065] When the target object distance is not found in Table 1, the electronic device determines the first object distance and the second object distance from Table 1, with the target object distance located between the first and second object distances. For example, if the target object distance is 7 meters, then the first object distance is 10 meters, the second object distance is 5 meters, and the offset corresponding to 5 meters is 17. Assuming the motor value corresponding to the farthest object distance of 10 meters is 200, that is, the first motor value is 200, then the first focusing range is [200, 217], where 217 = 200 + 17.
[0066] Using this approach, the electronic device determines a first object distance and a second object distance based on the target object distance. The target object distance is between the first object distance and the second object distance. Then, the electronic device determines the first focus range based on the motor value corresponding to the first object distance and the offset corresponding to the second object distance, thereby achieving the purpose of accurately and quickly determining the first focus range.
[0067] In this embodiment, by using a pre-set mapping table, search rules, multi-point fitting equations, etc., the appropriate focus mode can be selected according to the scene and needs, so as to achieve accurate and efficient focusing.
[0068] Figure 4 This is a flowchart illustrating the search for the focus position in the focusing method provided in this application embodiment. This embodiment includes:
[0069] 401. Determine the positional relationship between the current position of the motor and the total focusing range of the motor.
[0070] The total focus range is used to indicate the minimum position and the maximum position of the motor. The minimum position is the position of the motor when the motor value is a first motor value, and the maximum position is the position of the motor when the motor value is a second motor value.
[0071] In this embodiment, two motor values corresponding to different object distances are pre-programmed into the electronic device: a first motor value corresponding to the farthest object distance and a second motor value corresponding to the closest object distance. The first motor value represents the motor position when the distance between the target object and the lens module is at its farthest object distance, adjusting the motor to achieve the clearest image. The second motor value represents the motor position when the distance between the target object and the lens module is at its closest object distance, adjusting the motor to achieve the clearest image. The first and second motor values represent the two ends of the motor's total focusing range. The motor position corresponding to the first motor value is also called the minimum motor position, and the motor position corresponding to the second motor value is also called the maximum motor position. The position between the maximum and minimum positions is considered the intermediate position.
[0072] During the process of adjusting the motor to search for the focus position, the electronic device determines the relationship between the current position and the total focus range. For example, the electronic device determines whether the current position is between the minimum and intermediate positions, or between the intermediate and maximum positions.
[0073] 402. Based on the positional relationship, determine the adjustment starting point from the total focus range.
[0074] For example, the method for determining the adjustment starting point is as follows: when the current position is between the minimum position and the middle position, the search begins from the minimum position. Here, the current position being between the minimum position and the middle position is also called the current position being less than the middle position. For example, the total focus range is [100, 460], the minimum position is 100, the maximum position is 460, and the middle position is 280. If the current position is 150, then the motor is reset to 100, and the motor adjustment begins from 100, i.e., the adjustment starting point is 100. The first focus range is, for example, [200, 217].
[0075] When the current position is between the middle and maximum positions, the search begins from the middle position. A current position between the middle and maximum positions is also called a current position greater than the middle position. For example, the total focus range is [100, 460], the minimum position is 100, the maximum position is 460, and the middle position is 280. If the current position is 300, the motor is reset to 280, and motor adjustment begins from 280; that is, the adjustment starting point is 280. The first focus range is, for example, [200, 217]. During adjustment, when the motor is between 217 and 280, a larger step size is used; when the motor is between 200 and 217, a smaller step size is used.
[0076] 403. Adjust the motor according to the adjustment starting point and the first focus range to search for the focus position of the electronic device.
[0077] Once the electronic device determines the adjustment starting point, it begins adjusting the motor from that point. During the adjustment process, a larger step size is used from the adjustment starting point to the first end of the first focus range, and a smaller step size is used within the first focus range.
[0078] For example, the total focus range is [100, 460], the minimum position is 100, the maximum position is 460, the middle position is 280, and the first focus range is [200, 217]. If the current position is 150, the motor is reset to 100. Afterwards, larger step sizes are used for adjustments between the starting point of 100 and 200. Smaller step sizes are used for the first focus range.
[0079] Using this approach, the electronic device determines the adjustment starting point based on the current position of the motor and the positional relationship of the total focusing range. It then determines the step size and adjusts the motor based on the adjustment starting point and the first focusing range, thereby searching for the focusing position. This effectively reduces the amount of searching while increasing the focusing speed.
[0080] Optionally, in the above embodiments, during the process of the electronic device adjusting the motor according to the adjustment starting point and the first focus range to search for the focus position of the electronic device, firstly, the electronic device determines a second focus range and a third focus range based on the adjustment starting point and the first end of the first focus range. Then, the electronic device adjusts the motor starting from the starting point of the second focus range to search for the focus position of the electronic device. Wherein, the starting point of the second focus range is the adjustment starting point, the ending point of the second focus range is the starting point of the third focus range, the ending point of the third focus range is the first end of the first focus range, and the two ends of the first focus range are the first end and the second end, respectively. The step size of the second focus range, the third focus range, and the first focus range decreases sequentially.
[0081] For example, taking the total focusing range of the motor as [100, 580], the adjustment starting point as 100, the first focusing range as [200, 217], and the current position as 150, the first end of the first focusing range is 200, and the second end is 217. The electronic device determines the second focusing range as, for example, [100, 150], and the third focusing range as, for example, [150, 200].
[0082] Figure 5 This is a schematic diagram illustrating the rule search process in the focusing method provided in this application embodiment. Please refer to... Figure 5The first, second, and third focus ranges are shown as ①, ②, and ③ in the figure, respectively. Within the second focus range, the focus value changes little with motor adjustment. Within the third focus range, the focus value changes more significantly with motor adjustment than in the first focus range. Within the first focus range, the focus value changes significantly with motor adjustment. Assuming the step size for the first focus range is step size 1, the step size for the second focus range is step size 2, and the step size for the third focus range is step size 3, then step size 2 > step size 3 > step size 1. Clearly, Figure 5 In the search, when the focal value (FV) does not change significantly, increase the search step size; when the FV changes significantly, decrease the search step size.
[0083] Using this approach, the electronic device searches for the focus position using a rule-based search method. When the focus value does not change significantly, the search step size is increased; when the focus value changes significantly, the search step size is decreased. This reduces the search volume while improving the focusing speed.
[0084] Optionally, in the above embodiments, when the electronic device adjusts the motor starting from the beginning of the second focus range to search for the focus position of the electronic device, firstly, the motor is adjusted in a forward direction until a first condition is met three consecutive times. Then, after the three consecutive adjustments meet the first condition, the lens motor is adjusted in a reverse direction until a second condition is met two consecutive times. The first condition indicates that the focus value corresponding to the first two adjustments in the three consecutive adjustments increases, and the focus value corresponding to the last two adjustments decreases; the forward adjustment refers to driving the motor so that its position gradually moves closer to the second end of the first focus range. The second condition indicates that the focus value corresponding to the two consecutive adjustments increases, and the reverse adjustment refers to driving the motor so that its position moves away from the second end. Afterwards, the electronic device fits a relationship curve between the lens position and the focus value based on the focus values when the lens is in different positions during the forward and reverse adjustments, and determines the focus position of the electronic device based on the relationship curve.
[0085] For example, during a forward search, if the focus value increases twice consecutively and then decreases twice consecutively or once, it indicates that the maximum focus value has been exceeded. At this point, the electronic device updates the data used to fit the relationship curve based on the focus values adjusted three times consecutively and the position of the lens module corresponding to each focus value. The relationship curve refers to the relationship between the lens position and the focus value.
[0086] Afterwards, the electronic device performs a reverse search. If the focus value increases more than twice in a row, it begins multi-point fitting. After fitting the relationship curve, the focus position of the electronic device can be determined based on the relationship curve.
[0087] This approach uses a forward and reverse search method to find the focus position, avoiding incorrect focus positions and enhancing the robustness and accuracy of the focus. Additionally, it can shorten the focusing time.
[0088] Optionally, in the above embodiments, during the process of determining the focus position of the electronic device based on the relationship curve, the first step is to determine whether the peak value of the relationship curve is stable. When the peak value is stable, the lens position corresponding to the peak value is taken as the focus position of the electronic device.
[0089] This application embodiment utilizes a multi-point fitting equation to determine the location of the maximum focus value. Before determining the maximum focus value, i.e., the focus position, it first determines whether the peak value of the relationship curve is stable. If the relationship curve is unstable, refocusing is triggered, i.e., forward and reverse searches are re-executed to fit the relationship curve between the lens position and the focus value. If the relationship curve is stable, the multi-point fitting equation is solved. Through the multi-point fitting equation, the coordinates of several search points are input, each search point including the focus value and lens position. After fitting the relationship curve, the peak value can be determined, and the lens position corresponding to the peak value is used as the focus position of the electronic device.
[0090] In this embodiment, the multivariate polynomial equation is solved iteratively using a univariate quadratic variance. The method for solving the univariate quadratic variance is as follows:
[0091] (1) The quadratic equation in one variable is: y = ax 2 Formula (1) +bx+c
[0092] (2) Convert the quadratic equation in one variable into a linear equation in three variables: Ax + By + Cz + D = 0 (Formula (2))
[0093] (3) Taking the unknowns a, b, and c as the unknowns of the three-variable linear equation, we can obtain the following from formula (1): x 2 ×a+x×b+cy=0 formula (3)
[0094] According to formulas (2) and (3), we can obtain: A = x 2 B = x, C = 1, D = -y.
[0095] To determine whether the peak value of the relationship curve is stable, in this embodiment, a threshold range is pre-set, with the two endpoints of the threshold range being floating-point data, for example, [0.0, 2.0]. After fitting the relationship curve, the electronic device determines the stability value of the relationship curve and compares the stability value with the threshold range. If the stability value of the relationship curve falls within the threshold range, it indicates that the peak value of the relationship curve is stable; if the stability value of the relationship curve does not fall within the threshold range, it indicates that the peak value of the relationship curve is unstable, and the focus position determined based on the relationship curve is unreliable, requiring a refocusing attempt. When the stability value falls within the threshold range, the larger the stability value, the more stable the peak value of the relationship curve. In practice, the range of the threshold range needs to be set according to the actual lens module.
[0096] In determining whether the peak value of the relationship curve is stable, the electronic device fits an equation and calculates its parameters. Once the parameters are determined, the equation corresponding to the relationship curve can be obtained. Since the horizontal axis of the relationship curve represents the motor position and the vertical axis represents the FV value, substituting the horizontal axis into the equation determines the value of the vertical axis. Therefore, substituting the horizontal axis corresponding to the peak value into the equation yields the vertical axis corresponding to the peak value, i.e., the optimal point coordinates. The optimal point coordinates are the focal point value and lens position corresponding to the peak value of the relationship curve. The optimal point coordinates can have the following possible cases:
[0097] A. If the optimal point coordinates are outside the range of [first motor value, second motor value], it indicates that the data interference is significant and is invalid data, requiring refocusing.
[0098] B. If the focus value corresponding to the peak is not in the middle of the interval [first motor value, second motor value], but rather on either side, it indicates significant data interference and is therefore invalid data, requiring refocusing. The coordinates to the left or right of the focus value corresponding to the peak need to be refitted.
[0099] C. The focal value corresponding to the peak value is in the middle of the interval [first motor value, second motor value].
[0100] The following explains how the stability value of the relationship curve is determined in the above embodiments.
[0101] FV mean = sum of FV values for each coordinate / number of coordinates.
[0102] Stability value = Regression sum of squares (SSR) / Sum of squares for total (SST). Where SST = |FV1 - mean FV|^2 + |FV2 - mean FV|^2 + ... + |FVx - mean FV|^2. Where FV1, FV2, ..., FVX are the actual calculated coordinate values, i.e., the focal values obtained during the forward and reverse motor adjustment process used to fit the relationship curve.
[0103] SSR = |FV1' - FV mean|^2 + |FV2' - FV mean|^2 + ... + |FVx' - FV mean|^2. Where FV1', FV2', ..., FVX' are the focal values calculated by substituting the x-coordinates into the fitted equation.
[0104] When 0 < stability value < 1, the lens position corresponding to the peak value in the relationship curve is taken as the focus position of the electronic device.
[0105] When 1 < stability value < 2, the symmetry stability value is determined with 1 as the axis of symmetry. Symmetry stability value = 2 - stability value. The interval becomes [0, 1]. Simultaneously, the lens position corresponding to the peak value in the relationship curve is taken as the focus position of the electronic device.
[0106] When the stability value is greater than 2, it indicates that the peak of the relationship curve is not at the temperature, the fitting has failed, and refocusing is required.
[0107] As stated above: when 0 < stability value < 2, the peak value of the relationship curve is relatively stable. When 0 < stability value < 1, the peak value fluctuates downwards; when 1 < stability value < 2, the peak value fluctuates upwards. Both upward and downward fluctuations are normal.
[0108] This approach determines the stability of the peak value of the relationship curve before focusing, and then uses a multi-point fitting equation to determine the focusing position when the peak value is stable, thus increasing the accuracy of the focusing position.
[0109] In this embodiment, the electronic device identifies and adjusts the focus area using techniques such as image segmentation, target detection, and feature extraction. During the identification process, the current frame image is analyzed to determine the target object, and a focus area is then identified for that object. Subsequently, the activity range of the target object and its potential future movements are predicted, automatically adjusting the focus area and search range to quickly adapt to the target object's movement and changes, thereby reducing false focusing and shortening the search time.
[0110] Optionally, in the above embodiments, during the process of determining the focus area of the current frame image, the electronic device performs target detection on the current frame image to identify the target object in the current frame image. Then, based on the position information of the target object in the current frame image, the focus area is determined.
[0111] For example, before determining the focus position, an electronic device first segments the current frame image to identify the target object in the image. This process typically involves techniques such as object detection and feature extraction to classify different object categories.
[0112] In one approach, a pre-defined category of target objects is indicated. The electronic device performs target detection on the current frame image to determine whether a target object of the pre-defined category exists in the current frame image. The pre-defined category of target objects includes, but is not limited to, people, animals, plants, and buildings. For example, in a video conferencing scenario, the target objects are the participants. For instance, if the electronic device's camera module captures 10 faces, the focus area is determined for each of the 10 faces.
[0113] In another approach, different priorities for different types of target objects are pre-defined, such as faces, landscapes, and animals. The electronic device performs target detection on the current frame image according to the priority, thereby determining whether various categories of target objects exist in the current frame image.
[0114] After identifying the target object, the electronic device determines the focus area based on the target object's position information within the current frame image. This position information includes, but is not limited to, the target object's outline coordinates and the center coordinates of its outline. For example, if the target object is a participant, the position information refers to the location of a bounding box within the current frame image. This bounding box contains the participant's face image.
[0115] It should be noted that when multiple target objects exist in the current frame image, the electronic device can identify multiple focus areas. During the subsequent focus position determination process, the electronic device can flexibly determine the focus position. In one approach, the electronic device identifies target objects that meet certain conditions from among the multiple target objects, and determines the focus position based on the target object distance, etc. Target objects that meet the conditions are, for example, objects whose object distance differs little from a preset object distance; this application embodiment does not limit this.
[0116] In another approach, the electronic device determines the focus position for each target object, and then weights these focus positions to determine the final focus position.
[0117] Using this approach, the electronic device identifies the target object through target detection, and determines the focus area based on the target object's position information in the current frame image, thus achieving the goal of accurately and quickly determining the focus area.
[0118] Optionally, in the above embodiments, after determining the focus area based on the position information of the target object in the current frame image, the electronic device further predicts the activity range and movement trajectory of the target object. Then, the electronic device adjusts the focus area based on the movement trajectory and the activity range.
[0119] For example, when the target object is a dynamic object, such as a human, animal, or car, the electronic device combines image processing and machine learning to determine the target object's possible range of motion and predict its movement trajectory. Based on the range of motion and movement trajectory, it predicts the target object's potential future movements and adjusts the focus area and the motor's adjustment range accordingly.
[0120] After the electronic device identifies the target object and recognizes the focus area, the process of adjusting the focus area is as follows:
[0121] First, the electronic device predicts the potential activity range and trajectory of the target object. During this prediction process, the electronic device needs to consider various factors, such as the target object's category and speed.
[0122] Secondly, predict the dynamic changes of the target object.
[0123] Once the activity area is determined, the electronic device uses machine learning and other predictive technologies to predict the possible movement and changes of the target object. Based on the changes in the target object's movement state, it automatically adjusts the position of the focus area and the search range to adapt to the movement and changes of the target object.
[0124] Finally, the electronic device adjusts the center point of the focus area and the search range.
[0125] After predicting the motion changes of the target object, the electronic device automatically adjusts the position of the center point of the focus area and the search range. Determining the center point of the focus area employs optimized control based on the object's motion angle and displacement. The search placement can be adjusted using adaptive search strategies for different object types.
[0126] This approach, by identifying and adjusting diagonal regions, quickly adapts to the movement and changes of the target object, reducing focusing errors and thus lowering search time.
[0127] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0128] Figure 6 This is a schematic diagram of a focusing device provided in an embodiment of this application. The focusing device 600 includes: a determining module 61, a processing module 62, and a focusing module 63.
[0129] The determining module 61 is used to determine the focus area of the current frame image, wherein the current frame image is an image within the field of view of the lens module of the electronic device;
[0130] Processing module 62 is used to determine the first focusing range of the motor by querying a mapping table based on the target object distance. The motor is used to drive the lens module. The target object distance is used to indicate the distance between the target object corresponding to the focusing area and the lens module. The mapping table is used to indicate the offset corresponding to different object distances.
[0131] The focusing module 63 is used to adjust the motor according to the first focusing range to search for the focusing position of the electronic device, wherein the step size within the first focusing range is less than a preset step size, and the step size outside the first focusing range is greater than or equal to the preset step size.
[0132] In one feasible implementation, the processing module 62 is used to determine a first object distance and a second object distance based on the target object distance, wherein the first object distance is the farthest object distance or the closest object distance, and the target object distance is between the first object distance and the second object distance; and to determine the first focus range based on the offset corresponding to the second object distance and the motor value corresponding to the first object distance.
[0133] In one feasible implementation, the focusing module 63 is used to determine the positional relationship between the current position of the motor and the focusing range of the motor. The total focusing range is used to indicate the minimum position and the maximum position of the motor. The minimum position is the position of the motor when the motor value is a first motor value, and the maximum position is the position of the motor when the motor value is a second motor value. Based on the positional relationship, an adjustment starting point is determined from the total focusing range. The motor is adjusted according to the adjustment starting point and the first focusing range to search for the focusing position of the electronic device.
[0134] In one feasible implementation, when the focusing module 63 adjusts the motor according to the adjustment starting point and the first focusing range to search for the focusing position of the electronic device, it is used to determine a second focusing range and a third focusing range according to the adjustment starting point and the first end of the first focusing range. The starting point of the second focusing range is the adjustment starting point, the ending point of the second focusing range is the starting point of the third focusing range, the ending point of the third focusing range is the first end of the first focusing range, and the two ends of the first focusing range are the first end and the second end, respectively. The motor is adjusted starting from the starting point of the second focusing range to search for the focusing position of the electronic device, and the step size of the second focusing range, the third focusing range, and the first focusing range decreases sequentially.
[0135] In one feasible implementation, the focusing module 63 adjusts the motor from the starting point of the second focusing range to search for the focusing position of the electronic device. This adjustment is performed in a forward direction until three consecutive adjustments satisfy a first condition. The first condition indicates that the focus value corresponding to the first two adjustments increases, and the focus value corresponding to the last two adjustments decreases. The forward adjustment refers to driving the motor so that its position gradually moves closer to the second end of the first focusing range. After the three consecutive adjustments satisfy the first condition, the lens motor is adjusted in a reverse direction until two consecutive adjustments satisfy a second condition. The second condition indicates that the focus value corresponding to the two consecutive adjustments increases. The reverse adjustment refers to driving the motor so that its position moves away from the second end. Based on the focus values of the lens module at different positions during the forward and reverse adjustments, a relationship curve between the lens position and the focus value is fitted. The focusing position of the electronic device is determined based on the relationship curve.
[0136] In one feasible implementation, when the focusing module 63 determines the focusing position of the electronic device based on the relationship curve, it is used to determine whether the peak value of the relationship curve is stable; when the peak value is stable, the lens position corresponding to the peak value is taken as the focusing position of the electronic device.
[0137] In one feasible implementation, the determining module 61 is used to perform target detection on the current frame image to determine the target object in the current frame image; and to determine the focus area based on the position information of the target object in the current frame image.
[0138] In one feasible implementation, after determining the focus area based on the position information of the target object in the current frame image, the determining module 61 is further used to predict the activity range and movement trajectory of the target object; and adjust the focus area based on the movement trajectory and the activity range.
[0139] The focusing device provided in this application embodiment can perform the actions of the electronic device in the above embodiment. Its implementation principle and technical effect are similar, and will not be described again here.
[0140] Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Please refer to... Figure 7 The electronic device 700 described in this application embodiment includes: at least one processor 71, at least one network interface 74, user interface 73, memory 75, and at least one communication bus 72.
[0141] The communication bus 72 is used to enable communication between these components.
[0142] The user interface 73 may include a display screen and a camera. Optionally, the user interface 73 may also include a standard wired interface or a wireless interface. The camera includes a lens module, a motor, etc., and is used to capture images within its field of view.
[0143] The network interface 74 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0144] The processor 71 may include one or more processing cores. The processor 71 connects to various parts of the electronic device 70 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 75, and by calling data stored in the memory 75. Optionally, the processor 71 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 71 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and 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 on the screen; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 71 and may be implemented as a separate chip.
[0145] The memory 75 may include random access memory (RAM) or read-only memory. Optionally, the memory 75 may include a non-transitory computer-readable storage medium. The memory 75 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 75 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 touch function, sound playback function, image playback function, etc.), instructions for implementing the various method embodiments described above, etc.; the data storage area may store data involved in the various method embodiments described above, etc. Optionally, the memory 75 may also be at least one storage device located remotely from the aforementioned processor 71. Figure 7 As shown, the memory 75, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and operating applications for electronic devices.
[0146] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0147] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0148] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0149] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0150] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0151] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0152] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0153] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0154] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A focusing method, characterized in that, include: Determine the focus area of the current frame image, where the current frame image is an image within the field of view of the lens module of the electronic device, and the focus area is a local area of the current frame image; The offset corresponding to the target object distance is determined according to the target object distance lookup mapping table, and the first focusing range of the motor is determined according to the offset and the first motor value or the second motor value. The motor is used to drive the lens module. The target object distance is used to indicate the distance between the target object corresponding to the focusing area and the lens module. The mapping table is used to indicate the offset corresponding to different object distances. The first motor value is the motor value corresponding to the farthest object distance of the lens module. The second motor value is the motor value corresponding to the closest object distance of the lens module. The first focusing range is an interval of the total focusing range of the motor. The two ends of the total focusing range are the first motor value and the second motor value, respectively. The motor is adjusted according to the first focus range to search for the focus position of the electronic device. The step size within the first focus range is less than a preset step size, and the step size outside the first focus range is greater than or equal to the preset step size.
2. The method according to claim 1, characterized in that, The step of determining the first focusing range of the motor by querying the mapping table based on the target object distance includes: A first object distance and a second object distance are determined based on the target object distance, wherein the first object distance is the farthest object distance or the closest object distance, and the target object distance is between the first object distance and the second object distance; The first focusing range is determined based on the offset corresponding to the second object distance and the motor value corresponding to the first object distance.
3. The method according to claim 1, characterized in that, The step of adjusting the motor according to the first focus range to search for the focus position of the electronic device includes: The positional relationship between the current position of the motor and the total focus range of the motor is determined. The total focus range is used to indicate the minimum position and the maximum position of the motor. The minimum position is the position of the motor when the motor value is a first motor value, and the maximum position is the position of the motor when the motor value is a second motor value. Based on the positional relationship, the adjustment starting point is determined from the total focus range; The motor is adjusted according to the adjustment starting point and the first focus range to search for the focus position of the electronic device.
4. The method according to claim 3, characterized in that, The step of adjusting the motor according to the adjustment starting point and the first focus range to search for the focus position of the electronic device includes: Based on the adjustment starting point and the first end of the first focus range, a second focus range and a third focus range are determined. The starting point of the second focus range is the adjustment starting point, the ending point of the second focus range is the starting point of the third focus range, and the ending point of the third focus range is the first end of the first focus range. The two ends of the first focus range are the first end and the second end, respectively. The motor is adjusted starting from the beginning of the second focus range to search for the focus position of the electronic device, with the step size of the second focus range, the third focus range, and the first focus range decreasing sequentially.
5. The method according to claim 4, characterized in that, The step of adjusting the motor from the starting point of the second focus range to search for the focus position of the electronic device includes: The motor is adjusted in a positive direction until the first condition is met in three consecutive adjustments. The first condition is used to indicate that the focus value corresponding to the first two adjustments in the three consecutive adjustments increases and the focus value corresponding to the last two adjustments decreases. The positive adjustment means driving the motor so that the position of the motor gradually moves closer to the second end of the first focus range. After the first condition is met by the three consecutive adjustments, the motor of the lens is adjusted in the opposite direction until the second condition is met by the two consecutive adjustments. The second condition is used to indicate that the focus value corresponding to the two consecutive adjustments increases. The reverse adjustment means driving the motor so that the motor moves away from the second end. Based on the focus values of the lens module at different positions during the forward and reverse adjustment processes, a relationship curve between the lens position and the focus value is fitted. The focus position of the electronic device is determined based on the relationship curve.
6. The method according to claim 5, characterized in that, Determining the focus position of the electronic device based on the relationship curve includes: Determine whether the peak value of the relationship curve is stable; When the peak value stabilizes, the lens position corresponding to the peak value is taken as the focus position of the electronic device.
7. The method according to any one of claims 1 to 6, characterized in that, Determining the focus area of the current frame image includes: Perform target detection on the current frame image to determine the target object in the current frame image; The focus area is determined based on the position information of the target object in the current frame image.
8. The method according to claim 7, characterized in that, After determining the focus area based on the position information of the target object in the current frame image, the method further includes: Predict the activity range and movement trajectory of the target object; The focus area is adjusted based on the movement trajectory and the range of activity.
9. A focusing device, characterized in that, include: A determining module is used to determine the focus area of the current frame image, wherein the current frame image is an image within the field of view of the lens module of the electronic device, and the focus area is a local area of the current frame image; The processing module is used to determine the offset corresponding to the target object distance according to the target object distance lookup mapping table, and to determine the first focusing range of the motor according to the offset and the first motor value or the second motor value. The motor is used to drive the lens module. The target object distance is used to indicate the distance between the target object corresponding to the focusing area and the lens module. The mapping table is used to indicate the offset corresponding to different object distances. The first motor value is the motor value corresponding to the farthest object distance of the lens module. The second motor value is the motor value corresponding to the closest object distance of the lens module. The first focusing range is an interval of the total focusing range of the motor. The two ends of the total focusing range are the first motor value and the second motor value, respectively. The focusing module is used to adjust the motor according to the first focusing range to search for the focusing position of the electronic device, wherein the step size within the first focusing range is less than a preset step size, and the step size outside the first focusing range is greater than or equal to the preset step size.
10. An electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it causes the electronic device to implement the method as described in any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 8.