Focusing method and device and storage medium

By subdividing the target block and evaluating the phase difference value, determining the target focus area for focusing, the problems of slow focus speed and poor focus accuracy in the prior art are solved, and a fast and accurate focus effect is achieved in complex scenes.

CN119520991AActive Publication Date: 2025-02-25SHENZHEN EMEET TECH CO LTD

Patent Information

Application Number
CN202510081404.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-20
Publication Date
2025-02-25
Estimated Expiration
2045-01-20

AI Technical Summary

Technical Problem

Existing autofocus technologies are difficult to quickly and accurately focus on better areas of interest in the target block, especially in complex scenarios, resulting in slow focus speed, poor focus accuracy and insufficient clarity in small areas of interest in the user.

Method used

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 confidence and phase difference value to focus.

Benefits of technology

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 poor focus accuracy in traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119520991A_ABST
    Figure CN119520991A_ABST
Patent Text Reader

Abstract

The invention discloses a focusing method and device and a storage medium, and relates to the technical field of video image focusing, and the method comprises the steps: determining a to-be-focused target block in a current frame of video data and a plurality of target sub-blocks in the target block, and obtaining a to-be-focused region set, each target sub-block being obtained through the division of the target block; an image original pixel of the target block is acquired, a phase difference value of each to-be-focused area in the to-be-focused area set is determined based on the image original pixel, and each to-be-focused area comprises the target block and each target sub-block; and determining a target focusing area according to each phase difference value, and focusing the target focusing area. According to the method, the target block needing to be focused is further subjected to region division, and the phase difference values of the divided regions are evaluated, so that a better region of interest of the target block can be quickly focused in a complex scene, and the focusing efficiency and the imaging quality of the automatic focusing system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In modern optical technology equipment, 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 lens 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 focus (CDAF), laser focus (TOFAF), and phase detection focus (PDAF).

[0003] CDAF relies on contrast changes in the image sensor to achieve autofocus. This focusing method is low-cost and widely used, but the focusing speed is slow and requires constant adjustment to obtain a clear image. At the same time, it performs poorly in low-light environments and is prone to repeated focusing. TOFAF measures the distance by emitting and receiving lasers to make focus adjustments. It is usually used in high-demand environments, such as scenes that require fast focus. However, this focusing method is highly dependent on ambient light and reflective surfaces, which affects focus accuracy in some cases. In addition, the hardware design is complex, resulting in high manufacturing costs. PDAF relies on light entering the image sensor through different paths to compare phase differences to achieve focus, but this When ordinary image sensors are used for the focusing method, the focusing accuracy is poor. Although the use of high-end image sensors can improve the focusing accuracy, it also significantly increases the cost. No matter what sensor is used, it is impossible to focus on the better area of ​​interest of the target block. For example, when a user is communicating via video, he places a small object in the front and relatively central position of the lens target block for others to see. The general public generally hopes that the small object should be able to focus and image clearly. However, since this small object only occupies a small part of the target block area and is affected by the large area of ​​the background, the ordinary PDAF method can generally only make the small object and the background as a whole The target block has a clear focus effect, but the clarity of the small object in front is relatively insufficient.

[0004] Therefore, how to quickly focus on a better area of ​​interest of the target block is a problem that needs to be solved urgently. Summary of the invention

[0005] The main purpose of the present application is to provide a focusing method, device and storage medium, aiming to solve the technical problem of how to quickly focus on a better area of ​​interest of a target block.

[0006] To achieve the above purpose, the present application proposes a focusing method, which includes: 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 original pixels of the image of the target block, and determine 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, wherein each area to be focused includes the target block and each target sub-block; A target focus area is determined according to each phase difference value, and the target focus area is focused.

[0007] In one embodiment, the step of determining 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 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.

[0008] In one embodiment, the step of determining the target focus area according to each phase difference value includes: 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.

[0009] In one embodiment, after the step of determining the target focus area according to each phase difference value, the step further includes: In the case where the target 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.

[0010] In one embodiment, the step of focusing the target focus area includes: Determining a moving stroke value of a focus motor based on a phase difference value of the target focus area; 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.

[0011] In one embodiment, the step of determining the moving stroke value of the focus motor based on the phase difference value of the target focus area includes: Determine a first input of a preset PID position loop based on a difference between a phase difference value of the target focus area and a target value, and calculate an adjustment speed based on the first input through the preset PID position loop; The current moving speed of the focus motor is obtained, and based on the difference between the adjustment speed and the current moving speed, a second input of a preset PID speed loop is determined, and the moving stroke value of the focus motor is calculated based on the second input through the preset PID speed loop.

[0012] In one embodiment, after the step of calculating the regulating speed based on the first input by the preset PID position loop, the step further includes: comparing the adjusted speed with a preset speed threshold; When the adjustment speed is greater than the preset speed threshold, the adjustment speed is adjusted to the preset speed threshold.

[0013] In one embodiment, after the step of calculating the moving stroke value of the focus motor based on the second input by using the preset PID speed loop, the step 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.

[0014] In addition, to achieve the above-mentioned purpose, the present application also proposes an electronic device, which includes: 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 described above.

[0015] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which 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 focusing method described above are implemented.

[0016] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the focusing method described above are implemented.

[0017] One or more technical solutions proposed in this application have at least the following technical effects: The present application first determines a target block to be focused in a current frame of video data, and multiple target sub-blocks in the target block, and obtains a collection of areas to be focused, so as to subdivide the entire target block to be focused into multiple target sub-blocks by performing image area division, so as to more accurately detect the focus state of each target sub-block, thereby achieving rapid and accurate identification of small areas of interest to the user; then the original pixels of the image of the target block are obtained, and the phase difference values ​​of each area to be focused in the collection of areas to be focused are determined based on the original pixels of the image, so as to extract the phase information used for focus evaluation from the original image data, and ensure the accuracy of focus evaluation by calculating the phase difference values ​​of the target block and each target sub-block, thereby achieving the effect of improving the focusing speed and accuracy; finally, the target focus area is determined according to each phase difference value, and the target focus area is focused, so as to achieve the effect of judging a better target focus area of ​​interest based on the phase difference value, thereby completing the accurate focusing of the small area of ​​interest to the user.

[0018] In summary, the present application further divides the target block that needs to be focused into regions, and evaluates the phase difference value of each divided target sub-block to reasonably determine the user's optimal area of ​​interest. Due to the existence of smaller target sub-blocks, the granularity of the focus area is smaller, thereby avoiding the problems of insufficient clarity of the small area of ​​interest to the user, slow focusing speed, and poor focusing accuracy caused by overall focusing in traditional autofocus methods, and achieves the effect of quickly focusing on the optimal area of ​​interest of the target block in complex scenes, thereby improving the focusing efficiency and imaging quality of the autofocus system. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0021] Figure 1 A flowchart of the first embodiment of the focusing method of the present application is provided; Figure 2 A schematic diagram of a target block of a focusing method provided in Embodiment 1 of the present application; Figure 3 A schematic diagram of a target sub-block of the focusing method provided in Embodiment 1 of the present application; Figure 4 A schematic diagram of a phase difference acquisition process of a focusing method provided in Embodiment 1 of the present application; Figure 5 A schematic diagram of another phase difference acquisition process of the focusing method provided in Embodiment 1 of the present application; Figure 6 A schematic diagram of a flow chart provided for the second embodiment of the focusing method of the present application; Figure 7 A schematic diagram of a target sub-block sub-region of a focusing method provided in Embodiment 2 of the present application; Figure 8 A flowchart of the third embodiment of the focusing method of the present application is provided; Fig. 9 A schematic diagram of a brief flow of the focusing method provided in Embodiment 3 of the present application; Fig.10 A schematic diagram of the pixel acquisition process of the focusing method provided in Embodiment 3 of the present application; Fig.11 A schematic diagram of a focusing algorithm flow chart of a focusing method provided in Embodiment 3 of the present application; Fig.12 A schematic diagram of the PID flow of the focusing method provided in Embodiment 3 of the present application; Fig.13 Schematic diagram of the device structure of the hardware operating environment involved in the focusing method in the embodiment of the present application.

[0022] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

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

[0024] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0025] The main solution of the embodiment of the present application is: determine the target block to be focused in the current frame of the video data, and multiple 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; obtain the original pixels of the image of the target block, and determine the phase difference values ​​of each area to be focused in the collection of areas to be focused based on the original pixels of the image, wherein each area to be focused includes the target block and the target sub-blocks; determine the target focus area according to each phase difference value, and focus on the target focus area.

[0026] Since the existing technology cannot focus on the best area of ​​interest of the target block, for example, when a user places a small object in the front and relatively central part of the lens target block for others to see during video communication, the general public generally hopes that the small object should be able to focus and image clearly. However, since the small object only occupies a small part of the target block area and is affected by the large area of ​​the background, the ordinary PDAF method can generally only make the small object and the background as a whole target block focus clearly, but the clarity of the small object in front is relatively insufficient. Therefore, how to quickly focus on the best area of ​​interest of the target block is a problem that needs to be solved urgently.

[0027] The present application provides a solution, by further dividing the target block to be focused on, and evaluating the phase difference value of each divided target sub-block, so as to reasonably determine the user's better area of ​​interest. Due to the existence of smaller target sub-blocks, the granularity of the focus area is smaller, thereby avoiding the problems of insufficient clarity of the small area of ​​interest to the user, slow focusing speed, poor focusing accuracy, etc. caused by overall focusing in the traditional automatic focusing method, and achieving the effect of quickly focusing on the better area of ​​interest of the target block in complex scenes, thereby improving the focusing efficiency and imaging quality of the automatic focusing system.

[0028] It should be noted that the execution subject 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 that can realize the above functions. The following takes an electronic device as an example to illustrate this embodiment and the following embodiments.

[0029] Based on this, the present application embodiment provides a focusing method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the focusing method of the present application.

[0030] In this embodiment, the focusing method includes steps S10 to S30: Step S10, determining 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; It should be noted that the target block refers to the main area in the current frame of the video data that the user wants to focus on, which is usually the part of the image that contains the main points of interest; the target sub-block refers to the smaller area into which the target block is further subdivided, and each sub-block is used to independently evaluate the focus state to achieve more precise focus adjustment.

[0031] It is understandable that, since traditional autofocus methods are usually unable to effectively identify the better area of ​​interest in the target block, and thus are unable to focus on the better area of ​​interest, step S10 is performed to refine the target block by dividing it into regions. This can avoid the problem of the 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 areas, thereby providing an effective data basis for achieving precise focus.

[0032] For example, 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 the user specifies a certain area of ​​the current frame image as the target block, or the target object type is specified, and the position of the target object is dynamically detected by the image processing algorithm as the target block. The method for determining the target block in this embodiment is not specifically limited. Please refer to Figure 2 , the original image in the figure 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 subdivided into several smaller areas, namely target sub-blocks, please refer to Figure 3 In the figure, a target block is divided into three target sub-blocks: target left sub-block, target middle sub-block and target right sub-block. The size of any target sub-block is a*b. These sub-blocks can be divided according to a fixed grid or content-adaptive mode. Finally, these target sub-blocks are combined with the target block to form a collection of areas to be focused, which is convenient for subsequent focus evaluation.

[0033] Step S20, obtaining original pixels of the image of the target block, and 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, wherein each area to be focused includes the target block and each target sub-block; It should be noted that the original pixel of the image refers to the unprocessed pixel data directly obtained from the image sensor, which contains all the detailed information of the image; the phase difference value refers to the value obtained by comparing the phase information between the phase detection pixels in the target sub-block, which reflects the clarity of the image and is used to judge the focus state.

[0034] It can be understood that in order to evaluate the focus status of the target block and each sub-block of the target block, step S20 is performed. The focus status is accurately evaluated by calculating the phase difference value, which can avoid the problem of unclear image caused by inaccurate focus and achieve fast and accurate focus evaluation.

[0035] Exemplarily, the original pixel data of the target block and its sub-blocks are directly captured by an image sensor. These data are not processed in any way and retain all the details of the image. Then, a phase detection algorithm is applied to analyze these original pixels to calculate the phase difference value of the pixels in the target block and each target sub-block, wherein the phase difference value reflects the clarity of the image, and the closer the difference value is to 0, the closer the area is to a clear state. In this embodiment, the smaller the phase difference value of a block is, the better target area of ​​interest block of this embodiment is, and the block needs to be focused to be clear, that is, the block needs to be focused to a state where the phase difference value is closer to 0.

[0036] In a feasible implementation manner, the step of determining 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 in step S20 may include steps S21-S22: Step S21, performing pixel separation on the original pixels of the image based on pixel types to obtain phase detection pixels of the target block; It should be noted that phase detection pixels refer to specific pixels used in phase detection focusing systems that can reflect image clarity information. These pixels are usually specially designed pixels on image sensors that can detect phase changes in light. For image sensors with phase detection pixels, the raw pixels of each frame of the output image contain two parts: imaging pixels and phase detection pixels. Among them, imaging pixels are mainly used for image imaging, that is, video or image information that users often see. Phase detection pixels are mainly used to determine whether the image is clear. When the image is relatively blurred, that is, defocus occurs, the phase difference obtained by the phase detection pixel through the phase difference acquisition algorithm will be relatively large (the larger the absolute value of the phase difference, the more blurred it is, and the phase difference can be positive or negative), and when the image is relatively clear, the absolute value of the phase difference will be smaller and closer to 0.

[0037] It can be understood that since there are pixels for imaging and phase detection on the image sensor at the same time, these two pixels need to be distinguished in order to perform special focus calculations. Therefore, step S21 is performed. By separating the phase detection pixels, the problem of data processing errors caused by mixing pixel types can be avoided, and a special evaluation of the focus quality can be achieved, thereby improving the accuracy of the focus calculation.

[0038] For example, first, from the raw pixel data obtained by the image sensor, ordinary imaging pixels and specially designed phase detection pixels are distinguished according to the pixel mark or address information. Then, these phase detection pixels are extracted from the entire pixel array to form a set of independent phase detection pixels. This set corresponds to the target block area and provides a dedicated data source for subsequent focus calculations.

[0039] Step S22, determining the phase detection pixels of each area to be focused in the set of areas to be focused based on the phase detection pixels of the target block, and converting each phase detection pixel into a corresponding phase difference value to obtain the phase difference value of each area to be focused.

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

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

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

[0043] In the present embodiment, the original pixels of the image are separated based on pixel type to obtain the phase detection pixels of the target block, and each phase detection pixel is further converted into a corresponding phase difference value, thereby avoiding data processing errors due to pixel type mixing and the inability to accurately evaluate the focus state of each area to be focused, and achieving accurate focus evaluation of the area to be focused, thereby ensuring that the autofocus system can quickly and accurately determine a better focus position, thereby improving the focusing efficiency and image clarity.

[0044] Step S30, determining a target focus area according to each phase difference value, and focusing on the target focus area.

[0045] It should be noted that the target focus area refers to the sub-block that is most in need of focusing determined according to the phase difference value, and the sub-block is the most critical part of the focus quality in the entire target block.

[0046] It is understandable that, since the better ROI is often highly correlated with the phase difference value, performing step S30 can avoid the problem of being unable to reasonably determine the better ROI, thereby determining the better ROI that can meet the user's needs as the target focus area.

[0047] Exemplarily, first, the phase difference values ​​of the target block and all target sub-blocks are compared to find the focus area with the smallest phase difference value, which is the target focus area of ​​greater interest. Then, the target focus area is focused.

[0048] In a feasible implementation manner, the step of determining the target focus area according to each phase difference value in step S30 may include steps S31 to S33: Step S31, 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; 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 the area calculated based on the phase detection pixels separated from the original pixels of the image.

[0049] It can be understood that in order to effectively evaluate the focus quality of each area to be focused so as to determine a better focus target of interest 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 due to incorrect selection of focus areas can be avoided, thereby achieving the effect of accurately identifying the areas of greatest interest that require clear imaging.

[0050] For example, first, the original pixels of the image of each area to be focused are analyzed by the original phase acquisition algorithm, and its texture complexity, contrast and other features are calculated to obtain the focus confidence of the area. Then, the calculated confidence is compared with a preset confidence threshold to determine whether the area may be a better focus area.

[0051] Step S32, 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; It should be noted that the candidate to-be-focused area refers to the to-be-focused area whose confidence exceeds a preset confidence threshold.

[0052] In addition, it should be noted that, since in each area to be focused, if there is a target sub-block whose confidence is greater than the preset confidence threshold, the confidence of the target block to which the target sub-block belongs must be greater than the preset confidence threshold, and the confidence of the target block is greater than the preset confidence threshold, it does not mean that the confidence of any target sub-block in the target block is necessarily 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 in each area to be focused, the candidate area to be focused is the target block.

[0053] 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, the problem of being unable to lock the target focus area due to the low confidence of each target sub-block can be avoided, thereby achieving the effect of quickly locking the single clearest focus area.

[0054] Exemplarily, after completing the confidence evaluation of all the areas to be focused, check whether there is one and only 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.

[0055] Step S33: 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.

[0056] It should be noted that, after a large amount of user experience feedback and actual verification, it was found that users often hope that the object closest to the lens is in clear focus, and the positive and negative phase difference values ​​are distributed from small to large at distances from the lens from near to far, that is, the target sub-block with the smallest phase difference value is the target sub-block closest to the lens, and the target sub-block with the largest phase difference value is the target sub-block farthest from the lens.

[0057] It is understandable that since it is necessary to make a final selection that meets the actual needs of the user from multiple high-confidence areas, performing step S33 can avoid the uncertainty and focus errors caused by the high confidence of multiple areas, and achieve the effect of determining the clearest focus area by the minimum phase difference value.

[0058] Exemplarily, when the confidences of multiple (two or more) areas to be focused all exceed a threshold, the phase difference values ​​of these areas are compared, and the target sub-block in the area with the smallest phase difference value is selected as the target focus area, because the smallest phase difference value usually means that the area is closest to the lens.

[0059] In this implementation, by comparing the confidence of each area to be focused with a preset confidence threshold and selecting the clearest target sub-block according to the phase difference value, the problem of focusing failure or image blur due to the inability to accurately judge the focus area is avoided, ensuring that the autofocus system can make the best choice among multiple potential focus areas, thereby achieving fast and accurate determination of the best focus area in complex scenes, and improving the focus accuracy and imaging quality.

[0060] The present embodiment provides a focusing method, which further divides the target block to be focused on into regions, and evaluates the phase difference value of each divided target sub-block to reasonably determine the user's better area of ​​interest. Due to the existence of smaller target sub-blocks, the granularity of the focus area is smaller, thereby avoiding the problems of insufficient clarity of the small area of ​​interest to the user, slow focusing speed, poor focusing accuracy, etc. caused by overall focusing in the traditional automatic focusing method, and achieves the effect of quickly focusing on the better area of ​​interest of the target block in complex scenes, thereby improving the focusing efficiency and imaging quality of the automatic focusing system.

[0061] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 6 After the step of determining the target focus area according to each phase difference value in step S30, steps S100 to S400 may be further included: Step S100, when the target area is any target sub-block, dividing the target sub-block to obtain a plurality of sub-areas in the target sub-block; It should be noted that the sub-region refers to further subdividing the target sub-block into smaller regions so as to more accurately evaluate the focus quality.

[0062] It can be understood that in order to analyze the target sub-block more carefully to determine a clearer focus point, step S100 is performed. By further dividing the target sub-block with a better point of interest, the problem of inaccurate focusing due to an excessively large focus area can be avoided, thereby achieving the effect of further improving the focus accuracy.

[0063] Exemplarily, first, a target sub-block is selected as a candidate area for focus, and then the target sub-block is evenly or unevenly divided into several smaller areas, for example, by grid division or a division method based on image features, so as to more finely analyze the focus condition of each small area. Figure 7 For the convenience of representation, the schematic diagram of dividing the same target sub-block (size is a*b) is divided into target sub-block (a) and target sub-block (b). The target sub-block is divided into five sub-areas: 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-area is x*y.

[0064] Step S200, 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; It is understandable that, in order to evaluate the focus quality of each sub-region, step S200 is performed, which can avoid the problem of ignoring some better regions of interest that may be smaller in area, and achieves the screening of more detailed and better regions of interest by evaluating the self-healing confidence.

[0065] Exemplarily, for each divided sub-region, the original phase difference value acquisition algorithm is used to calculate its phase difference value and confidence, and then the calculated confidence is compared with a preset confidence threshold to determine whether the sub-region may be a better region of interest.

[0066] Step S300, 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, then updating the target focus region based on the candidate sub-region; It should be noted that the candidate sub-regions refer to those sub-regions whose confidence exceeds a preset confidence threshold after confidence evaluation is performed on the sub-regions.

[0067] It is understandable that in order to directly determine the focus area when there is only one high-confidence sub-area, step S300 is performed, which can avoid the problem of making complex decisions when there is only one clear focus point, thereby achieving the effect of quickly locking the target focus area.

[0068] Exemplarily, after all sub-regions are evaluated, if only one sub-region has a confidence exceeding a preset confidence threshold, then this sub-region is directly determined as a new target focus region, and the lens focus is adjusted accordingly.

[0069] Step S400: If there are multiple candidate sub-regions in each of the sub-regions, and the confidences of the 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.

[0070] It can be understood that in order to reasonably select a more interesting area when multiple sub-areas have high confidence, step S400 is performed. By comparing the confidences, the problem of difficulty in accurately selecting the focus point due to multiple potential focus points can be avoided, thereby providing an effective implementation method for quickly and accurately determining the better area of ​​interest that needs to be focused.

[0071] For example, when the confidences of multiple sub-regions all exceed the threshold, the phase difference values ​​of these candidate sub-regions are compared, and the sub-region with the smallest phase difference value is selected as the new target focus region. This is because the sub-region with the smallest phase difference value usually represents the region closest to the lens, which is most likely to be a better region of interest, thereby ensuring that the focus region can meet the actual needs of the user.

[0072] It should be noted that if the confidence of any candidate sub-region among the sub-regions is less than or equal to the preset confidence threshold, the current target focus region is maintained.

[0073] In this embodiment, the target sub-block is further divided into regions to further refine the focus area, and the confidence of the refined area is evaluated, thereby avoiding inaccurate focusing due to the excessively large focus area of ​​the target sub-block and the problem of indecisive focusing due to the existence of multiple focus points. The target focus area is accurately determined by performing fine-grained analysis on the target sub-block, thereby improving the focus speed and focus accuracy of the autofocus system, and meeting the user's focus needs for a smaller area of ​​better interest.

[0074] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those of the above-mentioned embodiments 1 and 2 can be referred to the above introduction, and will not be repeated in the following. Figure 8The step of focusing on the target focus area in step S30 may include steps S01-S02: Step S01, determining a moving stroke value of a focus motor based on a phase difference value of the target focus area; It should be noted that the moving stroke value refers to the distance that the focus motor needs to move in order to achieve clear imaging, and this distance is calculated based on the phase difference value of the target focus area.

[0075] It is understandable that since the focus motor needs to be precisely controlled to adjust the lens position for focusing, step S01 is performed. By calculating the moving stroke value of the focus motor, the focus failure problem caused by inaccurate movement of the focus motor can be avoided, thereby achieving efficient and accurate focus adjustment.

[0076] Exemplarily, the system converts the phase difference value of the target focus area into a specific travel value that the focus motor needs to move according to a mapping relationship between a pre-calibrated phase difference value and a travel distance of the focus motor.

[0077] In a feasible implementation, step S01 may include steps S011 to S012: Step S011, determining a first input of a preset PID position loop based on a difference between a phase difference value of the target focus area and a target value, and calculating an adjustment speed based on the first input through the preset PID position loop; It should be noted that the PID (Proportional Integral Derivative) control loop refers to a proportional-integral-derivative controller, which is used to control the position accuracy of the focus system; the first input refers to the difference between the phase difference value of the target focus area and the target value of the ideal focus state; the adjustment speed refers to the speed that the focus motor needs to reach in order to achieve the ideal focus state.

[0078] It is understandable that since the traditional autofocus method needs to calibrate the phase difference value and the travel value of the focus motor to perform fast focusing, but there is a need for calibration work, and the image acquisition sensor is affected by different environments, the calibration parameters may work better in one place, but not in another place, and there are problems such as complicated steps and instability as a whole. Therefore, step S011 is performed by proposing a method that can perform fast focusing according to the phase difference value without calibration and can also adjust the focusing speed. This avoids the complex and restrictive calibration work of the traditional focusing method, as well as the possible problem of image blur caused by inaccurate focusing, thereby achieving fast and precise focus adjustment.

[0079] For example, the phase difference value 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 focusing the mobile focus motor is determined according to the positivity of the phase difference value of the target focus area. Specifically: if the phase difference value is a positive number, it means that the target focus area is in a far focus blur state. At this time, the focus motor needs to continuously reduce the stroke value for focusing until the phase difference value is 0 to complete the focusing; if the phase difference value is a negative number, it means that the target focus area is in a near focus blur state. At this time, the focus motor needs to continuously increase the stroke value for focusing until the phase difference value is 0 to complete the focusing. The above focus logic can be used to quickly determine the appropriate Three parameters. Thus, the adjustment speed of the PID position loop output is obtained :

[0080]

[0081]

[0082]

[0083] in, is the output of the position loop, is the current proportional term value of the position loop, is the current integral value of the position loop, is the integral value of the position loop at the previous moment, and its initial value is 0. is the current differential value of the position loop, is the position loop proportional gain, is the position loop integral gain, is the position loop differential gain, is the position error of the position loop at the previous moment, It is the time difference between the current moment and the previous moment of the position loop, and its unit is second.

[0084] Step S012, obtaining the current moving speed of the focus motor, and determining the second input of the preset PID speed loop based on the difference between the adjustment speed and the current moving speed, and calculating the moving stroke value of the focus motor based on the second input through the preset PID speed loop.

[0085] It should be noted that the PID speed loop refers to another proportional-integral-differential controller, which is used to control the moving speed of the focus motor; the current moving speed refers to the actual moving speed of the focus 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 the focus motor needs to move.

[0086] It is understandable that since it is necessary to ensure that the focus motor moves at an appropriate speed to achieve smooth focus, performing step S012 can avoid the problem of unstable focus caused by improper movement speed of the focus motor, thereby achieving smooth and precise focus adjustment and improving the dynamic performance and stability of the autofocus system.

[0087] Exemplarily, the current moving speed of the focus motor is obtained :

[0088] in, is the position difference between the current and last moment of the focus motor. Then the adjustment speed of the PID position loop output is With the current moving speed Subtract and get the speed error , and the speed error As the second input of the PID speed loop, the focus motor travel value is calculated through the PID speed loop :

[0089]

[0090]

[0091]

[0092] in, is the output of the speed loop, is the current proportional term value of the speed loop, is the current integral value of the speed loop, is the integral value of the speed loop at the previous moment, and its initial value is 0. is the current differential value of the speed loop, is the speed loop proportional gain, is the speed loop integral gain, is the speed loop differential gain, is the speed error of the speed loop at the previous moment, It is the time difference between the current moment and the previous moment of the speed loop, and its unit is second.

[0093] In this implementation, the phase detection focusing principle and the PID control algorithm principle are combined, and two PID control loops are set as a position loop and a speed loop, wherein the position loop is used to quickly execute autofocus to the clearest position, and the speed loop is used to execute the focusing speed. This avoids the complex calibration work required for traditional autofocus and the problem of limited applicability of calibration parameters, and implements a method that can quickly autofocus according to the phase difference value without calibration and can also adjust the focusing speed, thereby improving the focusing performance of the autofocus system.

[0094] Step S02 , executing the moving stroke value by the focus motor, so as to control the lens to focus on the target focus area by the focus motor.

[0095] In this embodiment, the movement stroke value of the focus motor is determined based on the phase difference value of the target focus area, and the focus motor is precisely controlled to adjust the lens position for focusing, thereby avoiding the focus failure problem caused by inaccurate movement of the focus motor, thereby achieving efficient and accurate focus adjustment.

[0096] In a feasible implementation manner, step S011 may further include steps S010 to S020: Step S010, comparing the adjustment speed with a preset speed threshold; It should be noted that the preset speed threshold refers to a pre-set speed limit value, which is used to limit the upper limit of the focus motor adjustment speed.

[0097] It is understandable that since it is necessary to ensure that the moving speed of the focus motor does not exceed the safe operating range of the focus motor, step S010 is performed to avoid a series of problems caused by the automatic focus system due to excessive movement speed, such as motor damage, focus overshoot or image blur, thereby protecting the focus system and ensuring a smooth focusing process.

[0098] Step S020: When the adjustment speed is greater than the preset speed threshold, the adjustment speed is adjusted to the preset speed threshold.

[0099] It can be understood that when the calculated adjustment speed exceeds the preset speed threshold, the speed of the focus motor needs to be limited to a safe range, so step S020 is performed to avoid problems such as mechanical wear, vibration or inaccurate focus caused by excessive speed of the focus motor, thereby ensuring the stability of the focus system and extending the service life of the focus system by limiting the maximum adjustment speed.

[0100] For example, when the comparison result shows that the adjustment speed Exceeding the preset speed threshold When Restricted to This can be achieved by: if > , then The value of ,Right now = In this way, the command speed of the focus motor is limited to a safe range, ensuring a smooth and safe focusing process.

[0101] In this embodiment, by adopting speed limitation means, problems caused by excessive adjustment speed of the focus motor, such as mechanical damage, system instability or reduced focus accuracy, are avoided, thereby ensuring that the focus motor operates within a safe operating speed range, thereby improving the stability and reliability of the focus system, while ensuring the accuracy of image focus and the smoothness of the focusing process.

[0102] In a feasible implementation manner, step S012 may further include steps S030 to S040: Step S030, comparing the moving stroke value with a preset stroke value threshold; It should be noted that the preset travel value threshold refers to a preset upper limit of the moving distance of the focus motor, which is used to limit the maximum distance that the focus motor moves the focus lens in one adjustment.

[0103] It is understandable that since it is necessary to ensure that the movement of the focus motor does not exceed its mechanical stroke limit, thereby avoiding mechanical damage to the focus system or over-focusing due to excessive movement distance, step S030 is performed. This can avoid problems caused by the focus motor moving too long, such as lens collision, mechanical structure damage or inaccurate focus, thereby protecting the focus system and ensuring that the focusing process is carried out within a safe range.

[0104] Step S040 , when the moving stroke value is greater than the preset stroke value threshold, adjusting the moving stroke value to the preset stroke value threshold.

[0105] It can be understood that when the calculated moving stroke value exceeds the preset stroke value threshold, the moving distance of the focus motor needs to be limited to a safe range, so step S040 is performed to avoid problems such as damage to the mechanical limit position or over-focusing of the focus motor due to excessive moving stroke, thereby ensuring the mechanical safety of the focus system and improving the focusing accuracy by limiting the maximum moving stroke.

[0106] For example, when the comparison result shows the moving stroke value of the focus motor Exceeded the preset travel value threshold When Restricted to This can be achieved by: if > , then The value of ,Right now = In this way, the moving stroke value of the focus motor is limited to a safe range, ensuring the safety and accuracy of the focusing process.

[0107] In the present embodiment, by adopting the means of stroke limitation, problems such as mechanical damage, over-focusing or unstable focusing caused by the focus motor moving beyond its mechanical limit are avoided, thereby ensuring that the focus system operates within a safe stroke range, thereby protecting the mechanical integrity of the focus mechanism, improving the accuracy of the focus operation and the reliability of the system, and ensuring the stability of image focus and image quality.

[0108] For example, to help understand the implementation process of the focusing method obtained by combining the first embodiment and the second embodiment, please refer to Fig. 9 , Fig. 9 A brief flowchart of a focusing method is provided, specifically: First, the captured image is acquired, that is, the current frame of the video data is obtained; then, the target block in the current frame and the original phase difference values ​​of several small blocks (i.e., target sub-blocks) inside the target block are obtained; after that, a fast adaptive autofocus algorithm is executed to make the target focus area clearly visible, and the intelligent algorithm is used to focus on a better area of ​​interest (a sub-area in the target focus area) within the target focus area, so that the overall target imaging clarity is more in line with user expectations; then the focus motor is moved to focus on a better area of ​​interest of the target block, so that the target block image is clear.

[0109] For further information, please refer to Fig.10 , Fig.10 A pixel acquisition flow diagram of a focusing method is provided. In the acquisition process of shooting an image, the original pixels of the image are first obtained, and then imaging pixels and phase detection pixels are separated from the original pixels of the image.

[0110] Please refer to Fig.11 , Fig.11 A focusing algorithm flow chart of a focusing method is provided. In the fast adaptive autofocus algorithm, a target area focus block (i.e., target block) is first determined, and then the target block is divided into a plurality of sub-areas (i.e., target sub-blocks), and the corresponding original phase difference values ​​of the target area and the plurality of sub-areas are obtained, so as to intelligently select a better target area focus block, and finally a motor is moved to focus so that the better target area is imaged clearly.

[0111] Please refer to Fig.12 , Fig.12 A PID flow chart of a focusing method is provided. First, the phase difference value of the target focusing area is subtracted from the target value 0 to obtain the position error. , and then the position error As the first input, it is input into the PID position loop to adjust the speed through the PID position loop output Then input the target speed as the maximum speed to limit v and get the adjusted speed v_limit. Then subtract the adjusted speed v_limit from the current motor speed value V (i.e. the current motor speed) to get the speed error. , and then the speed error As the second input, it is input into the PID speed loop to output the motor movement value (i.e. the movement stroke value) through the PID speed loop. , then limit the motor movement value, and move the motor based on the limited motor movement value, so as to achieve precise focusing on the target focus area.

[0112] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the focusing method of the present application. More simple transformations based on this technical concept are all within the protection scope of the present application.

[0113] 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 above-mentioned embodiment 1.

[0114] Reference below Fig.13 , which shows a schematic diagram of the structure 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: tablet computers), PMPs (Portable Media Players: portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.13 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0115] like Fig.13 As shown, the electronic device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the electronic device are also stored. The processing device 1001, ROM1002, and RAM1004 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 can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, 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 by wire 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. More or fewer systems can be implemented or have alternatively.

[0116] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. 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 the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0117] The electronic device provided by the present application adopts the focusing method in the above embodiment to solve the technical problem of how to quickly focus on a better area of ​​interest of the target block. Compared with the prior art, the beneficial effects of the electronic device provided by the present application are the same as the beneficial effects of the focusing method provided by the above embodiment, and other technical features in the electronic device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0118] It should be understood that the various parts disclosed in this 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 any one or more embodiments or examples in a suitable manner.

[0119] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0120] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the focusing method in the above-mentioned embodiment.

[0121] The computer-readable storage medium provided in 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 thereof. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program.

[0122] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by an electronic device, the electronic device: determines a target block to be focused in a current frame of video data, and multiple 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; obtains the original image pixels of the target block, and determines the phase difference values ​​of each area to be focused in the collection of areas to be focused based on the original image pixels, wherein each area to be focused includes the target block and the target sub-blocks; determines a target focus area according to each phase difference value, and focuses on the target focus area.

[0123] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate 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 (e.g., via the Internet using an Internet service provider).

[0124] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0125] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0126] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned focusing method, 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 computer-readable storage medium provided in the present application are the same as the beneficial effects of the focusing method provided in the above-mentioned embodiment, and will not be described in detail here.

[0127] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned focusing method when executed by a processor.

[0128] 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 a target block. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the focusing method provided by the above embodiment, which will not be repeated here.

[0129] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are 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 original pixels of the image of the target block, and determine 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, wherein each area to be focused includes the target block and each target sub-block; A target focus area is determined according to each phase difference value, and the target focus area is focused.

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 the case where the target 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: The step of focusing on the target focus area comprises: Determining a moving stroke value of a focus motor based on a phase difference value of the target focus area; 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.

6. The focusing method according to claim 1, wherein: The step of determining the moving stroke value of the focus motor based on the phase difference value of the target focus area comprises: Determine a first input of a preset PID position loop based on a difference between a phase difference value of the target focus area and a target value, and calculate an adjustment speed based on the first input through the preset PID position loop; The current moving speed of the focus motor is obtained, and based on the difference between the adjustment speed and the current moving speed, a second input of a preset PID speed loop is determined, and the moving stroke value of the focus motor is calculated based on the second input through the preset PID speed loop.

7. The focusing method according to claim 6, wherein: After the step of calculating the adjustment speed based on the first input by the preset PID position loop, the following step is further included: comparing the adjusted speed with a preset speed threshold; When the adjustment speed is greater than the preset speed threshold, the adjustment speed is adjusted to the preset speed threshold.

8. The focusing method according to claim 6, 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.

9. 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 8.

10. 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 8 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

  • Target identification method and device, equipment and storage medium

    CN116977404A

  • Focusing motor control method and device

    CN117201934A

  • Focusing control method, electronic equipment and medium

    CN117714856A

Cited By

  • Target tracking shooting method and device and storage medium

    CN120602785A

  • Phase difference generation method and system based on left and right images

    CN120807647A