A focusing control method, device, electronic device and storage medium
By obtaining the brightness gradient information and regional score value of the image to be focused in the camera equipment, and adjusting the traveling direction of the focusing motor, the problem of focusing failure in point light source scenarios is solved, the accuracy and efficiency of focusing are improved, and the quality of the monitoring screen is improved. quality.
Patent Information
- Application Number
- CN202411007682.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-25
AI Technical Summary
Existing technology is difficult to achieve accurate and efficient focusing of camera equipment in point light source scenarios, and is prone to focus failure or out-of-focus images, affecting the visual experience of the surveillance image.
By obtaining the image to be focused when the focus motor is at the first focus position, determine the reference light source area, calculate the image brightness gradient information of the sub-image block, filter the brightness reference area, calculate the regional score value based on the brightness gradient information and regional brightness statistical information, and control The focus motor travels to the second or third focus position to adjust the focus direction and avoid relying on unreliable sharpness evaluation functions.
It improves the focusing accuracy and efficiency in point light source scenarios, avoids focusing failures and out-of-focus images, and improves the visual experience of monitoring images.
Smart Images

Figure CN118540581B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of monitoring image processing, and in particular to a focusing control method, device, electronic device and storage medium. Background Art
[0002] With the advancement of technology, more and more scenarios require the use of video equipment for security monitoring. During the monitoring process, how to control the device to accurately focus in order to obtain a clear target image is an important research direction. Focusing methods usually include manual focusing and automatic focusing, among which automatic focusing technology is widely used in various types of video equipment in the security field.
[0003] In related technologies, the focus curves at different object distances are usually pre-calibrated for the camera device's movement lens. When the focusing action is triggered, the focus lens group is adjusted within the preset range of the focus curve to perform a hill climbing algorithm to search for the image focal point. For conventional scenes, the above method can quickly find the focus point, but for scenes where the proportion of point light sources in the picture is high but other effective details are low, the reliability of this method will be significantly reduced, and it is easy to have a large focusing range, focus failure, and serious defocusing of the picture, which seriously affects the visual experience of the monitoring picture.
[0004] Currently, no effective solution has been proposed for the problem of how to accurately and efficiently focus in point light source scenarios in related technologies. Summary of the invention
[0005] The embodiments of the present application provide a focusing control method, device, electronic device and storage medium to at least solve the problem of how to accurately and efficiently focus in a point light source scenario in the related art.
[0006] In a first aspect, an embodiment of the present application provides a focusing control method.
[0007] In some embodiments, the focus control method includes:
[0008] Acquire an image to be focused when the focusing motor is located at a first focusing position, and determine a reference light source area in the image to be focused;
[0009] Calculating image brightness gradient information of the sub-image block in the reference light source area, and determining a brightness reference area from the reference light source area according to the image brightness gradient information;
[0010] Acquire regional brightness statistical information of the brightness reference area, and calculate a regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information;
[0011] According to the regional brightness statistical information and the regional score value, controlling the focus motor to move to a second focus position or a third focus position;
[0012] Among them, the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position; the third focus position is the position reached by the focus motor after moving once in the preset focus search direction from the first focus position.
[0013] In some embodiments, calculating the image brightness gradient information of the sub-image block in the reference light source area, and determining the brightness reference area from the reference light source area according to the image brightness gradient information comprises:
[0014] In the case where there are multiple reference light source areas, determining a reference sub-image block in each of the reference light source areas, and determining a brightness gradient value of each of the reference sub-image blocks in a reference direction;
[0015] According to the brightness gradient value, the effective brightness gradient total value corresponding to the reference light source area is determined, and the reference light source area corresponding to the largest effective brightness gradient total value is determined as the brightness reference area.
[0016] In some embodiments, the acquiring of regional brightness statistical information of the brightness reference area and calculating the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information comprises:
[0017] Acquire a first brightness gradient maximum index and first region brightness statistics of the brightness reference region at the first focus position, and calculate a first region brightness value corresponding to the brightness reference region at the first focus position according to the first brightness gradient maximum index and the first region brightness statistics;
[0018] Acquire a third brightness gradient maximum index and third region brightness statistics of the brightness reference area at the third focus position, and calculate a third region brightness value corresponding to the brightness reference area at the third focus position according to the first brightness gradient maximum index and the third region brightness statistics;
[0019] The area score value of the brightness reference area is calculated according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value.
[0020] In some embodiments, calculating the regional score value of the brightness reference area according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value comprises:
[0021] Determine a sub-image block corresponding to the first brightness gradient maximum index at the first focus position as a first sub-image block, determine a sub-image block that is expanded one grid outward along the corresponding reference direction of the first sub-image block as a first expanded sub-image block, and determine the sum of the brightness value of the first sub-image block and the brightness value of the first expanded sub-image block as the first region brightness value;
[0022] Determine the sub-image block corresponding to the maximum index of the first brightness gradient at the third focus position as a third sub-image block, determine the sub-image block that is expanded one grid outward of the third sub-image block along the corresponding reference direction as a third expanded sub-image block, and determine the sum of the brightness value of the third sub-image block and the brightness value of the third expanded sub-image block as the third region brightness value;
[0023] The area score value of the brightness reference area is calculated according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value.
[0024] In some embodiments, controlling the focus motor to move to the second focus position or the third focus position according to the regional brightness statistical information and the regional score value comprises:
[0025] Determining a target focus search direction according to the regional brightness statistical information and the regional score value;
[0026] When the target focus search direction is reverse, controlling the focus motor to move to the second focus position;
[0027] When the target focus search direction is a forward direction, the focus motor is controlled to move to the third focus position.
[0028] In some embodiments, after controlling the focus motor to move to the second focus position or the third focus position according to the regional brightness statistical information and the regional score value, the method further includes:
[0029] Obtaining image block clarity evaluation information of the image to be focused, and determining a reference fine-tuning correction position according to the regional brightness statistical information and the regional score value;
[0030] The fine adjustment interval of the image to be focused is determined according to the image block clarity evaluation information and the reference fine adjustment correction position.
[0031] In some embodiments, the focus control method further includes:
[0032] Acquire a reference brightness mean value of the brightness reference area and a global brightness variance of the image to be focused;
[0033] According to the reference brightness mean and the global brightness variance, the current position of the focus motor is determined as the updated first focus position, and the brightness reference area when the focus motor is located at the updated first focus position is determined.
[0034] In a second aspect, an embodiment of the present application provides a focus control device.
[0035] In some embodiments, the focus control device includes a reference light source area determination module, a brightness reference area determination module, an area score value calculation module, and a focus position control module:
[0036] The reference light source area determination module is used to obtain the image to be focused when the focus motor is located at the first focus position, and determine the reference light source area in the image to be focused;
[0037] The brightness reference area determination module is used to calculate the image brightness gradient information of the sub-image block in the reference light source area, and determine the brightness reference area from the reference light source area according to the image brightness gradient information;
[0038] The regional score value calculation module is used to obtain regional brightness statistical information of the brightness reference area, and calculate the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information;
[0039] The focus position control module is used to control the focus motor to move to the second focus position or the third focus position according to the regional brightness statistical information and the regional score value;
[0040] Among them, the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position; the third focus position is the position reached by the focus motor after moving once in the preset focus search direction from the first focus position.
[0041] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the focus control method as described in the first aspect above when executing the computer program.
[0042] In a fourth aspect, an embodiment of the present application provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements the focus control method as described in the first aspect above.
[0043] Compared with the related art, the focusing control method, device, electronic device and storage medium provided in the embodiments of the present application determine the reference light source area in the image to be focused by acquiring the image to be focused when the focusing motor is located at the first focusing position; then, according to the image brightness gradient information of the sub-image block in the reference light source area, the brightness reference area is screened out from the reference light source area, and according to the image brightness gradient information and the regional brightness statistical information of the brightness reference area, the regional score value of the brightness reference area is calculated; further, according to the regional brightness statistical information and the regional score value, the focusing motor is controlled to move to the second focusing position reached after the focusing motor moves once in the opposite direction of the preset focus search direction from the first focusing position, or the focusing motor is controlled to move to the third focusing position reached after the focusing motor moves once in the preset focus search direction from the first focusing position, so as to timely adjust the moving direction of the focusing motor, avoid dependence on unreliable clarity evaluation function statistics in point light source scenes, solve the problem of how to accurately and efficiently focus in point light source scenes in the related art, and improve the accuracy and efficiency of device focusing in point light source scenes.
[0044] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0046] Figure 1 is a hardware structure block diagram of a terminal according to a focusing control method according to an embodiment of the present application;
[0047] Figure 2 is a flow chart of a focusing control method according to an embodiment of the present application;
[0048] Figure 3 is a flow chart of another focusing control method according to an embodiment of the present application;
[0049] Figure 4 is a flow chart of a focusing control method according to a preferred embodiment of the present application;
[0050] Figure 5 It is a structural block diagram of a focus control device according to an embodiment of the present application. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for ordinary technicians in the field related to the contents disclosed in the present application, some changes such as design, manufacturing or production based on the technical contents disclosed in the present application are only conventional technical means, and should not be understood as insufficient contents disclosed in the present application.
[0052] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0053] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantity limitation, and may indicate the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application means greater than or equal to two. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. The terms "first", "second", "third" and the like involved in the present application are merely used to distinguish similar objects and do not represent a specific ordering of the objects.
[0054] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. Taking running on a terminal as an example, Figure 1 FIG. 1 is a hardware structure diagram of a terminal of a focusing control method according to an embodiment of the present invention. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Optionally, the terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is for illustration only and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0055] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the focusing control method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0056] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0057] This embodiment provides a focusing control method. Figure 2 is a flow chart of a focusing control method according to an embodiment of the present application. Figure 2 As shown, the process includes the following steps:
[0058] Step S201 , acquiring an image to be focused when the focus motor is located at a first focus position, and determining a reference light source area in the image to be focused.
[0059] The focus motor may be a group of motors and accessories for focusing, and the first focus position may be the initial focus position after the device receives a trigger focus command and the focus motor moves along a preset search direction, each step length is in place and the statistical value is waited for to stabilize. The image to be focused is acquired at the first focus position, and the block brightness statistical information of the sub-image block in the image to be focused is determined. The image block rule of the hardware platform may be , that is, the entire image to be focused is divided into M rows and N columns of sub-image blocks, and the block brightness statistics include image brightness. The brightness of the image block in the i-th row and j-th column is In addition, the embodiment of the present application further includes obtaining image block clarity evaluation information of the hardware platform, and the image block clarity evaluation information includes image block clarity evaluation statistics.
[0060] After acquiring the image to be focused and its sub-image blocks, The sub-image blocks are taken as a unit, and the whole image is traversed by sliding, and the K units with the largest sum of brightness are found as the light source area to be expanded. Where n is a positive integer, and , preferably, Preferably, K is 2 or 3. With the K light source regions to be expanded as the center, the sub-image blocks are expanded towards the upper left and lower right corners one by one until at least one of the expanded light source regions meets the following conditions: the ratio of the maximum brightness of the sub-image blocks contained in the light source region to the minimum brightness of the sub-image blocks is not less than the first threshold Th1, the ratio of the maximum brightness of the sub-image blocks to the average brightness of the region is not less than the second threshold Th2, the ratio of the number of sub-image blocks contained in the region to the number of sub-image blocks with brightness less than the average is not greater than the third threshold Th3, the brightness variance value of the region is not less than the fourth threshold Th4, and the ratio of the number of sub-image blocks contained in the entire image to the number of sub-image blocks contained in the reference region is greater than the fifth threshold Th5 and less than the sixth threshold Th6. (Preferably, 2<= Th1<=3, 1.5<= Th2<=1.8, 2<= Th3<=4, Th4=1000, 6<=Th5<=Th6<=32. The expanded light source area that meets the conditions is determined as the reference light source area. When the light source area to be expanded is extended to the upper limit of the range limit and still does not meet the conditions, the focus motor is moved to the next position along the preset focus direction based on the preset step size, and the above steps are continued. In addition, during the focusing process, the automatic exposure algorithm is suspended until the current focusing process is completed, so as to avoid factors such as aperture, shutter, gain, etc. affecting the image brightness change trend.
[0061] Step S202 : calculating the image brightness gradient information of the sub-image block in the reference light source area, and determining a brightness reference area from the reference light source area according to the image brightness gradient information.
[0062] After determining one or more reference light source areas, the image brightness gradient information of the sub-image blocks in each reference light source area is calculated respectively, and a brightness reference area is selected from the reference light source area according to the image brightness gradient information. Specifically, the brightness gradient information includes a brightness gradient value and a brightness gradient maximum value, wherein the specific calculation method of the brightness gradient value and the brightness gradient maximum value will be further explained below.
[0063] Step S203, obtaining regional brightness statistical information of the brightness reference area, and calculating the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information.
[0064] The regional brightness statistical information includes the brightness value of the sub-image block. According to the above-mentioned maximum brightness gradient value and the brightness value of the sub-image block, the regional score value of the brightness reference area is calculated.
[0065] Step S204, according to the regional brightness statistical information and the regional score value, control the focus motor to move to the second focus position or the third focus position; wherein the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position; the third focus position is the position reached by the focus motor after moving once in the preset focus search direction from the first focus position.
[0066] Among them, the regional brightness statistical information includes the brightness mean of the brightness reference area. According to the brightness mean and the regional score value, it is judged whether the light source is in a divergent or convergent trend. When the light source is divergent, the focusing motor is controlled to move to the second focusing position. When the light source is convergent, the focusing motor is controlled to move to the third focusing position, thereby interfering with the direction adjustment strategy of the coarse search, so as to avoid problems such as reverse early search and excessive search range caused by poor trend of image block clarity evaluation statistics in the light source area.
[0067] Through the above steps, the embodiment of the present application determines the reference light source area of the image to be focused at the initial focus position, and determines the best reference light source area as the brightness reference area based on the brightness gradient information. The brightness reference area is an area with clear light and dark. Furthermore, based on the brightness gradient information and the brightness statistical information of the brightness reference area, a regional score value is generated to characterize the divergence or convergence of the light edge. Finally, the search direction and range of the focus motor are corrected through the regional brightness statistical information and the regional score value, so as to accurately determine the focus position that the focus motor will reach next time it moves, thereby solving the problem of how the camera equipment can focus accurately and efficiently in a point light source scene, thereby improving the focusing accuracy and efficiency.
[0068] In some embodiments, step S202 includes:
[0069] Step S2021 : in the case where there are multiple reference light source areas, determining a reference sub-image block in each reference light source area, and determining a brightness gradient value of each reference sub-image block in a reference direction.
[0070] Specifically, at intervals of 45 degrees, 8 equally divided directions of each reference sub-image block in each reference light source area are obtained as reference directions, and the brightness of each reference sub-image block in each reference direction is convolved with a first-order Sobel operator (1, 0, -1) to determine the brightness gradient value of each reference sub-image block in the reference direction.
[0071] Step S2022: determining the total effective brightness gradient value corresponding to the reference light source area according to the brightness gradient value, and determining the reference light source area corresponding to the maximum total effective brightness gradient value as the brightness reference area.
[0072] Specifically, for each reference light source area, the maximum brightness gradient value in each reference direction is selected from all the brightness gradient values obtained to determine 8 brightness gradient maximum values, and the selected 8 brightness gradient maximum values are sorted from large to small, and the brightness gradient maximum values in the first P directions are recorded. Among them, P=3 in the case of 8 neighborhoods, and P=2 in the case of 4 neighborhoods. The maximum brightness gradient values in the first P directions corresponding to each reference light source area are accumulated respectively to determine the total effective brightness gradient value corresponding to each reference light source area. Further, the reference light source area corresponding to the maximum effective brightness gradient total value is determined as the brightness reference area.
[0073] Through the above steps, in the embodiment of the present application, when there are multiple reference light source areas, the brightness gradient values of the sub-image blocks of each area in 8 evenly spaced directions are calculated, and the first P reference directions with the largest brightness gradient values in each reference light source area are determined, and the brightness gradient values in the P reference directions are accumulated to determine the total effective brightness gradient value of each reference light source area, and then the brightness reference areas are screened out, providing an accurate and feasible method for determining brightness reference areas.
[0074] In some embodiments, step S203 includes:
[0075] Step S2031, obtaining a first brightness gradient maximum index and first area brightness statistics of the brightness reference area at the first focus position, and calculating a first area brightness value corresponding to the brightness reference area at the first focus position according to the first brightness gradient maximum index and the first area brightness statistics.
[0076] The first brightness gradient maximum index of the brightness reference area at the first focus position is the index corresponding to the maximum brightness gradient value in the first P directions obtained at the first focus position. The first area brightness statistical information includes the first image block brightness value of the reference sub-image block at the first focus position, and the first area brightness value corresponding to the brightness reference area at the first focus position is calculated according to the first brightness gradient maximum index and the first image block brightness value.
[0077] Step S2032, obtaining a third brightness gradient maximum index and third region brightness statistics of the brightness reference area at a third focus position, and calculating a third region brightness value corresponding to the brightness reference area at the third focus position according to the first brightness gradient maximum index and the third region brightness statistics.
[0078] The third brightness gradient maximum index of the brightness reference area at the third focus position is the index corresponding to the maximum brightness gradient value in the first P directions obtained at the third focus position. The third area brightness statistical information includes the brightness value of the third image block of the reference sub-image block at the third focus position, and the brightness value of the third area corresponding to the brightness reference area at the third focus position is calculated according to the first brightness gradient maximum index and the brightness value of the third image block.
[0079] Step S2033, calculating the area score value of the brightness reference area according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value.
[0080] Furthermore, the sub-image block index trend value is determined according to the third brightness gradient maximum index, the gradient direction brightness trend value is determined according to the first area brightness value and the third area brightness value, and the area score value of the brightness reference area is calculated according to the sub-image block index trend value and the gradient direction brightness trend value.
[0081] Through the above steps, the embodiment of the present application respectively calculates the brightness values of the initial focus position and its adjacent focus position after update, and determines the regional score value of the brightness reference area according to the change in brightness value between two adjacent focus positions and the updated maximum index of brightness gradient. The regional score value can accurately reflect the divergence or convergence of the light from the point light source, thereby interfering with the direction adjustment strategy of the coarse search according to the regional score value, so as to avoid problems such as reverse early search and excessive search range caused by poor change trend of image block clarity evaluation statistics in the light source area, thereby making subsequent focus fine-tuning position more accurate.
[0082] In some embodiments, step S2033 includes:
[0083] Step S2133: determine the sub-image block corresponding to the first brightness gradient maximum index at the first focus position as the first sub-image block, and determine the sub-image block that is expanded one grid outward from the first sub-image block along its corresponding reference direction as the first expanded sub-image block, and determine the sum of the brightness value of the first sub-image block and the brightness value of the first expanded sub-image block as the first area brightness value.
[0084] According to the first brightness gradient maximum index, the sub-image block corresponding to the first sub-image block at the first focus position is indexed and determined as the first sub-image block. At the same time, the sub-image block that is expanded one grid along the corresponding reference direction of the first sub-image block is determined as the first expanded sub-image block, wherein the corresponding reference direction is the reference direction of the maximum brightness gradient corresponding to the index at the first focus position. The sum of the brightness value of the first sub-image block and the brightness value of the first expanded sub-image block is calculated to determine the brightness value of the first region.
[0085] Step S2233: determine the sub-image block corresponding to the maximum index of the first brightness gradient at the third focus position as the third sub-image block, and determine the sub-image block that is expanded one grid outward along the corresponding reference direction of the third sub-image block as the third expanded sub-image block, and determine the sum of the brightness value of the third sub-image block and the brightness value of the third expanded sub-image block as the brightness value of the third area.
[0086] Similarly, according to the first brightness gradient maximum index, the sub-image block corresponding to the first brightness gradient maximum index at the third focus position is indexed and determined as the third sub-image block. At the same time, the sub-image block that is expanded one grid along the corresponding reference direction of the third sub-image block is determined as the third expanded sub-image block, wherein the corresponding reference direction is the reference direction of the brightness gradient maximum value corresponding to the index at the third focus position. The sum of the brightness value of the third sub-image block and the brightness value of the third expanded sub-image block is calculated to determine the brightness value of the third region.
[0087] Step S2333, calculating the regional score value of the brightness reference area according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value.
[0088] After the above steps, P third area brightness values and P first area brightness values can be obtained, the P third area brightness values are added to obtain the current area brightness value, the P first area brightness values are added to obtain the initial area brightness value, and the difference between the current area brightness value and the initial area brightness value is determined as the area brightness change value. According to the third brightness gradient maximum index and the area brightness change value, the area score value of the brightness reference area is determined.
[0089] Specifically, when the ratio of the regional brightness change value to the current regional brightness value is greater than the change threshold, it is judged that the light source is in a diffusion trend. At this time, if the count value representing the brightness change in the current gradient direction is If it is greater than 0, it is set to -1, otherwise Decrement by 1. When the ratio of the regional brightness change value to the current regional brightness value is less than the negative of the change threshold, it is judged that the light source is in a convergence trend. If it is less than 0, it is set to 1, otherwise Increment by 1. The initial value is zero, which is used to indicate the brightness change trend in the gradient direction. 0 indicates no trend in the initial state, a negative number corresponds to a divergent state of the light source, and a positive number corresponds to a convergent state of the light source. Preferably, the change threshold is 1%.
[0090] Furthermore, after each focus motor update, the index of the maximum brightness gradient in P reference directions in the brightness reference area is determined as the updated index. If the index position corresponding to the updated index is the maximum index of the first brightness gradient expanded one grid in its reference direction, and the index number of the updated index remains unchanged at the next motor position, that is, the sub-image block index number corresponding to the maximum brightness gradient value in the corresponding image after the next motor position is in place does not change, then the count value representing the change of the maximum brightness gradient block along the gradient direction is Minus 1 indicates that the light source diverges, and at the same time, the initial maximum brightness gradient block index in the corresponding reference direction is updated from the first brightness gradient maximum index to the updated index; conversely, if the index position corresponding to the updated index is the first brightness gradient maximum index indented one grid in its reference direction, and the index number of the updated index remains unchanged at the next motor position, then Adding 1 indicates that the light source converges, and at the same time, the initial maximum brightness gradient block index in the corresponding reference direction is updated from the first brightness gradient maximum index to the updated index. The initial value is 0, which is used to indicate the change of the sub-image block index corresponding to the maximum gradient value in each direction. 0 indicates the initial state, that is, the frame image when the brightness reference area is just locked. Negative numbers correspond to the number of sub-image blocks with these maximum gradient index numbers expanding along the direction of light source divergence, and positive numbers correspond to the number of sub-image blocks with these maximum gradient index numbers shrinking along the direction of light source convergence.
[0091] At each motor position, based on and Calculate the regional score value of the brightness reference area Among them, Weight1 is The weight value of Weight2 is The weight value of .
[0092] Through the above steps, the embodiment of the present application provides a specific method for calculating the brightness values of the initial focus position and its updated adjacent focus positions, and determines the regional score value of the brightness reference area based on the third brightness gradient maximum index and the regional brightness change value, which is accurate and feasible.
[0093] In some embodiments, step S204 includes:
[0094] Step S2041, determining the target focus search direction according to the regional brightness statistical information and the regional score value.
[0095] Among them, the regional brightness statistical information includes the brightness mean of the brightness reference area. When the regional score value is less than the first score threshold and the first score threshold is less than zero, and the brightness mean of the brightness reference area increases continuously for more than a times, or when the regional score value is less than the second score threshold and the second score threshold is less than the first score threshold, and the brightness mean of the current brightness reference area is not the historical minimum mean, it is determined that the target focus search direction is reverse. Preferably, when P is 2, the first score threshold is -5 and the second score threshold is -10; when P is 3, the first score threshold is -8 and the second score threshold is -15; a is 2.
[0096] When the regional score value is greater than the third score threshold and the third score threshold is greater than zero, and the current regional score value is greater than the previous regional score value or the brightness mean of the current brightness reference area is the historical minimum mean, or the brightness ratio of the brightest sub-image block to the darkest sub-image block in the brightness reference area increases c times continuously, and the brightness mean of the brightness reference area decreases b times continuously, or the brightness variance value of the current brightness reference area is greater than d times the variance value of the brightness reference area at the historical maximum image block clarity evaluation statistic, then the target focus search direction is determined to be positive. Preferably, when P is 2, the third score threshold is 5; when P is 3, the third score threshold is 8; c is 2, b is 2, and d is 10. It is worth mentioning that all the above situations in which the target focus search direction is judged to be positive are premised on the fact that the current focus motor position is not the search boundary position.
[0097] Step S2042, when the target focus search direction is reverse, control the focus motor to move to a second focus position.
[0098] When the target focus search direction is reverse, it is considered that the point light source has diverged to a certain extent, and the algorithm will actively issue a coarse adjustment reverse search request, thereby controlling the focus motor to move to the second focus position.
[0099] Step S2043, when the target focus search direction is forward, control the focus motor to move to the third focus position.
[0100] When the target focus search direction is forward, it is considered that the point light source is in a convergence trend. The algorithm will reject the search reverse request generated by the decrease in the statistical value of the image block clarity evaluation, maintain the current direction search, and control the focus motor to move to the third focus position.
[0101] Through the above steps, the embodiment of the present application determines the divergence or convergence of the light source according to the regional brightness statistical information and the regional score value, thereby adjusting the direction of the coarse focus search, and further controlling the next position reached by the focus motor, thereby improving the focusing success rate and efficiency.
[0102] In some embodiments, step S204 further includes:
[0103] Step S214, obtaining image block clarity evaluation information of the image to be focused, and determining a reference fine-tuning correction position according to the regional brightness statistical information and the regional score value.
[0104] The image block definition evaluation information includes the image block definition evaluation statistics. When the regional score value is greater than the third score threshold and the third score threshold is greater than zero, and the current regional score value is the highest score in history, or when the regional score value is greater than the third score threshold and the third score threshold is greater than zero, and the brightness mean of the current brightness reference area is the lowest value in history, the current focus motor position is determined to be the reference fine adjustment correction position.
[0105] Step S224, determining the fine adjustment interval of the image to be focused according to the image block clarity evaluation information and the reference fine adjustment correction position.
[0106] Under the premise that the coarse adjustment reaches the reverse search times threshold and the reference fine adjustment correction position is valid, when the brightness variance value of the reference fine adjustment correction position is greater than e times the variance value of the brightness reference area at the maximum image block clarity evaluation statistic, and the distance between the reference fine adjustment correction position and the position corresponding to the maximum image block clarity evaluation statistic is greater than the distance threshold, or when the brightness mean of the brightness reference area at the reference fine adjustment correction position is its historical minimum mean, and the distance between the reference fine adjustment correction position and the position corresponding to the maximum image block clarity evaluation statistic is greater than the distance threshold, the reference correction position and its left and right step lengths are used to form the fine adjustment interval of the image to be focused. Preferably, the reverse search times threshold is 2, and e is 10.
[0107] The above two situations both include the condition that the distance between the reference fine adjustment correction position and the maximum image block clarity evaluation statistical value position is greater than the distance threshold, mainly to avoid the poor night zoom follow-up focusing effect, the image block clarity evaluation statistical value trend is poor when the focus motor initial position is seriously out of focus, and there are multiple pseudo peaks, which causes the search algorithm to fall into a local extreme value. Among them, the distance threshold can be taken as the smaller value of α times the maximum coarse adjustment search step and 1 / β times the coarse adjustment search range. Preferably, α is 2 and β is 3.
[0108] In addition, when the above two conditions are not met, the maximum image block clarity evaluation statistical value and its left and right step lengths are used to form a fine adjustment interval of the image to be focused.
[0109] Through the above steps, after reaching the next suitable focusing position according to the adjusted coarse-adjustment focusing search direction, the embodiment of the present application determines the fine-adjustment interval according to the image block clarity evaluation information and the regional brightness statistical information, thereby further improving the focusing efficiency and accuracy.
[0110] This embodiment also provides a focus control method. Figure 3 is a flow chart of another focusing control method according to an embodiment of the present application. Figure 3 As shown, the process further includes the following steps based on steps S201 to S203:
[0111] Step S301, obtaining a reference brightness mean value of a brightness reference area and a global brightness variance of an image to be focused.
[0112] Following the above, the image segmentation rules of the hardware platform are still used as , that is, taking the entire image as an example, the brightness of the image block in the i-th row and j-th column is , then the average brightness of the entire image is , the brightness variance of the entire image is Thus, the reference brightness mean may be the brightness mean of the brightness reference area, and the global brightness variance may be the brightness variance value of the entire image.
[0113] Step S302, according to the reference brightness mean and the global brightness variance, the current position of the focus motor is determined as the updated first focus position, and the brightness reference area when the focus motor is located at the updated first focus position is determined.
[0114] When the reference brightness mean value decreases f times in succession, and the ratio of the current global brightness variance to the global brightness variance when determining the initial brightness reference area is greater than the variance threshold, it is determined that the image corresponding to the initial brightness reference area is seriously out of focus, and the brightness reference area needs to be updated once at the current focus motor position. Preferably, f is an integer greater than or equal to 3 and less than or equal to 5, and the variance threshold is greater than or equal to 1.05 and less than or equal to 1.1.
[0115] Through the above steps, in the case of severe initial defocus, the embodiment of the present application corrects and updates the initial brightness reference area according to the reference brightness mean and the global brightness variance, thereby further improving the focusing accuracy.
[0116] The embodiments of the present application are described and illustrated below through preferred embodiments.
[0117] Figure 4 is a flow chart of a focusing control method according to a preferred embodiment of the present application. Figure 4 As shown, the focusing control method comprises the following steps:
[0118] Step S401 , acquiring an image to be focused when the focus motor is located at a first focus position, and determining a reference light source area in the image to be focused.
[0119] Step S402: in the case where there are multiple reference light source areas, determine a reference sub-image block in each reference light source area, and determine a brightness gradient value of each reference sub-image block in a reference direction.
[0120] Step S403 : determining the total effective brightness gradient value corresponding to the reference light source area according to the brightness gradient value, and determining the reference light source area corresponding to the maximum total effective brightness gradient value as the brightness reference area.
[0121] Step S404, obtaining regional brightness statistical information of the brightness reference area, and calculating the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information.
[0122] Step S405: determining the target focus search direction according to the regional brightness statistical information and the regional score value.
[0123] Step S406, when the target focus search direction is in the reverse direction, control the focus motor to move to a second focus position; wherein the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position.
[0124] Step S407, when the target focus search direction is forward, control the focus motor to move to a third focus position; wherein the third focus position is the position reached by the focus motor after moving once along the preset focus search direction from the first focus position.
[0125] Step S408, obtaining image block clarity evaluation information of the image to be focused, and determining a reference fine-tuning correction position according to the regional brightness statistical information and the regional score value.
[0126] Step S409, determining the fine adjustment interval of the image to be focused according to the image block clarity evaluation information and the reference fine adjustment correction position.
[0127] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0128] This embodiment also provides a focusing control device, which is used to implement the above embodiments and preferred implementations, and will not be repeated here. As used below, the terms "module", "unit", "subunit", etc. can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0129] Figure 5 is a structural block diagram of a focus control device according to an embodiment of the present application, such as Figure 5 As shown, the device includes a reference light source area determination module 10, a brightness reference area determination module 20, an area score value calculation module 30, and a focus position control module 40:
[0130] A reference light source region determining module 10 is used to obtain an image to be focused when the focusing motor is located at a first focusing position, and to determine a reference light source region in the image to be focused;
[0131] A brightness reference region determination module 20 is used to calculate the image brightness gradient information of the sub-image block in the reference light source region, and determine the brightness reference region from the reference light source region according to the image brightness gradient information;
[0132] The regional score value calculation module 30 is used to obtain the regional brightness statistical information of the brightness reference area, and calculate the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information;
[0133] A focus position control module 40, configured to control the focus motor to move to a second focus position or a third focus position according to the regional brightness statistical information and the regional score value;
[0134] Among them, the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position; the third focus position is the position reached by the focus motor after moving once in the preset focus search direction from the first focus position.
[0135] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0136] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0137] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0138] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0139] Acquire an image to be focused when the focusing motor is located at a first focusing position, and determine a reference light source area in the image to be focused;
[0140] Calculating image brightness gradient information of the sub-image block in the reference light source area, and determining a brightness reference area from the reference light source area according to the image brightness gradient information;
[0141] Obtaining regional brightness statistical information of the brightness reference area, and calculating the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information;
[0142] Controlling the focus motor to move to a second focus position or a third focus position according to the regional brightness statistical information and the regional score value;
[0143] Among them, the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position; the third focus position is the position reached by the focus motor after moving once in the preset focus search direction from the first focus position.
[0144] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0145] In addition, in combination with the focus control method in the above embodiment, the embodiment of the present application can provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by a processor, any one of the focus control methods in the above embodiment is implemented.
[0146] Those skilled in the art should understand that the technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0147] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0148] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A focusing control method, characterized in that: The following steps are involved: Acquire an image to be focused when the focusing motor is located at a first focusing position, and determine a reference light source area in the image to be focused; In the case where there are multiple reference light source areas, determining a reference sub-image block in each of the reference light source areas, and determining a brightness gradient value of each of the reference sub-image blocks in a reference direction; Determine the effective total brightness gradient value corresponding to the reference light source area according to the brightness gradient value, and determine the reference light source area corresponding to the largest effective total brightness gradient value as the brightness reference area; Acquire regional brightness statistical information of the brightness reference area, and calculate a regional score value of the brightness reference area according to the brightness gradient information and the regional brightness statistical information; According to the regional brightness statistical information and the regional score value, controlling the focus motor to move to a second focus position or a third focus position; Among them, the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position; the third focus position is the position reached by the focus motor after moving once in the preset focus search direction from the first focus position.
2. The focusing control method according to claim 1, characterized in that: The acquiring of the regional brightness statistical information of the brightness reference area and calculating the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information comprises: Acquire a first brightness gradient maximum index and first region brightness statistics of the brightness reference region at the first focus position, and calculate a first region brightness value corresponding to the brightness reference region at the first focus position according to the first brightness gradient maximum index and the first region brightness statistics; Acquire a third brightness gradient maximum index and third region brightness statistics of the brightness reference area at the third focus position, and calculate a third region brightness value corresponding to the brightness reference area at the third focus position according to the first brightness gradient maximum index and the third region brightness statistics; The area score value of the brightness reference area is calculated according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value.
3. The focusing control method according to claim 2, characterized in that: Calculating the area score value of the brightness reference area according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value comprises: Determine a sub-image block corresponding to the first brightness gradient maximum index at the first focus position as a first sub-image block, determine a sub-image block that is expanded one grid outward along the corresponding reference direction of the first sub-image block as a first expanded sub-image block, and determine the sum of the brightness value of the first sub-image block and the brightness value of the first expanded sub-image block as the first region brightness value; Determine the sub-image block corresponding to the maximum index of the first brightness gradient at the third focus position as a third sub-image block, determine the sub-image block that is expanded one grid outward of the third sub-image block along the corresponding reference direction as a third expanded sub-image block, and determine the sum of the brightness value of the third sub-image block and the brightness value of the third expanded sub-image block as the third region brightness value; The area score value of the brightness reference area is calculated according to the third brightness gradient maximum index, the first area brightness value and the third area brightness value.
4. The focusing control method according to any one of claims 1 to 3, characterized in that: According to the regional brightness statistical information and the regional score value, controlling the focus motor to move to the second focus position or the third focus position comprises: Determining a target focus search direction according to the regional brightness statistical information and the regional score value; When the target focus search direction is reverse, controlling the focus motor to move to the second focus position; When the target focus search direction is a forward direction, the focus motor is controlled to move to the third focus position.
5. The focusing control method according to claim 4, characterized in that: After controlling the focus motor to move to the second focus position or the third focus position according to the regional brightness statistical information and the regional score value, the method further includes: Obtaining image block clarity evaluation information of the image to be focused, and determining a reference fine-tuning correction position according to the regional brightness statistical information and the regional score value; The fine adjustment interval of the image to be focused is determined according to the image block clarity evaluation information and the reference fine adjustment correction position.
6. The focusing control method according to claim 5, characterized in that: The method further comprises: Acquire a reference brightness mean value of the brightness reference area and a global brightness variance of the image to be focused; According to the reference brightness mean and the global brightness variance, the current position of the focus motor is determined as the updated first focus position, and the brightness reference area when the focus motor is located at the updated first focus position is determined.
7. A focus control device, characterized in that: It includes a reference light source area determination module, a brightness reference area determination module, an area score value calculation module, and a focus position control module: The reference light source area determination module is used to obtain the image to be focused when the focus motor is located at the first focus position, and determine the reference light source area in the image to be focused; The brightness reference area determination module is used to calculate the image brightness gradient information of the sub-image block in the reference light source area, and determine the brightness reference area from the reference light source area according to the image brightness gradient information; Wherein, the brightness reference area determination module includes a sub-image block processing module and a brightness reference area screening module; The sub-image block processing module is used to determine a reference sub-image block in each reference light source area when there are multiple reference light source areas, and determine a brightness gradient value of each reference sub-image block in a reference direction; The brightness reference area screening module is used to determine the effective brightness gradient total value corresponding to the reference light source area according to the brightness gradient value, and determine the reference light source area corresponding to the largest effective brightness gradient total value as the brightness reference area; The regional score value calculation module is used to obtain regional brightness statistical information of the brightness reference area, and calculate the regional score value of the brightness reference area according to the image brightness gradient information and the regional brightness statistical information; The focus position control module is used to control the focus motor to move to the second focus position or the third focus position according to the regional brightness statistical information and the regional score value; Among them, the second focus position is the position reached by the focus motor after moving once in the opposite direction of the preset focus search direction from the first focus position; the third focus position is the position reached by the focus motor after moving once in the preset focus search direction from the first focus position.
8. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the focus control method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the focus control method according to any one of claims 1 to 6 when executed.
Citation Information
Patent Citations
Light source positioning method and device
CN103810695A
Focusing processing method and device
CN112911153A
