Lens focusing method and apparatus, electronic device, and computer-readable storage medium

By acquiring the target phase difference and calibration data set of the main camera lens, and using the calibration phase difference and current to drive the main camera lens to focus, the problem of high cost of macro shooting function is solved, and low-cost macro shooting is realized.

CN117201935BActive Publication Date: 2026-06-16HUIZHOU TCL MOBILE COMM CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUIZHOU TCL MOBILE COMM CO LTD
Filing Date
2022-05-25
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

In existing technologies, achieving macro photography using a single camera results in high costs.

Method used

By acquiring the target phase difference and calibration data set of the main camera lens in macro shooting mode, the target current is determined using the calibration phase difference and calibration current, and the main camera lens is driven to focus, thus realizing the macro shooting function.

🎯Benefits of technology

It eliminates the need for an additional macro lens, reducing costs while enabling macro shooting functionality with the main camera lens.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117201935B_ABST
    Figure CN117201935B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a lens focusing method and device, electronic equipment and computer readable storage medium; in the embodiments of the present application, the target phase difference of the preview image collected by the main camera lens under the macro shooting mode is obtained;The calibration data set corresponding to the macro shooting mode is obtained, and the calibration data set includes the calibration phase difference of the reference calibration macro and the calibration current;Based on the calibration current corresponding to the calibration phase difference matched with the target phase difference, the target current is determined;According to the target current, the main camera lens is driven to focus.The embodiments of the present application can realize the macro shooting function through the main camera lens.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of photography technology, specifically to a lens focusing method, apparatus, electronic device, and computer-readable storage medium. Background Technology

[0002] As living standards improve, people have increasingly higher demands for the shooting functions of cameras. For example, cameras now offer wide-angle shooting and macro shooting capabilities.

[0003] Currently, a shooting function is generally achieved through a single camera. For example, macro shooting is achieved through a macro camera, which increases costs. Summary of the Invention

[0004] This application provides a lens focusing method, apparatus, electronic device, and computer-readable storage medium, which can solve the technical problem of high cost caused by achieving macro shooting function through macro lens.

[0005] A lens focusing method, comprising:

[0006] Obtain the target phase difference in the preview image captured by the main camera lens in macro shooting mode;

[0007] Obtain the calibration data set corresponding to the macro shooting mode, the calibration data set including the calibration phase difference and calibration current of the reference calibration macro;

[0008] The target current is determined based on the calibration current corresponding to the calibration phase difference that matches the target phase difference;

[0009] The main camera lens is driven to focus according to the target current.

[0010] Accordingly, embodiments of this application provide a lens focusing device, including:

[0011] The first acquisition module is used to acquire the target phase difference of the preview image captured by the main camera lens in macro shooting mode;

[0012] The second acquisition module is used to acquire the calibration data set corresponding to the macro shooting mode. The calibration data set includes the calibration phase difference and calibration current of the reference calibration macro.

[0013] A current determination module is used to determine the target current based on the calibration current corresponding to the calibration phase difference that matches the target phase difference;

[0014] The lens focusing module is used to drive the main camera lens to focus according to the target current.

[0015] Furthermore, this application also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor is used to run the computer program in the memory to implement the lens focusing method provided in this application.

[0016] Furthermore, embodiments of this application also provide a computer-readable storage medium storing a computer program adapted for loading by a processor to execute any of the lens focusing methods provided in embodiments of this application.

[0017] Furthermore, this application also provides a computer program product, including a computer program that, when executed by a processor, implements any of the lens focusing methods provided in this application.

[0018] In this embodiment, the target phase difference of the preview image captured by the main camera in macro shooting mode is first obtained. Then, the calibration data set corresponding to the macro shooting mode is obtained, which includes the calibration phase difference and calibration current of the reference macro. Next, the target current is determined based on the calibration current corresponding to the calibration phase difference that matches the target phase difference. Finally, the main camera is driven to focus according to the target current.

[0019] In this embodiment of the application, since the calibration data set includes the calibration phase difference and calibration current of the reference calibration macro, the main camera lens can be driven to focus in the macro range based on the target phase difference, calibration phase difference and calibration current. Thus, the macro shooting function can be realized through the main camera lens, without the need for a macro camera, which reduces the cost. Attached Figure Description

[0020] 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.

[0021] Figure 1 This is a schematic diagram of the phase focusing principle provided in the embodiments of this application;

[0022] Figure 2 This is a schematic flowchart of the lens focusing method provided in the embodiments of this application;

[0023] Figure 3 This is a schematic flowchart of another lens focusing method provided in an embodiment of this application;

[0024] Figure 4This is a schematic diagram of the lens focusing device provided in the embodiments of this application;

[0025] Figure 5 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0026] The technical solutions of 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.

[0027] This application provides a lens focusing method, apparatus, electronic device, and computer-readable storage medium. The lens focusing apparatus can be integrated into an electronic device, which may be a server or a terminal, etc.

[0028] The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, network acceleration services (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.

[0029] The terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. The terminal and the server can be connected directly or indirectly through wired or wireless communication, which is not limited herein.

[0030] Furthermore, in the embodiments of this application, "multiple" refers to two or more. The terms "first" and "second," etc., in the embodiments of this application are used for distinguishing descriptions and should not be construed as implying relative importance.

[0031] Phase detection autofocus (PDAF) refers to calculating the lens offset based on the phase difference, and then moving the lens to the focusing position according to the offset. Figure 1 For example, light rays from different directions cause the subject to be imaged onto the sensor through the lens. When light rays from different directions converge on the sensor, such as... Figure 1 As shown in b, there is no phase difference between light signal 1 and light signal 2 detected by the sensor. In this case, a clear image of the subject can be captured. When light rays from different directions converge in front of the sensor, as... Figure 1 As shown in Figure a, there is a phase difference between light signal 1 and light signal 2 detected by the sensor. In this case, the image of the captured object is blurry. When light rays from different directions converge behind the sensor, as... Figure 1 As shown in c, there is also a phase difference between the light signal 1 and the light signal 2 detected by the sensor. At this time, the image of the subject captured is also blurry.

[0032] When performing phase focusing, the phase difference of the image of the subject when the lens is in the current position is first obtained. Then, the phase difference is converted into the distance that the lens needs to move. Finally, the motor is driven to move the lens by that distance, and then a clear image of the subject can be obtained through the lens.

[0033] The following sections provide detailed descriptions of each example. It should be noted that the order in which the embodiments are described is not intended to limit the preferred order of the embodiments.

[0034] In this embodiment, the description will be from the perspective of the lens focusing device. In order to facilitate the explanation of the lens focusing method of this application, the following will describe the lens focusing device integrated into the terminal in detail, that is, the terminal will be used as the execution subject for detailed explanation.

[0035] Please see Figure 2 , Figure 2 This is a schematic flowchart of a lens focusing method provided in an embodiment of this application. The lens focusing method may include:

[0036] S201. Obtain the target phase difference of the preview image captured by the main camera lens in macro shooting mode.

[0037] When the terminal detects that it has entered macro shooting mode, it can directly capture a preview image at the current position of the main camera lens, or the terminal can first drive the motor to move the main camera lens to the initial position, then capture the preview image corresponding to the initial position through the main camera lens, and finally calculate the target phase difference of the preview image.

[0038] Optionally, multiple initial positions can be preset. When the current position of the main camera lens is included among the multiple initial positions, the terminal can directly capture a preview image at the current position of the main camera lens. When the current position of the main camera lens is not included among the multiple initial positions, the terminal can first drive the motor to move the main camera lens to the initial position, and then capture the preview image corresponding to the initial position through the main camera lens.

[0039] It should be understood that when the current position of the main camera is not included among multiple initial positions, the main camera can be moved to the initial position closest to the current position.

[0040] Alternatively, you can set an initial position, then directly drive the motor to move the main camera from the current position to the initial position, and then capture the preview image corresponding to the initial position through the main camera.

[0041] Since a single preview image contains multiple phase differences, in some embodiments, acquiring the target phase difference of the preview image captured by the main camera in macro shooting mode includes:

[0042] Determine multiple initial phase differences in the preview image captured by the main camera lens in macro shooting mode;

[0043] The largest initial phase difference among multiple initial phase differences is used as the target phase difference of the preview image.

[0044] Alternatively, obtain the target phase difference of the preview image captured by the main camera in macro shooting mode, including:

[0045] Determine multiple initial phase differences in the preview image captured by the main camera lens in macro shooting mode;

[0046] The average of multiple initial phase differences is used as the target phase difference of the preview image.

[0047] In this embodiment, the average value of all initial phase differences in the preview image can be used as the target phase difference of the preview image. Alternatively, the average value of a portion of the initial phase differences in the preview image can be used as the target phase difference of the preview image. This embodiment does not impose any limitations on this.

[0048] When using the average of a portion of the initial phase differences in the preview image as the target phase difference of the preview image, the average of multiple initial phase differences is used as the target phase difference of the preview image, including:

[0049] Multiple initial phase differences are arranged according to a preset rule to obtain the target array corresponding to the preview image;

[0050] The target phase difference of the preview image is calculated based on the average value of the initial phase difference at the preset positions in the target array.

[0051] For example, if the preset rule is a 6*8 two-dimensional array rule, that is, the target array is a 6*8 two-dimensional array, and the preset position is the four center positions, then the initial phase difference is arranged into a 6*8 two-dimensional array, and then the average value of the four initial phase differences at the center position of the 6*8 two-dimensional array is used as the target phase difference.

[0052] S202. Obtain the calibration data set corresponding to the macro shooting mode. The calibration data set includes the calibration phase difference and calibration current of the reference calibration macro.

[0053] When there are multiple initial positions in macro shooting mode, each initial position can correspond to a separate calibration data set. Therefore, after the terminal acquires a preview image at an initial position, it can obtain the calibration data set corresponding to that initial position.

[0054] Reference calibration macro is the macro setting used during the calibration of the main camera lens. For example, reference calibration macro can include 5 cm, 6.5 cm, and 8 cm, which means acquiring calibration images of the subject at positions of 5 cm, 6.5 cm, and 8 cm, respectively.

[0055] Calibration phase difference refers to the phase difference of the calibration image acquired by the main camera lens from its initial position when the subject is located at the reference calibration distance during the calibration process. Calibration current refers to the current required to move the main camera lens from its initial position to a position where a clear image of the subject can be obtained when the subject is located at the reference calibration macro distance; in other words, the current required to move the main camera lens from its initial position to the focusing position corresponding to the reference calibration macro distance.

[0056] It should be understood that the calibration current can also be a DAC (digital-to-analog converter) value or a code value. The code value refers to the indication code of the motor's travel, which can be understood as a computer language representation of the motor's travel. The motor's travel is also the distance the main camera lens moves.

[0057] It should be noted that the calibration data set can be burned into a memory used to store lens data before the main camera lens leaves the factory. The memory used to store lens data can be, for example, an electrically erasable programmable read-only memory (EEPROM). Then the terminal reads the calibration data set from the memory.

[0058] Therefore, in some embodiments, before obtaining the calibration data set corresponding to the macro shooting mode, the method further includes:

[0059] Acquire multiple test macro shots in macro shooting mode;

[0060] Select a reference calibration macro from multiple test macros;

[0061] Move the main camera to the initial position for acquiring the preview image, and take a picture of the subject located at the reference calibration macro position to obtain the calibration image of the subject;

[0062] Based on the calibration image, determine the calibration phase difference and calibration current of the reference calibration macro.

[0063] Based on the calibration phase difference and calibration current of the reference calibration macro, determine the calibration data set corresponding to the macro shooting mode.

[0064] The macro test distance can be selected according to the actual situation. For example, when the macro distance is 5 cm-8 cm, it can be divided into 5 cm-8 cm, resulting in macro test distances of 5 cm, 5.5 cm, 6.5 cm, and 8 cm.

[0065] After obtaining multiple test macros, the largest test macro among the multiple test macros can be used as the reference calibration macro, or the smallest test macro among the multiple test macros can be used as the reference calibration macro, or one test macro can be randomly selected from the multiple test macros as the reference calibration macro. This embodiment does not limit this.

[0066] The process of determining the calibration phase difference and calibration current of the reference calibration macro based on the calibration image, and then determining the calibration data set corresponding to the macro shooting mode based on the calibration phase difference and calibration current of the reference calibration macro, can be summarized as follows:

[0067] Based on the calibration image, determine the calibration phase difference corresponding to the reference calibration macro.

[0068] The main camera lens is moved according to the moving current until it reaches the initial focus position corresponding to the reference macro.

[0069] Use the moving current corresponding to the initial focusing position as the reference calibration current corresponding to the macro.

[0070] If multiple test macros have not been completely filtered, return to the step of filtering the reference calibration macro from the multiple test macros.

[0071] If multiple test macros have been selected, the calibration data set corresponding to the macro shooting mode is determined based on the calibration phase difference and calibration current of the reference calibration macro.

[0072] After obtaining the calibration phase difference of the reference macro (the terminal can input the calibration image into the Qualcomm tool for calculation to obtain the calibration phase difference of the reference macro), the terminal can first store the calibration phase difference of the reference macro, and then continuously input different moving currents to the motor of the main camera lens to move it, thereby making the main camera lens move continuously.

[0073] It should be understood that each time the terminal inputs a moving current to drive the motor and move the main camera lens to the position corresponding to the moving current, it can acquire a preview image of the position corresponding to the moving current. Then, based on the phase difference of the preview image of the position corresponding to the moving current, it can determine whether the position corresponding to the moving current is the initial focus position corresponding to the reference calibration macro. If not, it continues to input a moving current to the motor. If it is the initial focus position corresponding to the reference calibration macro, the moving current is used as the calibration current corresponding to the reference calibration macro.

[0074] Since there are multiple test macros, that is, multiple reference calibration macros, after obtaining the reference calibration macros, if there are still test macros that have not been used as reference calibration macros, that is, if multiple test macros have not been completely screened, the process returns to the step of screening out the reference calibration macros from the multiple test macros. If multiple test macros have been screened, the calibration data set corresponding to the macro shooting mode is determined based on the calibration phase difference and calibration current of the reference calibration macros.

[0075] For example, macro tests include 5 cm, 5.5 cm, 6.5 cm, and 8 cm. First, 5 cm is used as the parameter to calibrate the macro. Then, the main camera lens is positioned at the initial position, and a calibration image of the subject at the 5 cm position is acquired. Next, the calibration phase difference of the 5 cm calibration image is determined. Then, a moving current is continuously input to drive the motor to move the main camera lens so that a clear image of the subject can be acquired. That is, the initial focusing position corresponding to 5 cm is found (the focusing position refers to the position of the lens when a clear image can be acquired). The moving current corresponding to the acquisition of a clear image of the subject is used as the calibration current corresponding to 5 cm.

[0076] At this point, since there are still 5.5 cm, 6.5 cm, and 8 cm test macro distances, the process returns to the step of filtering out the reference calibration macro distance from the multiple test macro distances until the calibration phase difference and calibration current corresponding to 5.5 cm, 6.5 cm, and 8 cm are obtained. Finally, the calibration phase difference and calibration current corresponding to 5 cm, 5.5 cm, 6.5 cm, and 8 cm constitute the calibration data set.

[0077] It should be noted that the calibration phase difference of the calibration image of the subject at the reference calibration macro position is different when the main camera lens is positioned in different initial positions. Therefore, the moving current required to move the main camera lens from the initial position to the initial focusing position corresponding to the reference calibration macro is also different. Thus, if multiple initial positions are preset, after obtaining the calibration data set corresponding to one initial position, calibration data sets corresponding to other initial positions can be obtained. The test macros corresponding to different initial positions can be the same or different.

[0078] Optionally, the initial position can be set based on multiple test macro distances. For example, the focus position corresponding to the largest test macro distance among multiple test macro distances can be used as the initial position, or the focus position corresponding to the smallest test macro distance among multiple test macro distances can be used as the initial position.

[0079] Alternatively, the initial position can be the midpoint between the focus point corresponding to the largest and smallest test macro distances among multiple test macro distances. In this case, before moving the main camera to the initial position for capturing the preview image, the following steps are also included:

[0080] The maximum and minimum test macro distances are selected from multiple test macro distances;

[0081] The initial position is determined based on the focusing position corresponding to the maximum test macro distance and the focusing position corresponding to the minimum test macro distance.

[0082] The average of the calibration current for the maximum test macro distance and the calibration current for the minimum test macro distance can be used as the driving current corresponding to the initial position. When the driving current corresponding to the initial position is input to the motor, the motor can be driven to move the main camera lens to the initial position.

[0083] For example, the calibration current and drive current are represented by code values. The maximum test micro distance is 8 cm, and the code value corresponding to 8 cm is 500. The minimum test micro distance is 5 cm, and the code value corresponding to 5 cm is 800. Then the code value corresponding to the initial position is 650.

[0084] Optionally, the terminal may perform a step to determine the calibration data set corresponding to the macro shooting mode by calibrating the phase difference and calibration current based on the reference calibration macro before each main camera lens is shipped from the factory. Alternatively, the main camera lens of the same device type may only perform the step of determining the calibration data set corresponding to the macro shooting mode by calibrating the phase difference and calibration current based on the reference calibration macro only once. In this case, before obtaining the target phase difference of the preview image acquired by the main camera lens in macro shooting mode, the following steps are also included:

[0085] Determine the device type for the main camera lens;

[0086] Determine the calibration data set corresponding to the macro shooting mode based on the device type.

[0087] After obtaining the device type of the main camera lens, the terminal searches for the calibration data set corresponding to that device type. If a calibration data set for that device type exists, it is used as the calibration data set for the macro shooting mode, which is stored in an electrically erasable programmable read-only memory. If no corresponding calibration data exists for that device type, the terminal performs the step of determining the calibration data set for the macro shooting mode based on the calibration phase difference and calibration current of the reference calibration macro, and then associates and stores the calibration data set with the device type of the main camera lens.

[0088] S203. Determine the target current based on the calibration current corresponding to the calibration phase difference that matches the target phase difference.

[0089] The calibration phase difference matching the target phase difference can refer to the calibration phase difference whose difference from the target phase difference is within a preset range. Determining the target current based on the calibration current corresponding to the calibration phase difference matching the target phase difference can refer to using the calibration current corresponding to the calibration phase difference matching the target phase difference as the target current, or it can refer to multiplying the calibration current corresponding to the calibration phase difference matching the target phase difference by a preset current weight to obtain a first multiplication result, and then using the first multiplication result as the target current.

[0090] In related technologies, the relationship between the distance the main camera lens moves and the phase difference can be linear or nonlinear. That is, the relationship between the motor's travel (which is also the distance the main camera lens moves) and the phase difference can be linear or nonlinear. In other words, the relationship between the phase difference and the current driving the motor can be linear or nonlinear. For example, when the motor travel is 0-400 micrometers, the relationship between the motor travel and the phase difference can be linear; when the motor travel is 401-600 micrometers, the relationship can be nonlinear.

[0091] When the relationship between the motor's stroke and the phase difference is linear, after the terminal obtains the phase difference, it multiplies the phase difference by a fixed slope to obtain the motor's stroke, thereby driving the motor to bring the main camera lens to the focus position.

[0092] However, when the subject is located at the macro position, the motor travel obtained by multiplying the phase difference by a fixed slope is incorrect. That is, at this time, the drive motor moves the main camera lens but cannot move the main camera lens to the focus position.

[0093] At this point, if the main camera lens is to be moved to the focusing position using a linear relationship, the stroke of the motor corresponding to the linear relationship needs to be increased. Increasing the motor stroke leads to a larger size of the optical module housing the main camera lens, resulting in higher costs.

[0094] When the relationship between the motor's stroke and the phase difference is non-linear, the slope is variable, making it impossible to convert the phase difference into the motor's stroke. Therefore, currently, using a fixed slope method, when the subject is located at the macro position, it's impossible to move the main lens to the focusing position; using a variable slope method, it's impossible to determine the motor's stroke based on the phase difference.

[0095] In this embodiment, because the calibration data set includes the calibration phase difference and calibration current of the reference calibration macro, and then the target current is determined based on the calibration current corresponding to the calibration phase difference that matches the target phase difference, even if the relationship between the calibration phase difference and the calibration current is non-linear (even if the relationship between the motor stroke and the calibration phase difference is non-linear), the target current can still be obtained based on the target phase difference. Thus, the motor is driven to move the main camera lens based on the target current. In turn, the non-linear relationship between the motor stroke and the phase difference is used to realize the macro shooting function through the main camera lens. There is no need to add a macro lens or increase the size of the optical module where the main camera lens is located, which greatly reduces the cost.

[0096] In some embodiments, the reference calibration micrometer includes multiple reference calibration micrometers, each corresponding to multiple calibration phase differences and a calibration current.

[0097] Before determining the target current based on the calibration current corresponding to the calibration phase difference that matches the target phase difference, the method further includes:

[0098] Perform arithmetic operations on the multiple calibration phase differences corresponding to the reference calibration macro to obtain the target phase value;

[0099] Based on the target phase value, the calibration phase difference that matches the target phase difference is selected from the calibration dataset.

[0100] The four arithmetic operations include at least one of addition, subtraction, multiplication, and division. When addition and division are included simultaneously, the target phase value can be the average target phase value, i.e., the calibration phase difference that matches the target phase difference is selected from the calibration data set based on the average of multiple calibration phase differences. When addition, subtraction, multiplication, and division are included simultaneously, the target phase value can be the target phase variance or target phase standard deviation. In this case, the target phase difference can also be the variance or standard deviation of the initial phase difference.

[0101] When the target phase value is the target phase average value, the target phase average value can be the average value of all calibration phase differences of the reference calibration macro, or the target phase average value can be the average value of a portion of the calibration phase differences of the reference calibration macro.

[0102] When the target phase average is a subset of the average calibration phase differences of the reference calibration macro, perform arithmetic operations on multiple calibration phase differences corresponding to the reference calibration macro to obtain the target phase value, including:

[0103] The multiple calibration phase differences corresponding to each reference calibration macro are arranged according to a preset rule to obtain the permutation array corresponding to each reference calibration macro.

[0104] Based on the average value of the calibration phase difference at the preset position in the permutation array, calculate the target phase average value of multiple calibration phase differences corresponding to the reference calibration macro.

[0105] The preset rules can be set according to the actual situation. For example, the preset rules can be 6*8 two-dimensional array rules, or they can be one-dimensional array rules. This embodiment does not limit them here.

[0106] Optionally, when the calibration phase differences are arranged according to a preset rule, the positions of each calibration phase difference in the arrangement array can be arranged according to the rule of ascending from small to large, or according to the rule of descending from large to small, or according to the position of the corresponding preview image information on the preview image based on the optical signal corresponding to the calibration phase difference.

[0107] For example, if the preset rule is a 6*8 two-dimensional array rule, then in the process of arranging multiple calibration phase differences into a 6*8 two-dimensional array, the multiple calibration phase differences can be arranged in ascending order to obtain a 6*8 two-dimensional array.

[0108] The preset positions can be selected according to the actual situation. For example, in this embodiment, the four center positions of the permutation array are used as preset positions, or the first two positions and the last two positions of the permutation array are used as preset positions. This embodiment does not limit this.

[0109] Since the distance the main camera lens needs to move can be accurately obtained based on the calibration phase difference corresponding to the four central positions of the array, the average value of the calibration phase difference of the four central positions of the array can be used as the target phase average value of multiple calibration phase differences corresponding to the reference calibration macro. There is no need to calculate the average value of all calibration phase differences of the reference calibration macro. This allows the target phase value matching the target phase difference to be accurately obtained while reducing the amount of calculation, and thus the calibration phase difference matching the target phase difference can be accurately obtained.

[0110] Since there are multiple reference calibration macros, and each reference calibration macro has a corresponding target phase value, there are multiple target phase values. Therefore, the terminal can first match each target phase value with the target phase difference, and then use the calibration phase difference corresponding to the target phase value that matches the target phase difference as the calibration phase difference value that matches the target phase difference.

[0111] Alternatively, after obtaining the target phase value, the terminal can multiply the target phase value with a preset phase weight to obtain a second multiplication result. Then, based on the second multiplication result, it can filter out the calibration phase difference that matches the target phase difference from the calibration data set, that is, match the second multiplication result with the target phase difference.

[0112] When the target phase value matches the target phase difference, the calibration phase difference that matches the target phase difference is selected from the calibration dataset based on the target phase value, including:

[0113] The target phase difference is matched with the target phase value corresponding to each reference calibration macro to obtain the target phase value that matches the target phase difference;

[0114] Based on the target phase value that matches the target phase difference, the calibration phase difference that matches the target phase difference is selected from the calibration dataset.

[0115] That is, the multiple calibration phase differences corresponding to the target phase value that match the target phase difference are taken as the calibration phase differences that match the target phase difference, and then the calibration current corresponding to the multiple calibration phase differences that match the target phase value in the calibration data set is taken as the target current.

[0116] Matching the target phase difference with the target phase value corresponding to each reference calibration macro can be achieved by calculating the difference between the target phase difference and each target phase value separately, and then using the target phase value with the smallest difference as the target phase value to match the target phase difference. Alternatively, the target phase values ​​can be arranged in order of numerical value to obtain a matching array, and then compared with the target phase difference in turn to determine the numerical range of the target phase difference in the matching array, find the target phase value that matches the target phase difference, and thus reduce the number of comparisons.

[0117] When the target phase value is the average target phase value and the target phase values ​​are arranged in order of numerical value to obtain a matching array, the target phase difference is matched with the target phase value corresponding to each reference calibration macro to obtain the target phase value that matches the target phase difference, including:

[0118] Obtain the matching array by arranging the average target phase values ​​corresponding to each reference calibration macro in order of numerical magnitude;

[0119] Determine the position of the target phase difference within the numerical range of the matching array;

[0120] Based on the position of the numerical interval, determine the average value of the target phase that matches the target phase difference.

[0121] The numerical values ​​can be either from largest to smallest or smallest to largest. The position of the numerical interval refers to the position between two adjacent average values ​​in the matching array. After obtaining the position of the numerical interval, the terminal can determine the two target phase values ​​that are closest to the target phase difference among multiple target phase values, and then filter out the target phase average values ​​that match the target phase difference from the two target phase values ​​that are closest to the target phase difference.

[0122] For example, if the target phase averages are A, B, C, and D, where A is less than B, B is less than C, and C is less than D, the matching array is {A, B, C, D}. The target phase difference is compared sequentially with the average of the matching values ​​to determine that the target phase difference falls within the range of B and C in the matching array. The two target phase differences closest to the target phase difference are then B and C. Finally, the target phase averages that match the target phase difference are selected from B and C.

[0123] It should be understood that after obtaining the target phase average value, the terminal can arrange the values ​​sequentially according to their magnitude to obtain a matching array. Alternatively, the terminal can obtain the target phase difference first, and then arrange the target phase average value sequentially according to its magnitude to obtain a matching array. This embodiment does not impose any limitations on this.

[0124] In this embodiment, a matching array is obtained by arranging the target phase average value corresponding to each reference calibration macro in order of numerical value. Then, the position of the target phase difference in the numerical range of the matching array is determined. Finally, the target phase average value matching the target phase difference is determined based on the position of the numerical range. This eliminates the need to compare the target phase difference with the average value after the position of the array range, thereby reducing the amount of calculation and obtaining the target phase average value matching the target phase difference more quickly.

[0125] In other embodiments, determining the position of the target phase difference within a numerical interval in the matching array, and determining the average target phase value matching the target phase difference based on the position of the numerical interval, includes:

[0126] The target phase difference is compared with the average value in the matching array in turn;

[0127] If the target phase difference is greater than the first average value and less than the second average value, then the first difference between the target phase difference and the first average value is determined, and the second difference between the target phase difference and the second average value is determined. The first average value and the second average value are two adjacent average values ​​located in the numerical range in the matching array.

[0128] If the absolute value of the first difference is greater than the absolute value of the second difference, then the second average value is taken as the target phase average value that matches the target phase difference;

[0129] If the absolute value of the first difference is less than the absolute value of the second difference, then the first average value is taken as the target phase average value that matches the target phase difference.

[0130] The terminal can start by comparing the target phase difference with the average values ​​in the matching array, one by one, starting from the first average value of the matching array. Alternatively, the terminal can start by comparing the target phase difference with the average values ​​in the matching array, one by one, starting from the last average value of the matching array.

[0131] For example, if the target phase averages are A, B, C, and D, where A is less than B, B is less than C, and C is less than D, the matching array is {A, B, C, D}. The terminal first compares the target phase difference with the first average A in the matching array. If the target phase difference is greater than A, it compares it with B. If the target phase difference is still greater than B, it compares it with C. If the target phase difference is less than C, then the target phase difference falls within the range between B and C in the matching array; that is, B is the first average, and C is the second average. The absolute value of the first difference between the target phase difference and B is greater than the absolute value of the second difference between the target phase difference and C. Therefore, C is taken as the target phase average that matches the target phase difference. At this point, there is no need to compare the target phase difference with the average D that follows in the range, thus reducing computation.

[0132] Alternatively, the terminal first compares the target phase difference with the last average value D. If the target phase difference is less than D, it compares it with C. If the target phase difference is still less than C, it compares it with B. If the target phase difference is greater than B, then the target phase difference falls within the numerical range between B and C in the matching array. That is, B is the first average value, and C is the second average value. The absolute value of the first difference between the target phase difference and B is greater than the absolute value of the second difference between the target phase difference and C. Therefore, C is taken as the target phase average value that matches the target phase difference. In this case, there is no need to compare the target phase difference with the average value A that follows the numerical range, thus reducing the amount of computation.

[0133] Optionally, the terminal can directly calculate the difference between the target phase difference and the first average value and the last average value of the matching array. If the difference between the target phase difference and the first average value is less than the difference between the target phase difference and the last average value, the terminal can start from the first average value of the matching array and compare the target phase difference with the average values ​​in the matching array sequentially. If the difference between the target phase difference and the first average value is greater than the difference between the target phase difference and the last average value, the terminal can start from the last average value of the matching array and compare the target phase difference with the average values ​​in the matching array sequentially, thereby enabling a faster finding of the target phase average value that matches the target phase difference.

[0134] In other embodiments, selecting calibration phase differences that match the target phase difference from the calibration dataset based on the target phase value includes:

[0135] Determine the confidence level of the target phase difference;

[0136] If the confidence level is equal to or greater than the preset threshold, then the calibration phase difference that matches the target phase difference is selected from the calibration data set based on the target phase value.

[0137] The confidence level of the target phase difference is used to measure its reliability. A higher confidence level indicates greater reliability. The terminal can substitute the target phase difference into a preset function (such as a Gaussian function) to obtain its confidence level. Alternatively, the terminal can look up the corresponding confidence level for the target phase difference in a preset mapping table.

[0138] The preset threshold can be selected according to the actual situation. For example, in this embodiment, the preset threshold is set to 60. This embodiment does not limit this.

[0139] If the confidence level of the target phase difference is equal to or greater than the preset threshold, it means that the target phase difference is reliable. Then, based on the target phase value, a calibration phase difference that matches the target phase difference is selected from the calibration dataset. If the confidence level of the target phase difference is less than the preset threshold, it means that the target phase difference is unreliable. Then, the target phase difference is discarded, and a new target phase difference is obtained.

[0140] Therefore, in some other embodiments, after determining the confidence level of the target phase difference, the method further includes:

[0141] If the confidence level is less than the preset threshold, then update the number of times the target phase difference is acquired;

[0142] If the number of acquisitions is less than or equal to the preset number of acquisitions, return to the step of acquiring the target phase difference of the preview image captured by the main camera in macro shooting mode;

[0143] If the number of acquisition attempts exceeds the preset number, the main camera lens will be moved to the target focus position using the preset focus strategy.

[0144] When the confidence level of the target phase difference is less than the preset threshold, a new target phase difference can be obtained. However, if the confidence level of the target phase difference is always less than the preset threshold, there may be problems with focusing by the target phase difference. In this case, focusing can be performed by using a preset focusing strategy.

[0145] Therefore, in this embodiment, the number of times a new target phase difference is acquired is limited to prevent the acquisition of new target phase differences indefinitely, thereby avoiding continuous phase focusing. Specifically, when the confidence level is less than a preset threshold and the number of times the target phase difference is acquired is less than or equal to a preset number, the step of acquiring the target phase difference of the preview image captured by the main camera in macro shooting mode is then executed. If the confidence level is less than the preset threshold and the number of times the target phase difference is acquired is greater than the preset number, it means that focusing through the target phase difference may have problems. In this case, focusing can be performed directly using the preset focusing strategy.

[0146] The preset focus strategy can be selected according to the actual situation. For example, the preset focus strategy can be contrast detection auto focus (CDAF) or laser detection auto focus (LDAF) as the preset focus strategy in this embodiment. This embodiment does not limit it.

[0147] Updating the number of times the target phase difference is acquired can refer to incrementing the number of times the target phase difference is acquired by 1, or it can refer to incrementing the number of times the target phase difference is acquired by 10. This embodiment does not limit this.

[0148] S204. Drive the main camera lens to focus based on the target current.

[0149] After receiving the target current, if the current position of the object being photographed is the same as the position of the reference macro lens, the terminal can directly drive the motor to move the main camera lens to the target focus position based on the target current. If the current position of the object being photographed is different from the position of the reference macro lens, the terminal drives the motor to move the main camera lens to a candidate position based on the target current. There may still be a certain distance between the candidate position and the target focus position. In this case, the main camera lens can be moved from the candidate position to the target focus position again using a preset focusing strategy. Alternatively, the main camera lens can remain stationary once it has moved to the candidate position.

[0150] When there is a certain distance between the candidate position and the target focus position, the main camera lens is driven to focus based on the target current, including:

[0151] The main camera lens is moved to the candidate position based on the target current.

[0152] Adjust the main camera lens based on the candidate position until the main camera lens reaches the target focus position.

[0153] The process of adjusting the main camera lens based on the candidate position until the main camera lens reaches the target focus position includes:

[0154] Obtain the candidate phase difference of the preview image captured by the main camera at the candidate position;

[0155] If the candidate phase difference meets the preset phase threshold, the candidate position is determined to be the target focus position, and the main camera lens is stopped moving.

[0156] If the phase difference between the candidates does not meet the preset phase threshold, the candidate position is determined not to be the target focus position, and the main camera is moved to the target focus position using the preset focus strategy.

[0157] When the preset focus strategy is contrast-based focus, the main camera lens is moved to the target focus position using the preset focus strategy, including:

[0158] Based on the preset focusing strategy, the contrast difference of the preview images captured by the main camera at the candidate position is obtained;

[0159] Based on the contrast difference, the main camera lens is moved to the target focus position.

[0160] In this embodiment, the main camera lens is first moved to the candidate position based on the target phase difference, and then a preset focusing strategy is used to move the main camera lens from the candidate position to the target focusing position. Compared with directly using the preset focusing strategy, the main camera lens can be moved from the candidate position to the target focusing position more quickly.

[0161] As described above, in this embodiment, the target phase difference of the preview image captured by the main camera in macro shooting mode is first obtained. Then, the calibration data set corresponding to the macro shooting mode is obtained, which includes the calibration phase difference and calibration current of the reference macro. Next, the target current is determined based on the calibration current corresponding to the calibration phase difference that matches the target phase difference. Finally, the main camera is driven to focus according to the target current.

[0162] In this embodiment of the application, since the calibration data set includes the calibration phase difference and calibration current of the reference calibration macro, the main camera lens can be driven to focus in the macro range based on the target phase difference, calibration phase difference and calibration current. Thus, the macro shooting function can be realized through the main camera lens, without the need for a macro camera, which reduces the cost.

[0163] Based on the methods described in the above embodiments, the following examples will provide further detailed explanations.

[0164] Please see Figure 3 , Figure 3 This is a schematic flowchart illustrating the lens focusing method provided in an embodiment of this application. The lens focusing method may include:

[0165] S301. When macro shooting mode is detected, the terminal reads the calibration current corresponding to the maximum test macro distance and the calibration current corresponding to the minimum test macro distance from the calibration data set in the memory, and generates a motor lookup table based on the calibration current corresponding to the maximum test macro distance and the calibration current corresponding to the minimum test macro distance.

[0166] The maximum test macro distance can be used as the telephoto focal length, and the minimum test macro distance can be used as the near focal length.

[0167] S302. The terminal reads the calibration phase difference corresponding to each reference calibration micrometer from the calibration data set in the memory, and arranges the calibration phase difference corresponding to each reference calibration micrometer into a 6*8 two-dimensional array to obtain an array. The average value of the calibration phase difference at the center four positions of the array is taken as the target phase average value corresponding to the calibration phase difference of the reference calibration micrometer.

[0168] S303. The terminal arranges the target phase average of the calibration phase difference of each reference calibration macro in ascending order to obtain a matching array.

[0169] S304. The terminal reads the calibration current corresponding to the maximum test micro distance and the calibration current corresponding to the minimum test micro distance from the motor lookup table, and uses the average value of the calibration current corresponding to the maximum test micro distance and the calibration current corresponding to the minimum test micro distance as the current value corresponding to the initial position.

[0170] S305. The terminal drives the motor to move the main camera lens to the initial position according to the current value corresponding to the initial position.

[0171] S306. The terminal acquires a preview image of the object being photographed through the main camera lens, determines multiple initial phase differences of the preview image, takes the largest initial phase difference among the multiple initial phase differences as the target phase difference, and determines the confidence level of the target phase difference.

[0172] S307. The terminal determines whether the confidence level is equal to or greater than the preset threshold.

[0173] S308. If the confidence level is equal to or greater than the preset threshold, the terminal compares the target phase difference with the average value in the matching array once.

[0174] S309. If the target phase difference is greater than the first average value and less than the second average value, the terminal determines the first difference between the target phase difference and the first average value, and determines the second difference between the target phase difference and the second average value, wherein the first average value and the second average value are two adjacent average values ​​in the matching array.

[0175] S3010. If the absolute value of the first difference is greater than the absolute value of the second difference, the terminal uses the second average value as the target phase average value to match the target phase difference. If the absolute value of the first difference is less than the absolute value of the second difference, the first average value is used as the target phase average value to match the target phase difference.

[0176] S3011. The terminal takes the calibration current corresponding to the calibration phase difference corresponding to the target phase average value as the target current, and drives the motor to move the main camera lens to the candidate position according to the target current.

[0177] S3012. The terminal modifies the confidence level to 1. When the terminal detects that the confidence level is 1, the terminal focuses based on the contrast and moves the main camera lens from the candidate position to the target focus position.

[0178] S3013. If the confidence level is less than the preset threshold, the terminal will increment the number of times the target phase difference is acquired by 1 and determine whether the number of acquisitions is greater than the preset number.

[0179] S3014. If the number of acquisitions is less than or equal to the preset number, the terminal returns to step S306.

[0180] If the number of acquisitions is equal to or greater than the preset number, the terminal will focus based on the contrast and move the main camera lens from the initial position to the target focus position.

[0181] The specific implementation process and corresponding beneficial effects in this embodiment can be referred to the above-described lens focusing method embodiment, but this embodiment is not limited here.

[0182] To facilitate better implementation of the lens focusing method provided in the embodiments of this application, the embodiments of this application also provide an apparatus based on the above-described lens focusing method. The meanings of the terms used are the same as in the lens focusing method described above, and specific implementation details can be found in the descriptions within the method embodiments.

[0183] For example, such as Figure 4 As shown, the lens focusing device may include:

[0184] The first acquisition module 401 is used to acquire the target phase difference of the preview image captured by the main camera lens in macro shooting mode.

[0185] The second acquisition module 402 is used to acquire the calibration data set corresponding to the macro shooting mode. The calibration data set includes the calibration phase difference and calibration current of the reference calibration macro.

[0186] The current determination module 403 is used to determine the target current based on the calibration current corresponding to the calibration phase difference that matches the target phase difference.

[0187] The lens focusing module 404 is used to drive the main camera lens to focus based on the target current.

[0188] Optionally, the lens focusing module 404 is specifically used to perform:

[0189] The main camera lens is moved to the candidate position based on the target current.

[0190] Adjust the main camera lens based on the candidate position until the main camera lens reaches the target focus position.

[0191] Optionally, the lens focusing module 404 is specifically used to perform:

[0192] Obtain the candidate phase difference of the preview image captured by the main camera at the candidate position;

[0193] If the candidate phase difference meets the preset phase threshold, the candidate position is determined to be the target focus position, and the main camera lens is stopped moving.

[0194] If the phase difference between the candidates does not meet the preset phase threshold, the candidate position is determined not to be the target focus position, and the main camera is moved to the target focus position using the preset focus strategy.

[0195] Optionally, the lens focusing module 404 is specifically used to perform:

[0196] Based on the preset focusing strategy, the contrast difference of the preview images captured by the main camera at the candidate position is obtained;

[0197] Based on the contrast difference, the main camera lens is moved to the target focus position.

[0198] Optionally, there may be multiple reference calibration micros, each corresponding to multiple calibration phase differences and one calibration current.

[0199] Accordingly, the lens focusing device also includes:

[0200] The matching module is used to perform:

[0201] Perform arithmetic operations on the multiple calibration phase differences corresponding to the reference calibration macro to obtain the target phase value;

[0202] Based on the target phase value, the calibration phase difference that matches the target phase difference is selected from the calibration dataset.

[0203] Optionally, the matching module is specifically used to perform:

[0204] The target phase difference is matched with the target phase value corresponding to each reference calibration macro to obtain the target phase value that matches the target phase difference;

[0205] Based on the target phase value that matches the target phase difference, the calibration phase difference that matches the target phase difference is selected from the calibration dataset.

[0206] Optionally, the target phase value is the average value of the target phase.

[0207] Accordingly, the matching module is specifically used to perform:

[0208] Obtain the matching array by arranging the average target phase values ​​corresponding to each reference calibration macro in order of numerical magnitude;

[0209] Determine the position of the target phase difference within the numerical range of the matching array;

[0210] Based on the position of the numerical interval, determine the average value of the target phase that matches the target phase difference.

[0211] Optionally, the matching module is specifically used to perform:

[0212] The target phase difference is compared with the average value in the matching array in turn;

[0213] If the target phase difference is greater than the first average value and less than the second average value, then the first difference between the target phase difference and the first average value is determined, and the second difference between the target phase difference and the second average value is determined. The first average value and the second average value are two adjacent average values ​​located in the numerical range in the matching array.

[0214] If the absolute value of the first difference is greater than the absolute value of the second difference, then the second average value is taken as the target phase average value that matches the target phase difference;

[0215] If the absolute value of the first difference is less than the absolute value of the second difference, then the first average value is taken as the target phase average value that matches the target phase difference.

[0216] Optionally, the target phase value is the average value of the target phase.

[0217] Accordingly, the matching module is specifically used to perform:

[0218] The multiple calibration phase differences corresponding to each reference calibration macro are arranged according to a preset rule to obtain the permutation array corresponding to each reference calibration macro.

[0219] Based on the average value of the calibration phase difference at the preset position in the permutation array, calculate the target phase average value of multiple calibration phase differences corresponding to the reference calibration macro.

[0220] Optionally, the matching module is specifically used to perform:

[0221] Determine the confidence level of the target phase difference;

[0222] If the confidence level is equal to or greater than the preset threshold, then the calibration phase difference that matches the target phase difference is selected from the calibration data set based on the target phase value.

[0223] Optionally, the matching module is also used to perform:

[0224] If the confidence level is less than the preset threshold, then update the number of times the target phase difference is acquired;

[0225] If the number of acquisitions is less than or equal to the preset number of acquisitions, return to the step of acquiring the target phase difference of the preview image captured by the main camera in macro shooting mode;

[0226] If the number of acquisitions exceeds the preset number, a preset focusing strategy will be used to move the main camera lens to the target focus position.

[0227] Optionally, the first acquisition module 401 is specifically used to perform:

[0228] Determine multiple initial phase differences in the preview image captured by the main camera lens in macro shooting mode;

[0229] The largest initial phase difference among multiple initial phase differences is used as the target phase difference of the preview image.

[0230] Optionally, the first acquisition module 401 is specifically used to perform:

[0231] Determine multiple initial phase differences in the preview image captured by the main camera lens in macro shooting mode;

[0232] The average of multiple initial phase differences is used as the target phase difference of the preview image.

[0233] Optionally, the lens focusing device also includes:

[0234] The set determination module is used for execution:

[0235] Acquire multiple test macro shots in macro shooting mode;

[0236] Select a reference calibration macro from multiple test macros;

[0237] Move the main camera lens to the initial position for capturing the preview image, and take a picture of the subject located at the reference calibration macro position to obtain a calibration image of the subject;

[0238] Based on the calibration image, determine the calibration phase difference and calibration current of the reference calibration macro.

[0239] Based on the calibration phase difference and calibration current of the reference calibration macro, determine the calibration data set corresponding to the macro shooting mode.

[0240] Optionally, the set determination module is specifically used to execute:

[0241] Based on the calibration image, determine the calibration phase difference corresponding to the reference calibration macro.

[0242] The main camera lens is moved according to the moving current until it reaches the initial focus position corresponding to the reference macro.

[0243] Use the moving current corresponding to the initial focusing position as the reference calibration current corresponding to the macro.

[0244] If multiple test macros have not been completely filtered, return to the step of filtering the reference calibration macro from multiple test macros;

[0245] If multiple test macros have been selected, the calibration data set corresponding to the macro shooting mode is determined based on the calibration phase difference and calibration current of the reference calibration macro.

[0246] Optionally, the set determination module is specifically used to execute:

[0247] The maximum and minimum test macro distances are selected from multiple test macro distances;

[0248] The initial position is determined based on the focusing position corresponding to the maximum test macro distance and the focusing position corresponding to the minimum test macro distance.

[0249] Optionally, the set determination module is specifically used to execute:

[0250] Determine the device type for the main camera lens;

[0251] Determine the calibration data set corresponding to the macro shooting mode based on the device type.

[0252] In practice, each of the above modules can be implemented as an independent entity or can be combined arbitrarily to be implemented as the same or several entities. For the specific implementation methods and corresponding beneficial effects of each of the above modules, please refer to the previous method embodiments, which will not be repeated here.

[0253] This application also provides an electronic device, which may be a server or a terminal, etc. Figure 5 As shown, it illustrates a structural schematic diagram of the electronic device involved in the embodiments of this application, specifically:

[0254] The electronic device may include components such as a processor 501 with one or more processing cores, a memory 502 with one or more computer-readable storage media, a power supply 503, and an input unit 504. Those skilled in the art will understand that... Figure 5 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0255] The processor 501 is the control center of the electronic device, connecting various parts of the device via various interfaces and lines. It executes computer programs and / or modules stored in the memory 502, and calls data stored in the memory 502, to perform various functions and process data. Optionally, the processor 501 may include one or more processing cores; preferably, the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 501.

[0256] The memory 502 can be used to store computer programs and modules. The processor 501 executes various functional applications and data processing by running the computer programs and modules stored in the memory 502. The memory 502 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, computer programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 502 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 502 may also include a memory controller to provide the processor 501 with access to the memory 502.

[0257] The electronic device also includes a power supply 503 that supplies power to various components. Preferably, the power supply 503 can be logically connected to the processor 501 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 503 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0258] The electronic device may also include an input unit 504, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0259] Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 501 in the electronic device loads the executable files corresponding to the processes of one or more computer programs into the memory 502 according to the following instructions, and the processor 501 runs the computer programs stored in the memory 502 to realize various functions, such as:

[0260] Obtain the target phase difference in the preview image captured by the main camera lens in macro shooting mode;

[0261] Obtain the calibration data set corresponding to the macro shooting mode. The calibration data set includes the calibration phase difference and calibration current of the reference calibration macro.

[0262] The target current is determined based on the calibration current corresponding to the calibration phase difference that matches the target phase difference;

[0263] The main camera lens is driven to focus based on the target current.

[0264] For details on the specific implementation methods and corresponding beneficial effects of each of the above operations, please refer to the detailed description of the lens focusing method above, which will not be repeated here.

[0265] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by a computer program, or by a computer program controlling related hardware. The computer program can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0266] Therefore, embodiments of this application provide a computer-readable storage medium storing a computer program that can be loaded by a processor to execute the steps of any lens focusing method provided in embodiments of this application. For example, the computer program can execute the following steps:

[0267] Obtain the target phase difference in the preview image captured by the main camera lens in macro shooting mode;

[0268] Obtain the calibration data set corresponding to the macro shooting mode. The calibration data set includes the calibration phase difference and calibration current of the reference calibration macro.

[0269] The target current is determined based on the calibration current corresponding to the calibration phase difference that matches the target phase difference;

[0270] The main camera lens is driven to focus based on the target current.

[0271] For details on the specific implementation methods and corresponding beneficial effects of the above operations, please refer to the previous embodiments, which will not be repeated here.

[0272] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0273] Since the computer program stored in the computer-readable storage medium can execute the steps in any of the lens focusing methods provided in the embodiments of this application, the beneficial effects that any of the lens focusing methods provided in the embodiments of this application can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.

[0274] According to one aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the aforementioned lens focusing method.

[0275] The foregoing has provided a detailed description of a lens focusing method, apparatus, electronic device, and computer-readable storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A lens focusing method, characterized in that, include: Obtain the target phase difference in the preview image captured by the main camera lens in macro shooting mode; Obtain the calibration data set corresponding to the macro shooting mode. The calibration data set includes the calibration phase difference and calibration current of the reference calibration macro. There are multiple reference calibration macros, and each reference calibration macro corresponds to multiple calibration phase differences and one calibration current. Performing arithmetic operations on multiple calibration phase differences corresponding to the reference calibration macro to obtain a target phase value includes: arranging the multiple calibration phase differences corresponding to each reference calibration macro according to a preset rule to obtain an array corresponding to each reference calibration macro; calculating the target phase average value of the multiple calibration phase differences corresponding to the reference calibration macro based on the average value of the calibration phase differences at preset positions in the array; the target phase value is the target phase average value. Based on the target phase value, a calibration phase difference matching the target phase difference is selected from the calibration data set. The target current is determined based on the calibration current corresponding to the calibration phase difference that matches the target phase difference; The main camera lens is driven to focus according to the target current.

2. The lens focusing method according to claim 1, characterized in that, The step of driving the main camera lens to focus based on the target current includes: The main camera lens is driven to move to the candidate position according to the target current; Adjust the main camera lens based on the candidate position until the main camera lens reaches the target focus position.

3. The lens focusing method according to claim 2, characterized in that, The step of adjusting the main camera lens based on the candidate position until the main camera lens reaches the target focus position includes: Obtain the candidate phase difference of the preview image captured by the main camera lens at the candidate position; If the candidate phase difference meets the preset phase threshold, then the candidate position is determined to be the target focus position, and the movement of the main camera lens is stopped; If the candidate phase difference does not meet the preset phase threshold, then the candidate position is determined not to be the target focus position, and the main camera lens is moved to the target focus position using a preset focusing strategy.

4. The lens focusing method according to claim 3, characterized in that, The step of moving the main camera lens to the target focus position using a preset focus strategy includes: Based on a preset focusing strategy, the contrast difference of the preview image captured by the main camera lens at the candidate position is obtained; Based on the contrast difference, the main camera lens is moved to the target focus position.

5. The lens focusing method according to claim 1, characterized in that, The step of selecting calibration phase differences that match the target phase difference from the calibration data set based on the target phase value includes: The target phase difference is matched with the target phase value corresponding to each of the reference calibration micrometers to obtain the target phase value that matches the target phase difference; Based on the target phase value that matches the target phase difference, the calibration phase difference that matches the target phase difference is selected from the calibration data set.

6. The lens focusing method according to claim 5, characterized in that, The target phase value is the average target phase value; The step of matching the target phase difference with the target phase value corresponding to each of the reference calibration macros to obtain the target phase value that matches the target phase difference includes: Obtain the matching array by arranging the target phase average values ​​corresponding to each of the reference calibration macros in order of numerical value; Determine the position of the target phase difference within the numerical range of the matching array; Based on the position of the numerical interval, determine the average value of the target phase that matches the target phase difference.

7. The lens focusing method according to claim 6, characterized in that, Determining the position of the target phase difference within the numerical range of the matching array, and determining the average target phase value matching the target phase difference based on the position of the numerical range, includes: The target phase difference is compared sequentially with the average value in the matching array; If the target phase difference is greater than the first average value and less than the second average value, then a first difference between the target phase difference and the first average value is determined, and a second difference between the target phase difference and the second average value is determined, wherein the first average value and the second average value are two adjacent average values ​​located in the numerical range position in the matching array; If the absolute value of the first difference is greater than the absolute value of the second difference, then the second average value is taken as the target phase average value that matches the target phase difference; If the absolute value of the first difference is less than the absolute value of the second difference, then the first average value is taken as the target phase average value that matches the target phase difference.

8. The lens focusing method according to claim 1, characterized in that, The step of selecting calibration phase differences that match the target phase difference from the calibration data set based on the target phase value includes: Determine the confidence level of the target phase difference; If the confidence level is equal to or greater than a preset threshold, then a calibration phase difference that matches the target phase difference is selected from the calibration data set based on the target phase value.

9. The lens focusing method according to claim 8, characterized in that, After determining the confidence level of the target phase difference, the method further includes: If the confidence level is less than the preset threshold, then update the number of times the target phase difference is acquired; If the number of acquisitions is less than or equal to the preset number of acquisitions, then return to the step of acquiring the target phase difference of the preview image captured by the main camera lens in macro shooting mode; If the number of acquisitions exceeds the preset number, a preset focusing strategy is used to move the main camera lens to the target focusing position.

10. The lens focusing method according to claim 1, characterized in that, The acquisition of the target phase difference in the preview image captured by the main camera lens in macro shooting mode includes: Determine multiple initial phase differences in the preview image captured by the main camera lens in macro shooting mode; The largest initial phase difference among the multiple initial phase differences is taken as the target phase difference of the preview image.

11. The lens focusing method according to claim 1, characterized in that, The acquisition of the target phase difference in the preview image captured by the main camera lens in macro shooting mode includes: Determine multiple initial phase differences in the preview image captured by the main camera lens in macro shooting mode; The average of the multiple initial phase differences is used as the target phase difference of the preview image.

12. The lens focusing method according to any one of claims 1-11, characterized in that, Before acquiring the calibration data set corresponding to the macro shooting mode, the method further includes: Acquire multiple test macro shots under the macro shooting mode; The reference calibration macro is selected from among the multiple test macros; The main camera lens is moved to the initial position for acquiring the preview image, and the subject located at the reference calibration macro position is photographed to obtain a calibration image of the subject. Based on the calibration image, determine the calibration phase difference and calibration current of the reference calibration macro. Based on the calibration phase difference and calibration current of the reference calibration macro, the calibration data set corresponding to the macro shooting mode is determined.

13. The lens focusing method according to claim 12, characterized in that, The step involves determining the calibration phase difference and calibration current of the reference calibration macro based on the calibration image, and determining the calibration data set corresponding to the macro shooting mode based on the calibration phase difference and calibration current of the reference calibration macro, including: Based on the calibration image, determine the calibration phase difference corresponding to the reference calibration macro. The main camera lens is moved according to the moving current until it reaches the initial focus position corresponding to the reference calibration macro. The moving current corresponding to the initial focusing position is used as the calibration current corresponding to the reference calibration macro. If multiple test macros have not been completely filtered, then return to the step of filtering the reference calibration macro from the multiple test macros; If multiple test macros have been selected, the calibration data set corresponding to the macro shooting mode is determined based on the calibration phase difference and calibration current of the reference calibration macro.

14. The lens focusing method according to claim 12, characterized in that, Before moving the main camera lens to the initial position for capturing the preview image, the method further includes: The maximum and minimum test macro distances are selected from a plurality of the test macro distances; The initial position is determined based on the focusing position corresponding to the maximum test macro distance and the focusing position corresponding to the minimum test macro distance.

15. The lens focusing method according to claim 1, characterized in that, Before acquiring the target phase difference of the preview image captured by the main camera lens in macro shooting mode, the method further includes: Determine the device type of the main camera lens; Based on the device type, determine the calibration data set corresponding to the macro shooting mode.

16. A lens focusing device, characterized in that, include: The first acquisition module is used to acquire the target phase difference of the preview image captured by the main camera lens in macro shooting mode; The second acquisition module is used to acquire the calibration data set corresponding to the macro shooting mode. The calibration data set includes the calibration phase difference and calibration current of the reference calibration macro. The reference calibration macro includes multiple reference calibration macros, and each reference calibration macro corresponds to multiple calibration phase differences and one calibration current. The matching module is used to perform the following: performing arithmetic operations on multiple calibration phase differences corresponding to the reference calibration macro to obtain a target phase value, including: arranging the multiple calibration phase differences corresponding to each reference calibration macro according to a preset rule to obtain an array corresponding to each reference calibration macro; calculating the target phase average value of the multiple calibration phase differences corresponding to the reference calibration macro based on the average value of the calibration phase differences at preset positions in the array; the target phase value is the target phase average value. The matching module is further configured to perform: filtering out calibration phase differences that match the target phase difference from the calibration data set based on the target phase value; A current determination module is used to determine the target current based on the calibration current corresponding to the calibration phase difference that matches the target phase difference; The lens focusing module is used to drive the main camera lens to focus according to the target current.

17. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a computer program, and the processor running the computer program in the memory to perform the lens focusing method according to any one of claims 1 to 15.

18. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program adapted for loading by a processor to perform the lens focusing method according to any one of claims 1 to 15.