Focusing method and device in point light source scene and storage medium

By tiling the image frames in the point light source scene and brightness value processing, the brightness variance between the candidate background and the light source area is determined, and the problem of focus failure in the point light source scene is solved, achieving a focus effect with high accuracy and low calculation amount.

CN120034738AActive Publication Date: 2025-05-23ZHEJIANG HUASHI INTELLIGENT INSPECTION TECH CO LTD
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202510481351.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-17
Publication Date
2025-05-23
Estimated Expiration
2045-04-17

AI Technical Summary

Technical Problem

In point light source scenarios, it is difficult for the prior art to accurately determine the clearest position of the image, resulting in a failed focus.

Method used

By acquiring the image frame and dividing it into tile, calculating the brightness value of each tile, dividing the candidate background and light source area, calculating the brightness variance between regions, selecting the light source area corresponding to the threshold with the largest variance, and determining the position of the extremely small brightness value as the optimal focus point.

Benefits of technology

It improves the accuracy and speed of focus, reduces the amount of calculation, and enhances the universality of the algorithm.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120034738A_ABST
    Figure CN120034738A_ABST
Patent Text Reader

Abstract

The invention discloses a focusing method and device in a point light source scene and a storage medium, and the method comprises the steps: carrying out the image block division of a current image frame, and obtaining a plurality of current frame image blocks; respectively taking the brightness value of each current frame image block as a candidate threshold value; dividing the current frame image blocks with the brightness values smaller than the candidate threshold value into candidate background areas, and dividing the current frame image blocks with the brightness values not smaller than the candidate threshold value into candidate light source areas; calculating the variance of the brightness values between the candidate background region and the candidate light source region, and obtaining a target light source region corresponding to the current image frame based on the candidate light source region corresponding to the candidate threshold with the maximum variance in the plurality of candidate thresholds; according to the method, the image block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame is determined, the optimal focusing position is obtained, the target light source area can be obtained through rapid and accurate division, the focusing accuracy is improved, the calculated amount is reduced, and the algorithm universality is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a focusing method, device and storage medium in a point light source scene. Background Art

[0002] During the image acquisition and focusing process, it is necessary to determine the clearest position of the image. The current mainstream method is still to use the hill climbing algorithm to find the pixel with the maximum clarity in the continuously changing contrast information of the image to determine the clearest position of the image. However, in point light source scenes, the light source in the defocused state usually has more edge information, resulting in the position with the maximum image contrast in this scene not necessarily being the real clear position. Therefore, it is very easy to fail to focus in point light source scenes if you simply rely on the contrast of the entire image.

[0003] The industry is currently actively exploring the issue of accurate focusing in point light source scenarios, but there is no completely effective solution yet. Summary of the invention

[0004] In order to solve the above technical problems, the present application at least provides a focusing method, device and storage medium in a point light source scene.

[0005] In a first aspect, the present application provides a focusing method in a point light source scene, the method comprising: obtaining a current image frame obtained by performing image acquisition on the point light source scene, dividing the current image frame into blocks to obtain a plurality of current frame blocks; calculating the brightness value of each current frame block, and taking the brightness value of each current frame block as a candidate threshold; dividing the current frame blocks whose brightness values ​​are less than the candidate threshold into candidate background areas, and dividing the current frame blocks whose brightness values ​​are not less than the candidate threshold into candidate light source areas; calculating the variance of the brightness values ​​between the candidate background areas and the candidate light source areas, and obtaining a target light source area corresponding to the current image frame based on the candidate light source area corresponding to the candidate threshold having the largest variance among the plurality of candidate thresholds; determining the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame, and obtaining the optimal focusing position.

[0006] In one embodiment, a target light source area corresponding to a current image frame is obtained based on a candidate light source area corresponding to a candidate threshold with the largest variance among multiple candidate thresholds, including: taking the candidate light source area corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds as the initial light source area corresponding to the current image frame; and obtaining a previous image frame corresponding to the current image frame, and obtaining the initial light source area corresponding to the previous image frame; wherein an image acquisition time of the previous image frame is earlier than an image acquisition time of the current image frame; and calculating the intersection of the initial light source area corresponding to the current image frame and the initial light source area corresponding to the previous image frame to obtain the target light source area corresponding to the current image frame.

[0007] In one embodiment, before determining the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame and obtaining the optimal focus position, it also includes: obtaining the previous image frame corresponding to the current image frame; taking any current frame block in the target light source area corresponding to the current image frame as the block to be detected, determining the block in the previous image frame that is at the same position as the block to be detected, and obtaining the previous reference block; calculating the variation amplitude between the brightness value of the block to be detected and the brightness value of the previous reference block; if the variation amplitude is greater than a preset amplitude threshold, correcting the brightness value of the block to be detected.

[0008] In one embodiment, any of the following strategies is used to correct the brightness value of the block to be detected: Strategy 1: weighted sum the brightness value of the previous reference block and the brightness value of the block to be detected to obtain the corrected brightness value of the block to be detected; Strategy 2: obtain the current frame block adjacent to the block to be detected in the current image frame to obtain the adjacent block, and weighted sum the brightness value of the adjacent block and the brightness value of the block to be detected to obtain the corrected brightness value of the block to be detected; Strategy 3: obtain the current frame block adjacent to the block to be detected in the current image frame to obtain the adjacent block, and weighted sum the brightness value of the adjacent block and the brightness value of the block to be detected to obtain the current brightness sum; weighted sum the brightness value of the previous reference block and the current brightness sum to obtain the corrected brightness value of the block to be detected.

[0009] In one embodiment, a weighted sum is performed on the brightness values ​​of adjacent blocks and the brightness values ​​of blocks to be detected, including: determining the distance between the adjacent blocks and the blocks to be detected; setting weight parameters corresponding to the adjacent blocks and the blocks to be detected based on the distance and / or the magnitude of the change amplitude; and performing a weighted sum of the brightness values ​​of the adjacent blocks and the brightness values ​​of the blocks to be detected based on the weight parameters.

[0010] In one embodiment, there are multiple strategies for correcting the brightness value of the image block to be detected; correcting the brightness value of the image block to be detected includes: selecting a matching strategy from multiple strategies based on the magnitude of the change to obtain a target strategy; and correcting the brightness value of the image block to be detected using the target strategy.

[0011] In one embodiment, the position of a block corresponding to the minimum brightness value in a target light source area is determined to obtain an optimal focus position, including: recording the current movement position and the current movement direction of the focus motor as a first motor position and a first movement direction, respectively, and detecting a change trend of the brightness value of the current frame block in the target light source area in the first movement direction; if the change trend is a downward trend, continue to move along the first movement direction to the second motor position; detect whether the brightness value of the current frame block corresponding to the second motor position is a minimum value; if the brightness value of the current frame block corresponding to the second motor position is a minimum value, use the second motor position as the optimal focus position.

[0012] In one embodiment, detecting whether the brightness value of the current frame block corresponding to the second motor position is a minimum value includes: detecting the change trend of the brightness value corresponding to each movement direction of the second motor position, and if there is no downward trend, determining that the brightness value of the current frame block corresponding to the second motor position is a minimum value.

[0013] According to a second aspect of the present application, there is provided a focusing device in a point light source scene, the device comprising: a block division module, used to obtain a current image frame obtained by performing image acquisition on the point light source scene, and divide the current image frame into blocks to obtain a plurality of current frame blocks; a candidate threshold selection module, used to calculate the brightness value of each current frame block, and respectively use the brightness value of each current frame block as a candidate threshold; a region division module, used to divide the current frame blocks whose brightness values ​​are less than the candidate threshold into candidate background regions, and divide the current frame blocks whose brightness values ​​are not less than the candidate threshold into candidate light source regions; a target region determination module, used to calculate the variance of the brightness values ​​between the candidate background regions and the candidate light source regions, and obtain the target light source region corresponding to the current image frame based on the candidate light source region corresponding to the candidate threshold with the largest variance among the plurality of candidate thresholds; and a focusing module, used to determine the block position corresponding to the minimum brightness value in the target light source region corresponding to the current image frame, and obtain the optimal focusing position.

[0014] A third aspect of the present application provides an electronic device, including a memory and a processor, wherein the processor is used to execute program instructions stored in the memory to implement the above-mentioned focusing method in the point light source scene.

[0015] A fourth aspect of the present application provides a computer-readable storage medium having program instructions stored thereon, which, when executed by a processor, implements the focusing method in the above-mentioned point light source scene.

[0016] The above scheme obtains the current image frame obtained by image acquisition of the point light source scene, divides the current image frame into blocks, and obtains multiple current frame blocks; calculates the brightness value of each current frame block, and uses the brightness value of each current frame block as a candidate threshold; divides the current frame blocks with brightness values ​​less than the candidate threshold into candidate background areas, and divides the current frame blocks with brightness values ​​not less than the candidate threshold into candidate light source areas; calculates the variance of the brightness values ​​between the candidate background areas and the candidate light source areas, and obtains the target light source area corresponding to the current image frame based on the candidate light source area corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds; determines the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame, and obtains the best focusing position, which can quickly and accurately select the target light source area obtained by division under the optimal threshold, improve focusing accuracy, quickly achieve focusing, and reduce the amount of calculation at the same time. In addition, since the algorithm does not require high chip capabilities, the versatility of the algorithm is enhanced.

[0017] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.

[0019] Figure 1 is a schematic diagram of a solution implementation environment shown in an exemplary embodiment of the present application; Figure 2 is a flow chart of a focusing method in a point light source scene shown by an exemplary embodiment of the present application; Figure 3 is a flow chart of determining an optimal threshold value shown in an exemplary embodiment of the present application; Figure 4 is a schematic diagram showing a method of determining a target light source area according to an exemplary embodiment of the present application; Figure 5 is a schematic diagram showing a method of correcting brightness values ​​according to a preceding image frame and adjacent image blocks according to an exemplary embodiment of the present application; Figure 6 is a block diagram of a focusing device in a point light source scenario shown in an exemplary embodiment of the present application; Figure 7 is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present application; Figure 8 It is a schematic diagram of the structure of a computer-readable storage medium shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0020] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.

[0021] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.

[0022] The term "and / or" in this article is only an association information describing the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the previous and next associated objects are in an "or" relationship. In addition, "many" in this article means two or more than two. In addition, the term "at least one" in this article means any combination of at least two of any one or more of a plurality of, for example, including at least one of A, B, and C, can mean including any one or more elements selected from the set consisting of A, B, and C.

[0023] In the related art, if there is a point light source in the captured image, the number of highlighted pixels in a single image area is generally used to determine whether there is a point light source in the image area. This requires the image processing chip itself to provide the number of highlighted pixels, and requires the image processing chip to divide the image into blocks to obtain a large number of blocks. However, due to the capacity limitations of different image processing chips, not all image processing chips have the ability to provide highlighted pixels and to divide a large number of images into blocks. When the number of image blocks on the chip side is small and the information provided is small, the point light source area determined by the above method is not accurate, and the versatility of the above method is poor.

[0024] Based on this, the present application provides a more versatile focusing method in a point light source scenario. The focusing method in a point light source scenario provided by an embodiment of the present application is described below.

[0025] Please refer to Figure 1 , Figure 1 1 is a schematic diagram of a solution implementation environment shown in an exemplary embodiment of the present application. The solution implementation environment may include an image acquisition device 110 and a server 120, and the image acquisition device 110 and the server 120 are connected to each other for communication.

[0026] The number of image acquisition devices 110 can be used to perform image acquisition, and the image acquisition device 110 can be a camera, a smart phone, a tablet computer, a smart watch, etc., but is not limited thereto.

[0027] Server 120 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.

[0028] In an example, the server 120 may determine the best focus position according to the current image frame acquired from the image acquisition device 110 , and then the server 120 may transmit the best focus position back to the image acquisition device 110 .

[0029] In one example, a client running a target application is installed in the image acquisition device 110. The target application may be an application that provides an optimal focus position calculation function, and the optimal focus position is calculated based on the target application. The server 120 may be a background server of the target application, which is used to provide background services for the client of the target application.

[0030] In the focusing method for a point light source scene provided in an embodiment of the present application, the execution subject of each step may be the image acquisition device 110, such as a client of a target application installed and running in the image acquisition device 110, or the server 120, or the image acquisition device 110 and the server 120 may cooperate with each other to execute the method, that is, a part of the steps of the method are executed by the image acquisition device 110 and the other part of the steps are executed by the server 120.

[0031] See also Figure 2 , Figure 2 is a flowchart of a focusing method in a point light source scene shown in an exemplary embodiment of the present application. The focusing method in the point light source scene can be applied to Figure 1 It should be understood that the method can also be applied to other exemplary implementation environments and be specifically executed by devices in other implementation environments, and this embodiment does not limit the implementation environment to which the method is applicable.

[0032] like Figure 2 As shown, the focusing method in the point light source scene at least includes steps S210 to S250, which are described in detail as follows: Step S210: obtaining a current image frame obtained by performing image acquisition on a point light source scene, and dividing the current image frame into blocks to obtain a plurality of current frame blocks.

[0033] The image acquisition device performs image acquisition in a point light source scene. At this time, the acquired image frame contains the point light source, and the currently acquired image frame is used as the current image frame.

[0034] The current image frame is divided into blocks to obtain a plurality of current frame blocks.

[0035] It should be noted that the size of the current frame blocks obtained by dividing the current frame by different image processing chips may be different. The block division can also be performed on the current image frame. The block division.

[0036] Step S220: Calculate the brightness value of each current frame block, and use the brightness value of each current frame block as a candidate threshold.

[0037] For each current frame block, the brightness value corresponding to the current frame block is calculated. For example, the sum of the brightness values ​​of each pixel in the current frame block is calculated to obtain the brightness value corresponding to the current frame block; for another example, the average value between the brightness values ​​of each pixel in the current frame block is calculated to obtain the brightness value corresponding to the current frame block.

[0038] The brightness value of each current frame block is obtained, and the brightness value of each current frame block is taken as a candidate threshold in turn.

[0039] For example, an image histogram is obtained from the brightness value of each current frame block, and starting from the minimum brightness value in the image histogram, each brightness value is used as a candidate threshold in sequence until the maximum brightness value is reached.

[0040] Step S230: dividing the current frame image blocks whose brightness values ​​are less than the candidate threshold into candidate background areas, and dividing the current frame image blocks whose brightness values ​​are not less than the candidate threshold into candidate light source areas.

[0041] A region division is performed for each candidate threshold. Specifically, the current frame image blocks with brightness values ​​less than the candidate threshold are divided into candidate background regions, and the current frame image blocks with brightness values ​​not less than the candidate threshold are divided into candidate light source regions.

[0042] For example, if the currently selected candidate threshold is 100, the current frame image blocks with brightness values ​​less than 100 are divided into candidate background areas, and the current frame image blocks with brightness values ​​not less than 100 are divided into candidate light source areas.

[0043] Step S240: Calculate the variance of the brightness values ​​between the candidate background area and the candidate light source area, and obtain the target light source area corresponding to the current image frame based on the candidate light source area corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds.

[0044] Through the above method, each candidate threshold is divided into a candidate background area and a candidate light source area. For any candidate threshold, the variance of the brightness values ​​between the candidate background area and the candidate light source area corresponding to the candidate threshold is calculated, and the candidate threshold with the largest variance among multiple candidate thresholds is determined, and the candidate threshold with the largest variance is taken as the optimal threshold.

[0045] For example, see Figure 3 , Figure 3 is a flowchart of determining an optimal threshold value shown in an exemplary embodiment of the present application, such as Figure 3 As shown, including: Step S310: obtaining an image histogram from the brightness value of each current frame block, and initializing the maximum variance value to 0; Step S320: starting with the minimum brightness value in the image histogram, traversing each brightness value in the image histogram in turn as a candidate threshold; Step S330: Calculate the variance of the brightness values ​​between the candidate background area and the candidate light source area corresponding to the currently traversed candidate threshold; Step S340: whether the variance of the brightness value between the candidate background area and the candidate light source area is greater than the maximum variance, if so, execute step S350, if not, execute step S360; Step S350: assigning the variance of the brightness values ​​between the candidate background area and the candidate light source area to the maximum variance, and recording the candidate threshold value corresponding to the maximum variance; Step S360: Check whether each brightness value in the image histogram has been traversed. If not, execute S320. If yes, execute step S370. Step S370: Output the candidate threshold corresponding to the maximum variance as the optimal threshold.

[0046] The specific calculation method of the variance of the brightness value between the candidate background area and the candidate light source area is shown in the following formulas 1 to 3: Formula 1:

[0047] Formula 2:

[0048] Formula 3:

[0049] Among them, Variance is the variance of the brightness values ​​between the candidate background area and the candidate light source area; W0 is the number of current frame blocks contained in the candidate background area; W1 is the number of current frame blocks contained in the candidate light source area; T0 is the average value between the brightness values ​​corresponding to each current frame block in the candidate background area; T1 is the average value between the brightness values ​​corresponding to each current frame block in the candidate light source area; Tavg is the average brightness of the current image frame.

[0050] Of course, other variance calculation algorithms may also be used to calculate the variance of the brightness values ​​between the candidate background area and the candidate light source area, and this application does not limit this.

[0051] Optionally, when determining the optimal threshold, in addition to considering the variance of the brightness values ​​between the candidate background area and the candidate light source area, the variance of the brightness values ​​within the candidate background area and the variance of the brightness values ​​within the candidate light source area can be further considered. The variance of the brightness values ​​within the candidate background area and the candidate light source area can be minimized, but the variance of the brightness values ​​between the candidate background area and the candidate light source area can be maximized, and the optimal threshold can be selected from multiple candidate thresholds.

[0052] Then, based on the candidate light source area corresponding to the optimal threshold, the target light source area corresponding to the current image frame is obtained. For example, the candidate light source area corresponding to the optimal threshold is directly used as the target light source area corresponding to the current image frame; for another example, the candidate light source area corresponding to the optimal threshold is adjusted with reference to other image frames to obtain the target light source area corresponding to the current image frame. For specific implementation methods, please refer to the embodiments listed later.

[0053] Step S250: determining the image block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame, and obtaining the best focus position.

[0054] After obtaining the target light source area corresponding to the current image frame, the block position corresponding to the minimum brightness value in the target light source area is determined and used as the best focus position.

[0055] For example, the block position corresponding to the current frame block with the smallest brightness value in the target light source area corresponding to the current image frame can be directly used as the optimal focus position; the brightness value change trend of the passed block position can also be detected during the gradual movement of the focusing motor, and the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame collected in real time can be determined to obtain the optimal focus position. This application does not limit this.

[0056] The focusing method in the point light source scene disclosed in the present application divides the candidate light source area and the candidate background area into candidate light source areas by sequentially selecting the brightness values ​​corresponding to the current frame blocks as subsequent thresholds, and then sequentially judging the variance of the brightness values ​​between the candidate background area and the candidate light source area. This method can accurately select the light source area obtained by division under the optimal threshold, thereby improving the focusing accuracy. In general, there are blocks with consistent brightness values ​​in the current image frame. Therefore, the amount of calculation can be reduced and focusing can be achieved quickly. In addition, the algorithm does not have high requirements on chip capabilities, which can enhance the versatility of the algorithm.

[0057] Next, some embodiments of the present application are described in detail.

[0058] In some embodiments, in step S240, a target light source area corresponding to the current image frame is obtained based on a candidate light source area corresponding to a candidate threshold with the largest variance among multiple candidate thresholds, including: taking the candidate light source area corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds as the initial light source area corresponding to the current image frame; and obtaining a previous image frame corresponding to the current image frame, and obtaining the initial light source area corresponding to the previous image frame; wherein an image acquisition time of the previous image frame is earlier than an image acquisition time of the current image frame; and calculating the intersection of the initial light source area corresponding to the current image frame and the initial light source area corresponding to the previous image frame to obtain the target light source area corresponding to the current image frame.

[0059] Considering that point light sources in point light source scenes are prone to change (such as flashing lights or fast-moving car lights), in order to improve focusing accuracy, the candidate light source area corresponding to the optimal threshold is adjusted based on the previous image frame.

[0060] Specifically, the candidate light source region corresponding to the candidate threshold value with the largest variance among the multiple candidate threshold values ​​is used as the initial light source region corresponding to the current image frame, and the previous image frame captured before the current image frame is obtained, and the initial light source region corresponding to the previous image frame is obtained in the same manner. The initial light source regions corresponding to the current image frame and the previous image frame both contain multiple blocks, and the intersection of the blocks in the initial light source region corresponding to the current image frame and the initial light source region corresponding to the previous image frame is taken to obtain the target light source region corresponding to the current image frame.

[0061] For example, after obtaining the initial light source area corresponding to the current image frame and the initial light source area corresponding to the previous image frame, detect whether the blocks at the same position are all included in the initial light source area corresponding to the current image frame and the initial light source area corresponding to the previous image frame. If they are all included in the initial light source area corresponding to the current image frame and the initial light source area corresponding to the previous image frame, retain the current block at that position in the current image frame, detect whether each current block in the initial light source area corresponding to the current image frame is to be retained in the above manner, merge all current blocks that need to be retained, and obtain the target light source area corresponding to the current image frame.

[0062] For an example, see Figure 4 , Figure 4 is a schematic diagram of determining a target light source area shown in an exemplary embodiment of the present application. Figure 4 As shown, after taking the intersection of the initial light source region corresponding to the current image frame and the initial light source region corresponding to the previous image frame, the target light source region corresponding to the current image frame is obtained.

[0063] It should be noted that Figure 4Only one preceding image frame is used as an example for schematic illustration. In actual application scenarios, more preceding image frames may be selected to determine the target light source area, and this application does not limit this.

[0064] Optionally, the number of previous image frames to be acquired can be flexibly determined based on the actual situation of the current image frame. For example, the number of previous image frames to be acquired can be determined based on the average brightness of the current image frame and / or the number of current frame blocks contained in the initial light source area corresponding to the current image frame, wherein the average brightness of the current image frame and the number of current frame blocks in the initial light source area corresponding to the current image frame are proportional to the number of previous image frames to be acquired.

[0065] Of course, in addition to the above-mentioned embodiment in which the number of previous image frames is flexibly calculated based on parameters such as the average brightness of the current image frame, the number of current frame blocks in the initial light source area corresponding to the current image frame, etc., the number of previous image frames to be acquired can also be pre-set based on experience, and the present application does not limit this.

[0066] Through the above embodiments, the interference of the flickering light source can be avoided, and a more accurate target light source area can be obtained, which is convenient for subsequent focusing.

[0067] In some embodiments, before determining the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame and obtaining the optimal focus position, it also includes: obtaining the previous image frame corresponding to the current image frame; taking any current frame block in the target light source area corresponding to the current image frame as the block to be detected, determining the block in the previous image frame that is at the same position as the block to be detected, and obtaining the previous reference block; calculating the variation amplitude between the brightness value of the block to be detected and the brightness value of the previous reference block; if the variation amplitude is greater than a preset amplitude threshold, correcting the brightness value of the block to be detected.

[0068] The preset amplitude threshold is preset based on experience.

[0069] Taking into account that the brightness of the light source in the environment may change, in order to improve the focusing stability, the brightness information of the current frame block in the target light source area is judged by referring to the previous image frame, and the brightness value of the current frame block with a large change is corrected.

[0070] Exemplarily, any of the following strategies is used to correct the brightness value of the image block to be detected: Strategy 1: Perform a weighted sum of the brightness value of the previous reference block and the brightness value of the block to be detected to obtain the corrected brightness value of the block to be detected.

[0071] The number of preceding reference blocks may be one or more.

[0072] The brightness value of the previous reference block and the brightness value of the block to be detected are weightedly summed to obtain the corrected brightness value of the block to be detected.

[0073] When weighted summing the brightness value of the preceding reference block and the brightness value of the block to be detected is performed, the weight parameter used can be pre-set, such as the weight parameter of the brightness value of the preceding reference block is 0.4, and the weight parameter of the brightness value of the block to be detected is 0.6; it is also possible to calculate the interval duration between the image acquisition time of the preceding reference block and the image acquisition time of the block to be detected, and / or obtain the magnitude of the change amplitude, and set the weight parameters corresponding to the brightness value of the preceding reference block and the brightness value of the block to be detected according to the interval duration and / or the magnitude of the change amplitude. For example, the smaller the interval duration and the larger the change amplitude, the larger the weight parameter corresponding to the brightness value of the preceding reference block and the smaller the weight parameter corresponding to the brightness value of the block to be detected; conversely, the larger the interval duration and the smaller the change amplitude, the smaller the weight parameter corresponding to the brightness value of the preceding reference block and the larger the weight parameter corresponding to the brightness value of the block to be detected.

[0074] Based on the weight parameter, the brightness value of the previous reference block and the brightness value of the block to be detected are weighted and summed to obtain the corrected brightness value of the block to be detected.

[0075] Strategy 2: Obtain the current frame block adjacent to the block to be detected in the current image frame to obtain the adjacent block, perform weighted summation on the brightness value of the adjacent block and the brightness value of the block to be detected, and obtain the corrected brightness value of the block to be detected.

[0076] The current frame block whose distance to the block to be detected in the current image frame is less than the distance threshold is taken as the adjacent block corresponding to the block to be detected, wherein the distance threshold can be pre-set based on experience, or can be flexibly set according to the magnitude of the change amplitude, the larger the change amplitude, the larger the distance threshold, and the smaller the change amplitude, the smaller the distance threshold.

[0077] The brightness values ​​of the adjacent blocks and the brightness value of the block to be detected are weightedly summed to obtain the corrected brightness value of the block to be detected.

[0078] When weighted summing the brightness values ​​of adjacent blocks and the brightness values ​​of blocks to be detected, the weight parameters used can be pre-set, such as a weight parameter of 0.1 for the brightness values ​​of adjacent blocks and a weight parameter of 0.4 for the brightness values ​​of blocks to be detected; the distance between the adjacent blocks and the blocks to be detected can also be calculated, and / or the magnitude of the variation amplitude can be obtained, and the weight parameters corresponding to the brightness values ​​of the adjacent blocks and the brightness values ​​of the blocks to be detected can be set according to the distance and / or the magnitude of the variation amplitude. For example, the smaller the distance and the larger the variation amplitude, the larger the weight parameter corresponding to the brightness value of the adjacent blocks and the smaller the weight parameter corresponding to the brightness value of the blocks to be detected; conversely, the larger the distance and the smaller the variation amplitude, the smaller the weight parameter corresponding to the brightness value of the adjacent blocks and the larger the weight parameter corresponding to the brightness value of the blocks to be detected.

[0079] Based on the weight parameter, the brightness values ​​of the adjacent blocks and the brightness value of the block to be detected are weighted and summed to obtain the corrected brightness value of the block to be detected.

[0080] Strategy three: Get the current frame block adjacent to the block to be detected in the current image frame to obtain the adjacent block, perform weighted summation on the brightness value of the adjacent block and the brightness value of the block to be detected to obtain the current brightness sum; perform weighted summation on the brightness value of the previous reference block and the current brightness sum to obtain the corrected brightness value of the block to be detected.

[0081] The brightness information of the previous image frame and the adjacent image blocks is considered at the same time, and the brightness values ​​of the adjacent image blocks, the brightness values ​​of the previous reference image blocks and the brightness values ​​of the image blocks to be detected are weightedly summed to obtain the corrected brightness value of the image blocks to be detected.

[0082] The method for setting the weight parameters used in the weighted summation in Strategy 3 can refer to the method for setting the weight parameters in Strategy 1 and Strategy 2, which will not be repeated here.

[0083] For an example, see Figure 5 , Figure 5 is a schematic diagram showing an exemplary embodiment of the present application for modifying brightness values ​​according to a preceding image frame and adjacent image blocks, such as Figure 5 As shown, the brightness value of the block to be detected is Ycur, the brightness value of the previous reference block is Ylast, and the brightness values ​​of the adjacent blocks include Y1, Y2, Y3, Y4, Y5, Y6, Y7, and Y8 respectively.

[0084] Assuming that the weight parameters corresponding to Y2, Y4, Y5, and Y7 are 0.1, the weight parameters corresponding to Y1, Y3, Y6, and Y8 are 0.05, and the weight parameter corresponding to Ycur is 0.4, the brightness values ​​of adjacent blocks and the brightness value of the block to be detected are weighted and summed to obtain the specific calculation formula for the current brightness sum. See the following formula 4:

[0085] Among them, Yall is the current total brightness.

[0086] Assuming that the weight parameter corresponding to Ylast is 0.4, the weight parameter corresponding to Yall is 0.05, and the weight parameter corresponding to Ycur is 0.6, the brightness value of the previous reference block and the sum of the current brightness are weighted and summed to obtain the corrected brightness value of the block to be detected. For the specific calculation formula, see the following formula 5:

[0087] Wherein, Y is the corrected brightness value of the image block to be detected.

[0088] Optionally, if the adjacent image block does not belong to the target light source area, the brightness value of the adjacent image block may be set to 0 for calculation.

[0089] The above strategies correct the brightness value of the current frame block in the target light source area based on adjacent blocks and / or previous reference blocks to avoid unstable focus search caused by large brightness changes and reduce focus accuracy.

[0090] In some embodiments, there are multiple strategies for correcting the brightness value of the image block to be detected; correcting the brightness value of the image block to be detected includes: selecting a matching strategy from multiple strategies based on the magnitude of the change to obtain a target strategy; and correcting the brightness value of the image block to be detected using the target strategy.

[0091] The parameters considered corresponding to different strategies may be different. For example, the above-mentioned strategy one corrects the brightness value according to the brightness value of the previous reference block, the strategy two corrects the brightness value according to the brightness value of the adjacent block, and the strategy three corrects the brightness value by combining the brightness values ​​of the previous reference block and the adjacent block; the weight coefficients corresponding to different strategies may be different, and the number of selected previous reference blocks and / or the number of adjacent blocks corresponding to different strategies may be different, which is not limited in the present application.

[0092] According to the magnitude of the change, a matching strategy is selected from multiple strategies to obtain a target strategy. For example, the strategies for correcting the brightness value of the detected block include the above-mentioned strategies 1, 2, and 3. If the change is detected to be greater than the preset amplitude threshold, strategy selection is performed: if the change is less than the first abnormal threshold, strategy 1 is selected as the target strategy; if the change is less than the second abnormal threshold but greater than the first abnormal threshold, strategy 2 is selected as the target strategy; if the change is less than the third abnormal threshold but greater than the second abnormal threshold, strategy 3 is selected as the target strategy.

[0093] Determining the target strategy according to the magnitude of the change can improve the accuracy of brightness correction and further reduce the amount of calculation.

[0094] In some embodiments, step S250 determines the tile position corresponding to the minimum brightness value in the target light source area to obtain the optimal focus position, including: recording the current movement position and the current movement direction of the focus motor as the first motor position and the first movement direction, respectively, and detecting the change trend of the brightness value of the current frame tile in the target light source area in the first movement direction; if the change trend is a downward trend, continue to move along the first movement direction to the second motor position; detect whether the brightness value of the current frame tile corresponding to the second motor position is a minimum value; if the brightness value of the current frame tile corresponding to the second motor position is a minimum value, use the second motor position as the optimal focus position.

[0095] The focus motor moves in a first movement direction from a first motor position by default, and detects the change trend of the brightness value of the current frame block in the target light source area in the first movement direction. For example, if the brightness value of the nearest current frame block in the target light source area in the first movement direction is less than the brightness value of the first motor position, the change trend is a downward trend; if the brightness value of the nearest current frame block in the target light source area in the first movement direction is not less than the brightness value of the first motor position, the change trend is not a downward trend.

[0096] If the changing trend is a downward trend, continue to move along the first moving direction to the second motor position.

[0097] If the change trend is not a downward trend, take other movement directions different from the first movement direction as the second movement direction, and continue to detect whether the change trend of the brightness value of the current frame block in the target light source area on the second movement is a downward trend, until the movement direction of the downward trend is detected, and move along the movement direction of the downward trend to the second motor position.

[0098] Detect whether the brightness value of the current frame block corresponding to the second motor position is a minimum value. If the brightness value of the current frame block corresponding to the second motor position is a minimum value, take the second motor position as the optimal focusing position; if the brightness value of the current frame block corresponding to the second motor position is not a minimum value, continue to move in the above manner until a minimum value is detected.

[0099] Exemplarily, detecting whether the brightness value of the current frame block corresponding to the second motor position is a minimum value includes: detecting the changing trend of the brightness values ​​corresponding to each movement direction of the second motor position, and if there is no downward trend, judging that the brightness value of the current frame block corresponding to the second motor position is a minimum value.

[0100] The focusing method in a point light source scene provided by the present application obtains a current image frame obtained by image acquisition of the point light source scene, divides the current image frame into blocks, and obtains multiple current frame blocks; calculates the brightness value of each current frame block, and uses the brightness value of each current frame block as a candidate threshold; divides the current frame blocks with brightness values ​​less than the candidate threshold into candidate background areas, and divides the current frame blocks with brightness values ​​not less than the candidate threshold into candidate light source areas; calculates the variance of the brightness values ​​between the candidate background areas and the candidate light source areas, and obtains the target light source area corresponding to the current image frame based on the candidate light source area corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds; determines the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame, and obtains the best focusing position, so that the target light source area obtained by division under the optimal threshold can be quickly and accurately selected, thereby improving the focusing accuracy, quickly achieving focusing, and reducing the amount of calculation at the same time. In addition, since the algorithm does not have high requirements on chip capabilities, the versatility of the algorithm is enhanced.

[0101] Figure 6 FIG. 1 is a block diagram of a focusing device in a point light source scenario shown in an exemplary embodiment of the present application. Figure 6 As shown, the focusing device 600 in the exemplary point light source scenario includes: The image block division module 610 is used to obtain a current image frame obtained by performing image acquisition on a point light source scene, and divide the current image frame into blocks to obtain a plurality of current frame blocks; A candidate threshold selection module 620 is used to calculate the brightness value of each current frame block and use the brightness value of each current frame block as a candidate threshold; A region division module 630 is used to divide the current frame image blocks whose brightness values ​​are less than the candidate threshold into candidate background regions, and divide the current frame image blocks whose brightness values ​​are not less than the candidate threshold into candidate light source regions; The target region determination module 640 is used to calculate the variance of the brightness values ​​between the candidate background region and the candidate light source region, and obtain the target light source region corresponding to the current image frame based on the candidate light source region corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds; The focusing module 650 is used to determine the image block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame to obtain the best focusing position.

[0102] It should be noted that the focusing device in the point light source scene provided in the above embodiment and the focusing method in the point light source scene provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here. In actual applications, the focusing device in the point light source scene provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.

[0103] See also Figure 7 , Figure 7 7 is a schematic diagram of the structure of an embodiment of an electronic device of the present application. The electronic device 700 includes a memory 701 and a processor 702, and the processor 702 is used to execute the program instructions stored in the memory 701 to implement the steps in the embodiment of the focusing method in any point light source scene described above. In a specific implementation scenario, the electronic device 700 may include but is not limited to: a microcomputer, a server, and in addition, the electronic device 700 may also include a mobile device such as a laptop computer and a tablet computer, which is not limited here.

[0104] Specifically, the processor 702 is used to control itself and the memory 701 to implement the steps in the focusing method embodiment under any of the above-mentioned point light source scenarios. The processor 702 can also be called a central processing unit (CPU). The processor 702 may be an integrated circuit chip with signal processing capabilities. The processor 702 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 702 can be implemented by an integrated circuit chip.

[0105] See also Figure 8 , Figure 8 The computer-readable storage medium 800 stores program instructions 810 that can be executed by a processor, and the program instructions 810 are used to implement the steps in the above-mentioned focusing method embodiment in any point light source scene.

[0106] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0107] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.

[0108] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0109] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.

Claims

1. A focusing method in a point light source scene, characterized in that: The method comprises: Acquire a current image frame obtained by performing image acquisition on a point light source scene, and divide the current image frame into blocks to obtain a plurality of current frame blocks; Calculate the brightness value of each current frame block, and use the brightness value of each current frame block as a candidate threshold; The current frame image blocks whose brightness values ​​are less than the candidate threshold are divided into candidate background areas, and the current frame image blocks whose brightness values ​​are not less than the candidate threshold are divided into candidate light source areas; Calculate the variance of the brightness values ​​between the candidate background area and the candidate light source area, and obtain the target light source area corresponding to the current image frame based on the candidate light source area corresponding to the candidate threshold with the largest variance among multiple candidate thresholds; The block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame is determined to obtain the best focus position.

2. The method according to claim 1, characterized in that The step of obtaining the target light source region corresponding to the current image frame based on the candidate light source region corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds includes: Taking the candidate light source region corresponding to the candidate threshold with the largest variance among the multiple candidate thresholds as the initial light source region corresponding to the current image frame; and obtaining a previous image frame corresponding to the current image frame, and obtaining the initial light source region corresponding to the previous image frame; wherein the image acquisition time of the previous image frame is earlier than the image acquisition time of the current image frame; The intersection of the initial light source region corresponding to the current image frame and the initial light source region corresponding to the previous image frame is calculated to obtain the target light source region corresponding to the current image frame.

3. The method according to claim 1, characterized in that Before determining the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame to obtain the best focus position, the method further includes: Obtaining a previous image frame corresponding to the current image frame; Taking any current frame image block in the target light source area corresponding to the current image frame as the image block to be detected, determining an image block in the previous image frame that is at the same position as the image block to be detected, and obtaining a previous reference image block; Calculating a variation between a brightness value of the image block to be detected and a brightness value of the preceding reference image block; If the change amplitude is greater than the preset amplitude threshold, the brightness value of the image block to be detected is corrected.

4. The method according to claim 3, characterized in that The brightness value of the image block to be detected is corrected by using any of the following strategies: Strategy 1: performing a weighted summation on the brightness value of the previous reference block and the brightness value of the block to be detected to obtain a corrected brightness value of the block to be detected; Strategy 2: Obtain a current frame block adjacent to the block to be detected in the current image frame to obtain an adjacent block, perform a weighted summation on the brightness value of the adjacent block and the brightness value of the block to be detected to obtain a corrected brightness value of the block to be detected; Strategy three: obtain the current frame block adjacent to the block to be detected in the current image frame to obtain the adjacent block, perform weighted summation on the brightness value of the adjacent block and the brightness value of the block to be detected to obtain the current brightness sum; perform weighted summation on the brightness value of the previous reference block and the current brightness sum to obtain the corrected brightness value of the block to be detected.

5. The method according to claim 4, characterized in that The weighted summing of the brightness values ​​of the adjacent blocks and the brightness value of the block to be detected comprises: Determining the distance between the adjacent image block and the image block to be detected; Based on the distance and / or the magnitude of the change amplitude, respectively set weight parameters corresponding to the adjacent image block and the image block to be detected; A weighted sum is performed on the brightness values ​​of the adjacent image blocks and the brightness value of the image block to be detected based on the weight parameter.

6. The method according to claim 3, characterized in that There are multiple strategies for correcting the brightness value of the image block to be detected; the correcting the brightness value of the image block to be detected includes: Selecting a matching strategy from multiple strategies based on the magnitude of the change to obtain a target strategy; The target strategy is adopted to correct the brightness value of the image block to be detected.

7. The method according to claim 1, characterized in that The determining the block position corresponding to the minimum brightness value in the target light source area corresponding to the current image frame to obtain the best focus position includes: Recording the current movement position and the current movement direction of the focus motor as a first motor position and a first movement direction respectively, and detecting a change trend of the brightness value of the current frame image block in the target light source area in the first movement direction; If the change trend is a downward trend, continue to move along the first movement direction to the second motor position; Detecting whether the brightness value of the current frame block corresponding to the second motor position is a minimum value; If the brightness value of the current frame image block corresponding to the second motor position is a minimum value, the second motor position is used as the best focus position.

8. The method according to claim 7, characterized in that The detecting whether the brightness value of the current frame block corresponding to the second motor position is a minimum value includes: The change trend of the brightness value corresponding to each movement direction of the second motor position is detected. If there is no downward trend, it is determined that the brightness value of the current frame block corresponding to the second motor position is a minimum value.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein the processor is configured to execute program instructions stored in the memory to implement the steps in the method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, and the program instructions can be executed by a processor to implement the steps in the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Identification and focusing method for point light source scene

    CN104853087A

  • Automatic focusing processing method and device

    CN105430268A

  • Method and device for improving automatic focusing accuracy and speed of camera

    CN110166692A

  • Focusing processing method and device

    CN112911153A

  • Focusing processing method and device, camera device and storage medium

    CN114245023A