Focusing Method, Device, and Storage Medium
By subdividing the target block and evaluating the phase difference value, the target focus area is determined, and the problems of slow focus speed and insufficient clarity in the prior art are solved, fast and accurate focusing effect is achieved, and the efficiency and imaging quality of the automatic focus system are improved.
Patent Information
- Application Number
- CN202510081404.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-20
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2045-01-20
AI Technical Summary
Existing autofocus technologies are difficult to quickly and accurately focus on a better area of interest in the target block, especially in complex scenarios, resulting in insufficient clarity, slow focus speed and poor focus accuracy.
By further dividing the target blocks that need to be focused, multiple target sub-blocks in the target block are determined, the original image pixels of the target block are obtained, the focus state of each area to be focused based on the phase difference value, and the target focus area is determined based on the phase difference value to focus.
It realizes a better area of interest in the target block quickly and accurately in complex scenes, improves the focus efficiency and imaging quality of the autofocus system, and avoids the problems of slow focus speed and insufficient clarity in traditional methods.
Smart Images

Figure CN119520991B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of video image focusing, and particularly to a focusing method, device, and storage medium. Background Art
[0002] In modern optical technology devices, the autofocus system is one of the key components and is widely used in cameras, smartphones, and other image capture devices. The main goal of autofocus technology is to quickly and accurately adjust the lenses in the camera to obtain a clear image. With the continuous development of focusing technology, three main methods are widely used in products on the market: contrast detection autofocus (CDAF), time-of-flight autofocus (TOFAF), and phase detection autofocus (PDAF).
[0003] CDAF relies on the contrast change in the image sensor to achieve autofocus. This focusing method has a low cost and wide application, but the focusing speed is slow, and continuous adjustment is required to obtain a clear image. At the same time, its performance is poor in low-light environments, and the phenomenon of repeated focusing back and forth is likely to occur; TOFAF measures the distance by emitting and receiving lasers to perform focusing adjustment, and is usually used in high-demand environments, such as scenarios that require fast focusing. However, this focusing method depends greatly on ambient light and reflective surfaces, which affects the focusing accuracy in some cases, and the hardware design is complex, resulting in a high manufacturing cost; PDAF relies on light entering the image sensor through different paths to compare the phase difference to achieve focusing. However, when using an ordinary image sensor, the focusing accuracy is poor. Although using a high-end image sensor can improve the focusing accuracy, it also significantly increases the cost. And no matter which sensor is used, it is impossible to focus on the better region of interest of the target block. For example, when a user is having a video call and places a small object at the relatively central position in the front of the target block of the lens for others to view, the general public hopes that the small object should be clearly focused. Since this small object only occupies a small part of the area of the target block and is affected by the large area of the background, the ordinary PDAF method generally can only make the small object and the background as a whole target block have a clear focusing effect, but the clarity of the small object in the front is relatively insufficient.
[0004] Therefore, how to quickly focus on the better region of interest of the target block is an urgent problem to be solved at present. Summary of the Invention
[0005] The main purpose of this application is to provide a focusing method, device, and storage medium, aiming to solve the technical problem of how to quickly focus on the better region of interest of the target block.
[0006] To achieve the above object, this application proposes a focusing method, and the focusing method includes:
[0007] Determine the target block to be focused on in the current frame of the video data, as well as multiple target sub-blocks in the target block, to obtain a set of regions to be focused on, where each target sub-block is obtained by dividing the target block;
[0008] Obtain the original image pixels of the target block, and determine the phase difference of each region to be focused on in the set of regions to be focused on based on the original image pixels, where each region to be focused on includes the target block and each target sub-block;
[0009] Determine the target focus region according to each phase difference, and perform focusing on the target focus region.
[0010] In one embodiment, the step of determining the phase difference of each region to be focused on in the set of regions to be focused on based on the original image pixels includes:
[0011] Separate the original image pixels based on the pixel type to obtain the phase detection pixels of the target block;
[0012] Based on the phase detection pixels of the target block, determine the phase detection pixels of each region to be focused on in the set of regions to be focused on, and convert each phase detection pixel into a corresponding phase difference to obtain the phase difference of each region to be focused on.
[0013] In one embodiment, the step of determining the target focus region according to each phase difference includes:
[0014] For any region to be focused on, compare the confidence level of the region to be focused on with a preset confidence threshold, where the confidence level is determined based on the original image pixels of the region to be focused on;
[0015] After traversing each region to be focused on, if only one candidate region to be focused on among the regions to be focused on has a confidence level greater than the preset confidence threshold, then use the target block as the target focus region;
[0016] If the confidence levels of multiple candidate regions to be focused on among the regions to be focused on are all greater than the preset confidence threshold, then use the target sub-block with the smallest phase difference among the candidate regions to be focused on as the target focus region.
[0017] In one embodiment, after the step of determining the target focus region according to each phase difference, the following steps are further included:
[0018] When the target region is any target sub-block, divide the target sub-block to obtain multiple sub-regions in the target sub-block;
[0019] For any sub-region, determine the phase difference and confidence level of the sub-region, and compare the confidence level of the sub-region with a preset confidence level threshold;
[0020] After traversing each sub-region, if there is only one candidate sub-region among the sub-regions whose confidence level is greater than the preset confidence level threshold, update the target focus region based on the candidate sub-region;
[0021] If there are multiple candidate sub-regions among the sub-regions whose confidence levels are all greater than the preset confidence level threshold, update the target focus region based on the candidate sub-region with the smallest phase difference among the candidate sub-regions.
[0022] In one embodiment, the step of focusing on the target focus region includes:
[0023] Determine the moving stroke value of the focusing motor based on the phase difference of the target focus region;
[0024] Execute the moving stroke value through the focusing motor to control the lens to focus on the target focus region through the focusing motor.
[0025] In one embodiment, the step of determining the moving stroke value of the focusing motor based on the phase difference of the target focus region includes:
[0026] Based on the difference between the phase difference of the target focus region and the target value, determine the first input of the preset PID position loop, and calculate the adjustment speed based on the first input through the preset PID position loop;
[0027] Obtain the current moving speed of the focusing motor, and based on the difference between the adjustment speed and the current moving speed, determine the second input of the preset PID speed loop, and calculate the moving stroke value of the focusing motor based on the second input through the preset PID speed loop.
[0028] In one embodiment, after the step of calculating the adjustment speed based on the first input through the preset PID position loop, the following steps are further included:
[0029] Compare the adjustment speed with a preset speed threshold;
[0030] In the case where the adjustment speed is greater than the preset speed threshold, adjust the adjustment speed to the preset speed threshold.
[0031] In one embodiment, after the step of calculating the moving stroke value of the focusing motor based on the second input through the preset PID speed loop, the following steps are further included:
[0032] Compare the moving stroke value with a preset stroke value threshold;
[0033] When the moving stroke value is greater than the preset stroke value threshold, adjust the moving stroke value to the preset stroke value threshold.
[0034] In addition, to achieve the above object, the present application further provides an electronic device, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and the computer program is configured to implement the steps of the focusing method as described above.
[0035] In addition, to achieve the above object, the present application further provides a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium, and when the computer program is executed by a processor, it implements the steps of the focusing method as described above.
[0036] In addition, to achieve the above object, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the steps of the focusing method as described above.
[0037] One or more technical solutions proposed by the present application have at least the following technical effects:
[0038] The present application first determines a target block to be focused in the current frame of video data and multiple target sub-blocks in the target block to obtain a set of regions to be focused, so as to divide the entire target block to be focused into multiple target sub-blocks by region division of the image, which is convenient for more accurately detecting the focusing state of each target sub-block, thereby achieving fast and accurate identification of small regions of interest to the user; then obtains the original image pixels of the target block and determines the phase difference of each region to be focused in the set of regions to be focused based on the original image pixels, so as to extract the phase information for focusing evaluation from the original image data, and ensure the accuracy of focusing evaluation by calculating the phase difference of the target block and each target sub-block, thereby achieving the effect of improving the focusing speed and accuracy; finally, determines the target focusing region according to each phase difference and focuses on the target focusing region to achieve the effect of determining a better target focusing region of interest based on the phase difference, thereby completing the precise focusing of the small region of interest to the user.
[0039] In summary, the present application further divides the target block to be focused into regions, and evaluates the phase differences of the divided target sub-blocks to reasonably determine a better region of interest for the user. Since there are smaller target sub-blocks, the granularity of the focus area is smaller, avoiding problems such as insufficient clarity of small regions of interest for the user, slow focus speed, and poor focus accuracy caused by overall focusing in traditional autofocus methods. The effect of quickly focusing on the better region of interest of the target block in a complex scene is achieved, improving the focus efficiency and imaging quality of the autofocus system. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings herein are incorporated into and constitute a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0041] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0042] Figure 1 It is a schematic flowchart provided for Embodiment 1 of the focusing method of the present application;
[0043] Figure 2 It is a schematic diagram of the target block of the focusing method provided for Embodiment 1 of the present application;
[0044] Figure 3 It is a schematic diagram of the target sub-block of the focusing method provided for Embodiment 1 of the present application;
[0045] Figure 4 It is a schematic flowchart of the phase difference acquisition of the focusing method provided for Embodiment 1 of the present application;
[0046] Figure 5 It is another schematic flowchart of the phase difference acquisition of the focusing method provided for Embodiment 1 of the present application;
[0047] Figure 6 It is a schematic flowchart provided for Embodiment 2 of the focusing method of the present application;
[0048] Figure 7 It is a schematic diagram of the sub-region of the target sub-block of the focusing method provided for Embodiment 2 of the present application;
[0049] Figure 8 It is a schematic flowchart provided for Embodiment 3 of the focusing method of the present application;
[0050] Figure 9 It is a schematic brief flowchart of the focusing method provided for Embodiment 3 of the present application;
[0051] Figure 10 Schematic diagram of the pixel acquisition process of the focusing method provided in the third embodiment of the present application;
[0052] Figure 11 Schematic diagram of the focusing algorithm process of the focusing method provided in the third embodiment of the present application;
[0053] Figure 12 Schematic diagram of the PID process of the focusing method provided in the third embodiment of the present application;
[0054] Figure 13 Schematic diagram of the device structure of the hardware operating environment involved in the focusing method in the embodiments of the present application.
[0055] The realization of the purpose, functional features and advantages of the present application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. Specific embodiments
[0056] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0057] In order to better understand the technical solutions of the present application, the following will be described in detail in conjunction with the accompanying drawings of the specification and specific embodiments.
[0058] The main solution of the embodiment of the present application is: determining a target block to be focused in the current frame of video data, and a plurality of target sub - blocks in the target block, to obtain a set of regions to be focused, where each target sub - block is obtained by dividing the target block; acquiring the original image pixels of the target block, and determining the phase difference of each region to be focused in the set of regions to be focused based on the original image pixels, where each region to be focused includes the target block and each target sub - block; determining a target focusing region according to each phase difference, and performing focusing on the target focusing region.
[0059] Since the prior art cannot focus on a better region of interest of the target block. For example, when a user is having a video communication and places a small object in the relatively central position in front of the target block of the camera for others to view, the general public usually hopes that the small object can be focused and imaged clearly. However, since this small object only occupies a small part of the area of the target block and is affected by the large area of the background, ordinary PDAF methods generally can only make the small object and the background as a whole target block have a clear focusing effect, but the clarity of the small object in the front is relatively insufficient. Therefore, how to quickly focus on a better region of interest of the target block is an urgent problem to be solved at present.
[0060] The present application provides a solution. By further dividing the target block to be focused on into regions and evaluating the phase differences of each divided target sub-block, a more suitable region of interest for the user can be reasonably determined. Since there are smaller target sub-blocks, the granularity of the focus area is smaller, avoiding problems such as insufficient clarity of small regions of interest to the user, slow focus speed, and poor focus accuracy caused by overall focusing in traditional autofocus methods. The effect of quickly focusing on the more suitable region of interest of the target block in a complex scene is achieved, improving the focus efficiency and imaging quality of the autofocus system.
[0061] It should be noted that the execution entity of this embodiment can be a computing service device with data processing, network communication, and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of implementing the above functions. Hereinafter, an electronic device will be taken as an example to illustrate this embodiment and the following embodiments.
[0062] Based on this, an embodiment of the present application provides a focusing method. Referring to Figure 1 , Figure 1 is a schematic flowchart of the first embodiment of the focusing method of the present application.
[0063] In this embodiment, the focusing method includes steps S10 to S30:
[0064] Step S10, determining the target block to be focused on in the current frame of video data, and multiple target sub-blocks in the target block, to obtain a set of regions to be focused on, where each target sub-block is obtained by dividing the target block;
[0065] It should be noted that the target block refers to the main region that the user hopes to focus on in the current frame of video data, and this region is usually the part of the image that contains the main interest points; the target sub-block refers to a smaller region obtained by further dividing the target block, and each sub-block is used to independently evaluate the focus state to achieve more refined focus adjustment.
[0066] It can be understood that since traditional autofocus methods usually cannot effectively identify the more suitable region of interest in the target block and thus cannot focus on this more suitable region of interest, step S10 is performed. By refining the division of the region of the target block, the problem of overall focus being roughly clear but the details that the user is more interested in being blurred due to the inability to identify and subdivide the focus region can be avoided, thus providing an effective data basis for achieving accurate focus.
[0067] Exemplarily, first, the current frame of the video data is analyzed by an image processing algorithm, and the target block in the current frame is determined. The specific method can be that a certain area of the current frame image is specified by the user to be fixed as the target block, or the type of the target object is specified, and the position of the target object is dynamically detected by the image processing algorithm as the target block. In this embodiment, the method for determining the target block is not specifically limited. Please refer to Figure 2 , in the figure, the original image is the current frame, the image size is W*H, and the size of the target block is ω*h. Then, the target block is further divided into several smaller regions, that is, target sub-blocks. Please refer to Figure 3 , in the figure, a target block is divided into three target sub-blocks: a target left sub-block, a target middle sub-block, and a target right sub-block. Among them, the size of any target sub-block is a*b, and these sub-blocks can be divided in a fixed grid or content-adaptive manner. Finally, these target sub-blocks and the target block are combined to form a set of regions to be focused, so as to facilitate subsequent focus evaluation.
[0068] Step S20: Obtain the original image pixels of the target block, and determine the phase difference of each region to be focused in the set of regions to be focused based on the original image pixels, where each region to be focused includes the target block and each target sub-block;
[0069] It should be noted that the original image pixels refer to the pixel data directly obtained from the image sensor without any processing, and this data contains all the detailed information of the image; the phase difference is a value obtained by comparing the phase information between the phase detection pixels in the target sub-block, and this value reflects the clarity of the image and is used to judge the focus state.
[0070] It can be understood that in order to evaluate the focus state of the target block and each sub-block of the target block, step S20 is performed. By accurately evaluating the focus state through the calculated phase difference, the problem of unclear images caused by inaccurate focusing can be avoided, and fast and accurate focus evaluation is achieved.
[0071] Exemplarily, the original pixel data of the target block and its sub-blocks are directly captured by the image sensor. These data are not processed at all and retain all the details of the image. Then, a phase detection algorithm is applied to analyze these original pixels, and the phase difference of the pixels in the target block and each target sub-block is calculated. Among them, this phase difference reflects the clarity of the image, and the closer the difference is to 0, the clearer the area is. In this embodiment, the smaller the phase difference of a block is, the more likely it is that the block is the region of interest block of the target in this embodiment. Finally, this block needs to be focused to be clear, that is, this block needs to be focused to a state where the phase difference is closer to 0.
[0072] In a feasible implementation manner, the step of determining the phase difference of each to-be-focused area in the to-be-focused area set based on the original image pixels in step S20 may include steps S21 to S22:
[0073] Step S21: Separate the original image pixels based on the pixel type to obtain the phase detection pixels of the target block;
[0074] It should be noted that the phase detection pixels refer to specific pixels in the phase detection focusing system that can reflect the image sharpness information. These pixels are usually specially designed pixels on the image sensor that can detect the phase change of light. For an image sensor with phase detection pixels, each frame of the original image pixels output contains two parts: imaging pixels and phase detection pixels. Among them, the imaging pixels are mainly used for image imaging, that is, the video or image information that users often see. The phase detection pixels are mainly used to determine whether the image is clear. When the image imaging is relatively blurred, that is, defocus occurs, at this time, the phase difference obtained by the phase difference acquisition algorithm for the phase detection pixels will be relatively large (the larger the absolute value of the phase difference, the blurrier it is, and the phase difference has positive and negative values). When the image imaging is relatively clear, the absolute value of the phase difference will be smaller and closer to 0.
[0075] It can be understood that since there are both pixels for imaging and phase detection on the image sensor, these two types of pixels need to be distinguished to facilitate dedicated focusing calculations. Therefore, step S21 is performed. By separating the phase detection pixels, the problem of data processing errors caused by the mixing of pixel types can be avoided, and dedicated evaluation of the focusing quality can be achieved, thereby improving the accuracy of the focusing calculation.
[0076] Exemplarily, first, from the original pixel data obtained from the image sensor, the ordinary imaging pixels and the specially designed phase detection pixels are distinguished according to the pixel marking or address information. Then, these phase detection pixels are extracted from the entire pixel array to form a set of independent phase detection pixel sets. This set corresponds to the target block area and provides a dedicated data source for subsequent focusing calculations.
[0077] Step S22: Determine the phase detection pixels of each to-be-focused area in the to-be-focused area set based on the phase detection pixels of the target block, and convert each phase detection pixel into a corresponding phase difference to obtain the phase difference of each to-be-focused area.
[0078] It should be noted that the operation of converting the phase detection pixel into the corresponding phase difference value can be performed in the image acquisition sensor or in the main control end. In this embodiment, the implementation subject of the phase difference value conversion is not specifically limited. That is, in the case where the original phase difference value acquisition algorithm is integrated in the image acquisition sensor, please refer to Figure 4 When capturing images, the image acquisition sensor will automatically convert the phase detection pixels into phase difference values through the algorithm of the base layer, and then transmit them to the main control end through, for example, the IIC (Inter-Integrated Circuit, integrated circuit bus) protocol; if the original phase difference acquisition algorithm is not integrated in the image acquisition sensor, please refer to Figure 5 , the original pixels of the image acquired by the image acquisition sensor are transmitted to the main control end (the transmission protocol depends on the sensor designer), and then the main control end first separates the phase detection pixels from the original pixels of the image, and then converts the separated phase detection pixels into corresponding phase difference values through the original phase difference value acquisition algorithm configured by the main control end, wherein the original phase difference value acquisition algorithm configured by the main control end can be an algorithm provided by the main control end SDK, or an algorithm provided by the image acquisition sensor designer, or a general open source algorithm. In this embodiment, the source of the original phase difference value acquisition algorithm is not specifically limited.
[0079] It can be understood that since it is necessary to evaluate the focus state of each area to be focused by analyzing the phase detection pixels, step S22 is performed. By converting the phase detection pixels into phase difference values, the problem of inaccurate global focus caused by the inability to accurately evaluate the focus state of each area to be focused can be avoided, thereby achieving the effect of accurately evaluating the focus state of the area to be focused, thereby ensuring that the focusing system can quickly and accurately find a better focus position.
[0080] For example, for each area to be focused in the collection of focus areas, the corresponding phase detection pixels are identified and extracted, and signal processing is performed on these phase detection pixels to calculate the phase difference between them and the reference signal. This process usually involves PDAF technology. The calculated phase difference values are assigned to the corresponding areas to be focused. These phase difference values represent the focus status of each area, thereby providing a basis for determining a better focus area.
[0081] In this embodiment, by separating the original pixels of the image based on the pixel type, the phase detection pixels of the target block are obtained, and further each phase detection pixel is converted into a corresponding phase difference, avoiding the problems of data processing errors caused by the mixing of pixel types and the inability to accurately evaluate the focusing state of each area to be focused, realizing the accurate focusing evaluation of the area to be focused, thereby ensuring that the autofocus system can quickly and accurately determine a better focusing position, and improving the focusing efficiency and the clarity of the image.
[0082] Step S30: Determine the target focusing area according to each phase difference, and perform focusing on the target focusing area.
[0083] It should be noted that the target focusing area refers to the sub-block that most needs to be focused according to the phase difference, and this sub-block is the most critical part of the focusing quality in the entire target block.
[0084] It can be understood that since the better region of interest is often highly correlated with the phase difference, performing step S30 can avoid the problem of being unable to reasonably determine the better region of interest, so as to determine the better region of interest that can meet the user's needs as the target focusing area.
[0085] Exemplarily, first, compare the phase differences of the target block and all target sub-blocks, and find the focusing area with the smallest phase difference. This area is the target focusing area that is more interesting. Then, perform focusing on this target focusing area.
[0086] In a feasible embodiment, the step of determining the target focusing area according to each phase difference in step S30 may include steps S31 to S33:
[0087] Step S31: For any area to be focused, compare the confidence level of the area to be focused with a preset confidence threshold, where the confidence level is determined based on the original pixels of the image of the area to be focused;
[0088] It should be noted that the confidence level of the area to be focused refers to the probability or reliability index of the focusing accuracy of this area calculated based on the phase detection pixels separated from the original pixels of the image.
[0089] It can be understood that in order to effectively evaluate the focusing quality of each area to be focused, so as to determine a better target of interest for focusing among multiple areas to be focused, step S31 is performed. By comparing the confidence levels of the areas to be focused, the problem of inaccurate focusing caused by wrongly selecting the focusing area can be avoided, thereby achieving the effect of accurately identifying the area that is most interesting and needs to be clearly imaged.
[0090] Exemplarily, first, the original pixels of the images in each area to be focused are analyzed through the original phase acquisition algorithm to calculate features such as its texture complexity and contrast, and then the focus confidence of this area is obtained. Then, the calculated confidence is compared with a preset confidence threshold to determine whether this area may be a better focus area.
[0091] Step S32, after traversing each area to be focused, if there is only one candidate area to be focused whose confidence is greater than the preset confidence threshold among the areas to be focused, then use the target block as the target focus area;
[0092] It should be noted that a candidate area to be focused refers to an area to be focused whose confidence exceeds the preset confidence threshold.
[0093] In addition, it should be noted that since in the areas to be focused, if there is a situation where the confidence of a target sub-block is greater than the preset confidence threshold, then the confidence of the target block to which this target sub-block belongs must be greater than the preset confidence threshold. However, the fact that the confidence of the target block is greater than the preset confidence threshold does not mean that the confidence of any target sub-block in this target block must be greater than the preset confidence threshold. Therefore, when there is only one candidate area to be focused whose confidence is greater than the preset confidence threshold among the areas to be focused, this candidate area to be focused is the target block.
[0094] It can be understood that since there is a situation where the confidence of each target sub-block is lower than the preset confidence threshold, step S32 is performed. By selecting the target block as the target focus area when the confidence of each target sub-block is too low, it can avoid the problem of being unable to lock the target focus area due to the too low confidence of each target sub-block, and achieve the effect of quickly locking the single clearest focus area.
[0095] Exemplarily, after completing the confidence evaluation of all areas to be focused, check whether there is exactly one area whose confidence exceeds the preset confidence threshold, and this area happens to be the initially set target block. If so, directly confirm the target block as the final target focus area.
[0096] Step S33, if there are multiple candidate areas to be focused whose confidence is greater than the preset confidence threshold among the areas to be focused, then use the target sub-block with the smallest phase difference among the candidate areas to be focused as the target focus area.
[0097] It should be noted that through a large number of user experience feedbacks and actual verifications, it is found that users often hope that the object closest to the camera lens is in sharp focus. For the phase differences with positive and negative values, they are distributed from small to large in the distance from the lens, that is, the target sub-block with the smallest phase difference is the target sub-block closest to the lens, and the target sub-block with the largest phase difference is the target sub-block farthest from the lens.
[0098] It can be understood that since it is necessary to make a final selection that meets the actual needs of users from multiple high-confidence regions, performing step S33 can avoid the uncertainty and focusing errors caused by multiple regions all having high confidence, and achieve the effect of determining the clearest focusing region through the smallest phase difference.
[0099] Exemplarily, when the confidence levels of multiple (two or more) regions to be focused exceed the threshold, compare the phase differences of these regions, and select the target sub-block in the region with the smallest phase difference as the target focusing region, because the smallest phase difference usually means that the region is closest to the lens.
[0100] In this embodiment, by comparing the confidence level of each region to be focused with the preset confidence threshold and selecting the clearest target sub-block according to the phase difference, the problems of focusing failure or image blurring caused by the inability to accurately judge the focusing region are avoided, ensuring that the autofocus system can make the best choice among multiple potential focusing regions, thereby achieving the effect of quickly and accurately determining a better focusing area in a complex scene, and improving the focusing accuracy and imaging quality.
[0101] This embodiment provides a focusing method. By further dividing the target block to be focused and evaluating the phase differences of each divided target sub-block, a better region of interest of the user can be reasonably determined. Since there are smaller target sub-blocks, the granularity of the focusing region is smaller, avoiding problems such as insufficient clarity of small regions of interest of the user, slow focusing speed, and poor focusing accuracy caused by overall focusing in traditional autofocus methods, and achieving the effect of quickly focusing on the better region of interest of the target block in a complex scene, and improving the focusing efficiency and imaging quality of the autofocus system.
[0102] Based on the first embodiment of the present application, in the second embodiment of the present application, for the same or similar content as in the above-mentioned first embodiment, reference can be made to the above introduction and will not be repeated hereinafter. On this basis, please refer to Figure 6 , after the step of determining the target focusing region according to each phase difference described in step S30, steps S100 to S400 may further be included:
[0103] Step S100, when the target area is any target sub-block, divide the target sub-block to obtain multiple sub-regions in the target sub-block;
[0104] It should be noted that a sub-region refers to further dividing the target sub-block into smaller regions for more accurate evaluation of the focus quality.
[0105] It can be understood that in order to analyze the target sub-block more carefully to determine a clearer focus point, Step S100 is carried out. By further dividing the target sub-block with better interest points, the problem of inaccurate focusing caused by too large a focusing area can be avoided, achieving the effect of further improving the focusing accuracy.
[0106] Exemplarily, first, select the target sub-block as the candidate area for focusing, and then divide the target sub-block evenly or unevenly into several smaller regions, such as by grid division or an image feature-based division method, in order to analyze the focusing situation of each small region more finely. Refer to Figure 7 For the sake of convenient representation, in the figure, the schematic diagrams of dividing the same target sub-block (with size a*b) are divided into target sub-block (a) and target sub-block (b). In the figure, the determined target sub-block is divided into five sub-regions: target sub-block (left area), target sub-block (middle area), target sub-block (right area), target sub-block (upper area), and target sub-block (lower area), where the size of any sub-region is x*y.
[0107] Step S200, for any one sub-region, determine the phase difference and confidence level of the sub-region, and compare the confidence level of the sub-region with a preset confidence level threshold;
[0108] It can be understood that in order to evaluate the focus quality of each sub-region, Step S200 is carried out, which can avoid the problem of ignoring some better interested regions that may have a smaller area, and realizes screening out more detailed better interested regions through the evaluation of the self-healing confidence level.
[0109] Exemplarily, for each divided sub-region, use the original phase difference acquisition algorithm to calculate its phase difference and confidence level. Then, compare the calculated confidence level with the preset confidence level threshold to determine whether the sub-region may be a better interested region.
[0110] Step S300, after traversing each sub-region, if there is only one candidate sub-region whose confidence level is greater than the preset confidence level threshold among the sub-regions, update the target focusing area based on the candidate sub-region;
[0111] It should be noted that the candidate sub-regions refer to those sub-regions whose confidence levels exceed a pre-set confidence threshold after the confidence levels of the sub-regions are evaluated.
[0112] It can be understood that in order to directly determine the focus area in the case of only one sub-region with a high confidence level, step S300 is performed, which can avoid the problem of still making complex decisions when there is only one clear focus point, thus achieving the effect of quickly locking the target focus area.
[0113] Exemplarily, after all sub-regions are evaluated, if only one sub-region's confidence level exceeds the pre-set confidence threshold, then directly determine this sub-region as the new target focus area and adjust the lens focus accordingly.
[0114] Step S400, if there are multiple candidate sub-regions among the sub-regions whose confidence levels are all greater than the pre-set confidence threshold, then update the target focus area based on the candidate sub-region with the smallest phase difference among the candidate sub-regions.
[0115] It can be understood that in order to reasonably select a more interesting area when multiple sub-regions all have high confidence levels, step S400 is performed. By comparing the confidence levels, it can avoid the problem of difficult accurate selection of the focus point due to multiple potential focus points, and provides an effective implementation method for quickly and accurately determining a better area of interest to be focused on.
[0116] Exemplarily, when the confidence levels of multiple sub-regions all exceed the threshold, compare the phase differences of these candidate sub-regions, and select the sub-region with the smallest phase difference as the new target focus area. This is because the sub-region with the smallest phase difference usually represents the area closest to the lens, and this area is very likely to be a better area of interest, thus ensuring that the focus area can meet the actual needs of the user.
[0117] It should be noted that if the confidence level of any one of the candidate sub-regions among the sub-regions is less than or equal to the pre-set confidence threshold, then keep the current target focus area.
[0118] In this embodiment, by further dividing the target sub-block into regions to further refine the focus area and evaluating the confidence level of the refined regions, it avoids the problem of inaccurate focusing caused by too large a focus area of the target sub-block and the problem of hesitation in focusing due to the existence of multiple focus points. It realizes the precise determination of the target focus area through fine-grained analysis of the target sub-block, thereby improving the focusing speed and focusing accuracy of the autofocus system, and meeting the user's focusing requirements for a better area of interest with a small area.
[0119] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the content that is the same as or similar to the above-mentioned first embodiment and second embodiment can be referred to the above introduction and will not be elaborated hereinafter. On this basis, please refer to Figure 8 , the step of focusing on the target focusing area described in step S30 may include steps S01 to S02:
[0120] Step S01, determining the moving stroke value of the focusing motor based on the phase difference of the target focusing area;
[0121] It should be noted that the moving stroke value refers to the distance that the focusing motor needs to move in order to achieve clear imaging, and this distance is calculated based on the phase difference of the target focusing area.
[0122] It can be understood that since it is necessary to precisely control the focusing motor to adjust the lens position for focusing, so step S01 is performed. By calculating the moving stroke value of the focusing motor, the problem of focusing failure caused by inaccurate movement of the focusing motor can be avoided, thereby achieving efficient and accurate focusing adjustment.
[0123] Exemplarily, the system converts the phase difference of the target focusing area into the specific stroke value that the focusing motor needs to move according to the pre-calibrated mapping relationship between the phase difference and the moving stroke of the focusing motor.
[0124] In a feasible implementation manner, step S01 may include steps S011 to S012:
[0125] Step S011, determining the first input of the preset PID position loop based on the difference between the phase difference of the target focusing area and the target value, and calculating the adjustment speed based on the first input through the preset PID position loop;
[0126] It should be noted that the PID (Proportional Integral Derivative) control loop refers to a proportional-integral-derivative controller for controlling the position accuracy of the focusing system; the first input refers to the difference between the phase difference of the target focusing area and the target value in the ideal focusing state; the adjustment speed refers to the speed that the focusing motor needs to reach in order to achieve the ideal focusing state.
[0127] It is understandable that since traditional autofocus methods require calibrating the phase difference and the moving stroke value of the focus motor for fast autofocus, there is a need for calibration work. Additionally, due to the interference of the image acquisition sensor in different environments, the calibration parameters may work well in one place but not in another. Moreover, there are problems such as complex steps and instability overall. Therefore, step S011 is carried out. By proposing a method that can perform fast autofocus based on the phase difference without calibration and can also adjust the autofocus speed, it avoids the complex and restrictive calibration work of traditional autofocus methods, as well as the problem of image blurring caused by possible inaccurate autofocus, thus achieving fast and accurate focus adjustment.
[0128] Exemplarily, the phase difference of the target focus area is subtracted from the target value to obtain the position error As the first input of the PID position loop, where the target value is set to 0. It should be noted that the direction of moving the focus motor for autofocus is determined according to the positive or negative nature of the phase difference of the target focus area. Specifically: if the phase difference is positive, it indicates that the target focus area is in a far - focus blurred state. At this time, the focus motor needs to continuously reduce the stroke value for autofocus until the phase difference is 0 to complete autofocus; if the phase difference is negative, it indicates that the target focus area is in a near - focus blurred state. At this time, the focus motor needs to continuously increase the stroke value for autofocus until the phase difference is 0 to complete autofocus. The above autofocus logic can be used to quickly determine the appropriate Three parameters. Thus, the adjustment speed output by the PID position loop is obtained :
[0129]
[0130]
[0131]
[0132]
[0133] Among them, is the output of the position loop, is the current proportional term value of the position loop, is the current integral term value of the position loop, is the integral term value of the position loop at the previous moment, and its initial value is 0, is the current differential term value of the position loop, is the proportional gain of the position loop, is the integral gain of the position loop, is the differential gain of the position loop, is the position error of the position loop at the previous moment, is the time difference between the current moment and the previous moment of the position loop, and its unit is seconds.
[0134] Step S012: Obtain the current moving speed of the focusing motor, and based on the difference between the adjustment speed and the current moving speed, determine the second input of the preset PID speed loop, and calculate the moving stroke value of the focusing motor through the preset PID speed loop based on the second input.
[0135] It should be noted that the PID speed loop refers to another proportional-integral-derivative controller used to control the moving speed of the focusing motor; the current moving speed refers to the actual moving speed of the focusing motor at the current moment; the second input refers to the difference between the adjustment speed output by the PID position loop and the current moving speed; the moving stroke value refers to the distance that the focusing motor needs to move.
[0136] It can be understood that since it is necessary to ensure that the focusing motor moves at an appropriate speed to achieve smooth focusing, performing step S012 can avoid the problem of unstable focusing caused by inappropriate moving speed of the focusing motor, thereby achieving smooth and precise focusing adjustment and improving the dynamic performance and stability of the autofocus system.
[0137] Exemplarily, obtain the current moving speed of the focusing motor :
[0138]
[0139] Among them, is the position difference between the current moment and the previous moment of the focusing motor. Then subtract the adjustment speed output by the PID position loop from this current moving speed to obtain the speed error , and use this speed error as the second input of the PID speed loop to calculate the moving stroke value of the focusing motor through this PID speed loop :
[0140]
[0141]
[0142]
[0143]
[0144] Among them, is the output of the speed loop, is the current proportional term value of the speed loop, is the current integral term value of the speed loop, is the integral term value at a certain moment on the speed loop, and its initial value is 0. is the current differential term value of the speed loop. is the proportional gain of the speed loop. is the integral gain of the speed loop. is the differential gain of the speed loop. is the speed error at the previous moment of the speed loop. is the time difference between the current moment and the previous moment of the speed loop, and its unit is seconds.
[0145] In this embodiment, by combining the principle of phase detection autofocus and the principle of PID control algorithm, two PID control loops are set as the position loop and the speed loop. Among them, the position loop is used to quickly perform autofocus to the clearest position, and the speed loop is used to execute the focusing speed, avoiding the complex calibration work required by traditional autofocus and the problem of limited applicability of calibration parameters. A method of quickly performing autofocus according to the phase difference without calibration and being able to adjust the focusing speed is realized, thereby improving the focusing performance of the autofocus system.
[0146] Step S02: Execute the moving stroke value through the focusing motor to control the lens to focus on the target focusing area through the focusing motor.
[0147] In this embodiment, by determining the moving stroke value of the focusing motor based on the phase difference of the target focusing area, the focusing motor is accurately controlled to adjust the lens position for focusing, avoiding the problem of focusing failure caused by inaccurate movement of the focusing motor, thereby realizing efficient and accurate focusing adjustment.
[0148] In a feasible embodiment, after step S011, steps S010 to S020 may further be included:
[0149] Step S010: Compare the adjustment speed with a preset speed threshold.
[0150] It should be noted that the preset speed threshold refers to a pre-set speed limit value used to limit the upper limit of the adjustment speed of the focusing motor.
[0151] It can be understood that since it is necessary to ensure that the moving speed of the focusing motor does not exceed the safe working range of the focusing motor, performing step S010 can avoid a series of problems caused by the too fast moving speed of the autofocus system, such as motor damage, overshoot of focusing or image blurring, etc., realizing the effect of protecting the focusing system and ensuring the smoothness of the focusing process.
[0152] Step S020: When the adjustment speed is greater than the preset speed threshold, adjust the adjustment speed to the preset speed threshold.
[0153] It can be understood that since when the calculated adjustment speed exceeds the preset speed threshold, the speed of the focusing motor needs to be limited within a safe range, so step S020 is performed, which can avoid problems such as mechanical wear, vibration, or inaccurate focusing caused by the excessive speed of the focusing motor, and achieves the effect of ensuring the stability of the focusing system and extending the service life of the focusing system by limiting the maximum adjustment speed.
[0154] Exemplarily, when the comparison result shows that the adjustment speed exceeds the preset speed threshold the system will limit the adjustment speed to the value. This can be achieved in the following way: If > then set the value to that is = . In this way, the commanded speed of the focusing motor is limited within a safe range, ensuring the smoothness and safety of the focusing process.
[0155] In this embodiment, by adopting the means of speed limitation, problems caused by the excessive adjustment speed of the focusing motor, such as mechanical damage, system instability, or reduced focusing accuracy, are avoided, achieving the effect of ensuring that the focusing motor operates within a safe working speed range, thereby enhancing the stability and reliability of the focusing system, and at the same time ensuring the accuracy of image focusing and the smoothness of the focusing process.
[0156] In a feasible embodiment, after step S012, steps S030 to S040 may further be included:
[0157] Step S030, comparing the movement stroke value with a preset stroke value threshold;
[0158] It should be noted that the preset stroke value threshold refers to a pre-set upper limit value of the movement distance of the focusing motor, which is used to limit the maximum distance that the focusing lens moves in one adjustment of the focusing motor.
[0159] It can be understood that since it is necessary to ensure that the movement of the focusing motor does not exceed its mechanical stroke limit, thereby avoiding mechanical damage or over-focusing of the focusing system due to excessive movement distance, so step S030 is performed, which can avoid problems caused by the excessive movement stroke of the focusing motor, such as lens collision, mechanical structure damage, or inaccurate focusing, and achieves the effect of protecting the focusing system and ensuring that the focusing process is carried out within a safe range.
[0160] Step S040, when the moving stroke value is greater than the preset stroke value threshold, adjust the moving stroke value to the preset stroke value threshold.
[0161] It can be understood that since when the calculated moving stroke value exceeds the preset stroke value threshold, it is necessary to limit the moving distance of the focusing motor within a safe range, so performing step S040 can avoid problems such as mechanical limit position damage or over-focusing caused by the over-long moving stroke of the focusing motor, achieving the effect of ensuring the mechanical safety of the focusing system by limiting the maximum moving stroke and improving the focusing accuracy.
[0162] Exemplarily, when the comparison result shows that the moving stroke value of the focusing motor exceeds the preset stroke value threshold the system will limit the adjustment speed to the value. This can be achieved in the following way: If >[[]] then set the value to i.e., =[[]] . In this way, the moving stroke value of the focusing motor is limited within a safe range, ensuring the safety and accuracy of the focusing process.
[0163] In this embodiment, by adopting the means of stroke limitation, problems such as mechanical damage, over-focusing or unstable focusing caused by the moving stroke of the focusing motor exceeding its mechanical limit are avoided, achieving the operation of ensuring the focusing system within a safe stroke range, thereby protecting the mechanical integrity of the focusing mechanism, improving the accuracy of the focusing operation and the reliability of the system, and at the same time ensuring the stability of image focusing and image quality.
[0164] Exemplarily, to help understand the implementation process of the focusing method obtained by combining the above Embodiment 1 and Embodiment 2 of this embodiment, please refer to Figure 9 , Figure 9 which provides a schematic diagram of the brief process of a focusing method. Specifically:
[0165] First, collect the captured image, that is, obtain the current frame of video data; then, obtain the target block in the current frame and the original phase difference of several small blocks (i.e., target sub-blocks) inside the target block; then, execute the fast adaptive autofocus algorithm to make the target focus area clearly visible, and also focus on a better region of interest (sub-region in the target focus area) within the target focus area through the intelligent algorithm, so that the overall clarity of the target imaging is more in line with the user's expectations; then, focus on the better region of interest of the target block by moving the focusing motor, so that the imaging of the target block is clear.
[0166] Further, please refer to Figure 10 , Figure 10 which provides a schematic diagram of the pixel acquisition process of a focusing method. During the acquisition process of capturing an image, the original image pixels are first obtained, and then the imaging pixels and phase detection pixels are separated from the original image pixels.
[0167] Please refer to Figure 11 , Figure 11 which provides a schematic diagram of the focusing algorithm process of a focusing method. In the fast adaptive autofocus algorithm, first, the target area focusing block (i.e., the target block) is determined, then the target block is divided into several sub-areas (i.e., target sub-blocks), and the corresponding original phase differences between the target area and the several sub-areas are obtained, so as to intelligently select a better target area focusing block, and finally, the motor is moved to focus so that the imaging of the better target area is clear.
[0168] Please refer to Figure 12 , Figure 12 which provides a schematic diagram of the PID process of a focusing method. First, the phase difference of the target focusing area is subtracted from the target value 0 to obtain the position error , and then this position error is used as the first input and input into the PID position loop to output the adjustment speed through the PID position loop . Then, the target speed is input as the maximum speed to limit v, and the adjusted adjustment speed v_limit is obtained. After that, the adjustment speed v_limit is subtracted from the current moving speed value V of the motor (i.e., the current moving speed of the focusing motor) to obtain the speed error , and then this speed error is used as the second input and input into the PID speed loop to output the motor moving value (i.e., the moving stroke value) through the PID speed loop . Then, the motor moving value is limited, and the motor is moved based on the limited motor moving value, thereby completing the precise focusing on the target focusing area.
[0169] It should be noted that the above examples are only for understanding the present application and do not constitute a limitation on the focusing method of the present application. Based on this technical concept, more forms of simple transformations are within the protection scope of the present application.
[0170] The present application provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the focusing method in the first embodiment above.
[0171] Next, refer to Figure 13, which shows a schematic structural diagram of an electronic device suitable for implementing the embodiments of the present application. The electronic devices in the embodiments of the present application may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 13 The electronic device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present application.
[0172] As Figure 13 shown, the electronic device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM: Read Only Memory) 1002 or the program loaded from the storage device 1003 into the random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of the electronic device are also stored. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems may be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the electronic device to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. Instead, more or fewer systems may be implemented or had.
[0173] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product that includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by a processing device 1001, the above-mentioned functions defined in the methods of the embodiments disclosed in the present application are executed.
[0174] The electronic device provided by the present application adopts the focusing method in the above embodiment, and can solve the technical problem of how to quickly focus on a better region of interest of a target block. Compared with the prior art, the beneficial effects of the electronic device provided by the present application are the same as those of the focusing method provided by the above embodiment, and other technical features in the electronic device are the same as those disclosed in the method of the previous embodiment, which will not be elaborated here.
[0175] It should be understood that the various parts disclosed in the present application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.
[0176] As described above, only the specific embodiments of the present application are provided, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present application, and all should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0177] The present application provides a computer-readable storage medium having computer-readable program instructions (i.e., computer programs) stored thereon, and the computer-readable program instructions are used to execute the focusing method in the above embodiment.
[0178] The computer-readable storage medium provided by the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or flash memory, optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program.
[0179] The above computer-readable storage medium carries one or more programs. When the above one or more programs are executed by an electronic device, the electronic device is caused to: determine a target block to be focused in the current frame of video data and a plurality of target sub-blocks in the target block to obtain a set of regions to be focused, where each target sub-block is obtained by dividing the target block; acquire the original image pixels of the target block, and determine the phase difference of each region to be focused in the set of regions to be focused based on the original image pixels, where each region to be focused includes the target block and each target sub-block; determine a target focus region according to each phase difference, and perform focusing on the target focus region.
[0180] Computer program code for performing the operations of the present application may be written in one or more programming languages or combinations thereof. The above programming languages include object-oriented programming languages - such as Java, Smalltalk, C++, and also include conventional procedural programming languages - such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network - including a local area network (LAN) or a wide area network (WAN) - or may be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).
[0181] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0182] The modules described in the embodiments of the present application can be implemented in software or in hardware. Among them, the name of the module does not constitute a limitation on the unit itself in some cases.
[0183] The readable storage medium provided by the present application is a computer-readable storage medium, and the computer-readable storage medium stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned focusing method, which can solve the technical problem of how to quickly focus on a better region of interest of the target block. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as those of the focusing method provided by the above embodiments, and will not be elaborated here.
[0184] The present application also provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the steps of the focusing method as described above.
[0185] The computer program product provided by the present application can solve the technical problem of how to quickly focus on a better region of interest of the target block. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as those of the focusing method provided by the above embodiments, and will not be elaborated here.
[0186] The above are only some embodiments of the present application, and do not limit the patent scope of the present application. Any equivalent structural transformation made under the technical concept of the present application by using the content of the specification and drawings of the present application, or any direct / indirect application in other related technical fields, is included in the patent protection scope of the present application.
Claims
1. A focusing method, characterized in that: The focusing method comprises: Determine a target block to be focused in a current frame of video data, and a plurality of target sub-blocks in the target block, to obtain a collection of areas to be focused, wherein each target sub-block is obtained by dividing the target block; Acquire the original pixels of the image of the target block, and determine the phase difference value of each to-be-focused area in the to-be-focused area collection based on the original pixels of the image, wherein each to-be-focused area includes the target block and each target sub-block, and the determination process of the phase difference value is performed on the image sensor or the main control end; Determine a target focus area according to each phase difference value, use the difference between the phase difference value of the target focus area and the target value as a first input of a preset PID position loop, and calculate an adjustment speed based on the first input through the preset PID position loop; comparing the adjusted speed with a target speed; When the adjustment speed is greater than the target speed, adjusting the adjustment speed to the target speed; Acquire the current moving speed of the focus motor, use the difference between the adjustment speed and the current moving speed as the second input of a preset PID speed loop, and calculate the moving stroke value of the focus motor based on the second input through the preset PID speed loop; The moving stroke value is executed by the focus motor, so as to control the lens to focus on the target focus area through the focus motor.
2. The focusing method according to claim 1, wherein: The step of determining the phase difference value of each area to be focused in the collection of areas to be focused based on the original pixels of the image comprises: Performing pixel separation on the original pixels of the image based on pixel types to obtain phase detection pixels of the target block; The phase detection pixels of each area to be focused in the collection of areas to be focused are determined based on the phase detection pixels of the target block, and each phase detection pixel is converted into a corresponding phase difference value to obtain the phase difference value of each area to be focused.
3. The focusing method according to claim 1, wherein: The step of determining the target focus area according to each phase difference value comprises: For any area to be focused, comparing the confidence of the area to be focused with a preset confidence threshold, wherein the confidence is determined based on original pixels of the image of the area to be focused; After traversing each to-be-focused area, if there is only one candidate to-be-focused area among the to-be-focused areas whose confidence is greater than the preset confidence threshold, then taking the target block as the target focus area; If there are multiple candidate areas to be focused among the areas to be focused, and the confidences of all of them are greater than the preset confidence threshold, then the target sub-block with the smallest phase difference value among the candidate areas to be focused is used as the target focus area.
4. The focusing method according to claim 1, wherein: After the step of determining the target focus area according to each phase difference value, the following step is further included: In a case where the target focus area is any target sub-block, dividing the target sub-block to obtain a plurality of sub-areas in the target sub-block; For any sub-region, determining the phase difference value and confidence of the sub-region, and comparing the confidence of the sub-region with a preset confidence threshold; After traversing each sub-region, if there is only one candidate sub-region among the sub-regions whose confidence is greater than the preset confidence threshold, updating the target focus region based on the candidate sub-region; If there are multiple candidate sub-regions in each of the sub-regions, and the confidences of the multiple candidate sub-regions are all greater than the preset confidence threshold, the target focus region is updated based on the candidate sub-region with the smallest phase difference value among the candidate sub-regions.
5. The focusing method according to claim 1, wherein: After the step of calculating the moving stroke value of the focus motor based on the second input by the preset PID speed loop, the method further includes: Comparing the moving stroke value with a preset stroke value threshold; When the moving stroke value is greater than the preset stroke value threshold, the moving stroke value is adjusted to the preset stroke value threshold.
6. An electronic device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the focusing method according to any one of claims 1 to 5.
7. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the storage medium method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Image processing method and device, electronic equipment and computer readable storage medium
CN112866549A
Focusing method and device, electronic equipment and computer readable storage medium
CN112866552A
Focusing motor control method and device
CN117201934A
Focusing control method, electronic equipment and medium
CN117714856A
Control device, photographing device, moving body, control method, and program
WO2020063779A1