(19)
(11)EP 3 889 661 A1

(12)EUROPEAN PATENT APPLICATION

(43)Date of publication:
06.10.2021 Bulletin 2021/40

(21)Application number: 20179436.9

(22)Date of filing:  11.06.2020
(51)International Patent Classification (IPC): 
G02B 7/36(2021.01)
H04N 5/232(2006.01)
G03B 13/36(2021.01)
(52)Cooperative Patent Classification (CPC):
G03B 13/36; G02B 7/365; H04N 5/232123
(84)Designated Contracting States:
AL AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IS IT LI LT LU LV MC MK MT NL NO PL PT RO RS SE SI SK SM TR
Designated Extension States:
BA ME
Designated Validation States:
KH MA MD TN

(30)Priority: 31.03.2020 CN 202010243515

(71)Applicant: Infiray Technologies Co., Ltd.
Hefei, Anhui 230001 (CN)

(72)Inventors:
  • LIU, Jiankang
    Hefei, Anhui 230001 (CN)
  • LV, Xianmin
    Hefei, Anhui 230001 (CN)

(74)Representative: Biallo, Dario et al
Barzanò & Zanardo Milano S.p.A. Via Borgonuovo, 10
20121 Milano
20121 Milano (IT)

  


(54)FOCUSING METHOD AND APPARATUS, ELECTRONIC DEVICE AND STORAGE MEDIUM


(57) A focusing method, a focusing apparatus, an electronic device and a computer-readable storage medium are provided. The focusing method includes: determining a focus window based on a current image collected by a lens, performing a coarse focusing operation on the lens by a first step, determining a first sharpness evaluation value of the focus window, and setting a first potential value corresponding to the maximum first sharpness evaluation value as a coarse focusing preferred potential value; performing a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value; and performing a micro focusing operation on the lens to make a sharpness evaluation value of the focus window after the micro focusing operation greater than or equal to the target sharpness evaluation value.




Description

TECHNICAL FIELD



[0001] The present disclosure relates to the technical field of camera photography, and in particular to a focusing method, a focusing apparatus, an electronic device and a computer-readable storage medium.

BACKGROUND



[0002] With the lower and lower price of infrared modules and the development of uncooled infrared imaging technology, more infrared products are applied in the fields of industrial temperature measurement, automobile night driving assistance, security monitoring, firefighting, consumer electronics, and the like. In the infrared products, the effects of temperature measurement and security monitoring are directly affected by clarity and contrast of an infrared image. In an infrared thermal imager product based on the infrared module, an urgent problem to be solved is how to make an image of a target collected by a lens to have best quality, that is, how to enable an optical focus position for the lens.

[0003] At present, most of the focusing methods for infrared images are similar to the focusing method for visible light images, that is, an automatic focusing method based on image quality. The automatic focusing method relies on sharpness evaluations of an imaging target at different focus positions, by which a focus position is quickly and accurately found by using a certain search strategy and the lens is moved to the focus position. Thus, the key to the focusing effect is an accurate sharpness evaluation function and the search strategy. However, unlike a visible light image, the infrared image bears disadvantages such as poor uniformity, rough imaging details, and low signal-to-noise ratio, and the evaluation value of the infrared image often fails to meet the requirements of unimodality and unbiasedness, resulting in failure of the sharpness evaluation function and the search strategy in a focusing process and thereby frequent focusing failures.

[0004] Therefore, a technical problem for those skilled in the art is how to avoid the failure of focusing due to the infrared image having large noise and multiple local extreme points.

SUMMARY



[0005] An object of the present disclosure is to provide a focusing method, a focusing apparatus, an electronic device and a computer-readable storage medium, to avoid the focusing failure due to the infrared image having large noise and multiple local extreme points.

[0006] To achieve the object above, a focusing method is provided according to the present disclosure. The method includes:

determining a focus window based on a current image collected by a lens;

performing a coarse focusing operation on the lens by a first step from a starting point to an ending point of a focusing range of the lens, determining a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value, and setting a first potential value corresponding to a maximum value among all first sharpness evaluation values as a coarse focusing preferred potential value, where the first potential value is a modulus value corresponding to a difference between voltages across a potentiometer before and after the lens moves by the first step;

performing a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value; and

determining a current position of the lens, and performing a micro focusing operation on the lens to make a sharpness evaluation value of the focus window after the micro focusing operation is performed greater than or equal to the target sharpness evaluation value.



[0007] In an embodiment, the determining a focus window based on a current image collected by a lens includes:

collecting the current image by the lens, and dividing the current image into blocks; and

calculating a gradient of each of the blocks, and determining a block having a gradient greater than a preset value as the focus window.



[0008] In an embodiment, the determining a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value includes:

performing median filtering on the focus window to obtain an intermediate image when the lens is located at the position corresponding to the first potential value; and

constructing an edge gradient map corresponding to the focus window based on the intermediate image, and determining a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window.



[0009] In an embodiment, the constructing an edge gradient map corresponding to the focus window based on the intermediate image and determining a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window includes:

calculating a horizontal gradient and a vertical gradient of the intermediate image, and constructing the edge gradient map corresponding to the focus window based on the horizontal gradient and the vertical gradient; and

calculating an image gradient variance of the edge gradient map, and determining the image gradient variance as the first sharpness evaluation value of the focus window.



[0010] In an embodiment, the focusing method further includes:
performing motion detection on the current image, and if a moving target is detected in the current image, re-performing the coarse focusing operation on the lens by the first step from the starting point to the ending point of the focusing range of the lens.

[0011] In an embodiment, the performing a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value includes:

determining a maximum number of direction reversing operations and a target direction, and performing the fine focusing operation on the lens in the target direction by a second step, where a potential value corresponding to a starting position of the lens when the fine focusing operation is performed for a first time is the coarse focusing preferred potential value, and the second step is smaller than the first step;

determining a second sharpness evaluation value of the focus window when the lens is at a position corresponding to a second potential value during the fine focusing operation, and setting a maximum value among all second sharpness evaluation values as a candidate target sharpness evaluation value, where the second potential value is a modulus value corresponding to a difference between voltages across the potentiometer before and after the lens moves by the second step;

if a predetermined condition is met, determining whether a current number of direction reversing operations is greater than the maximum number of direction reversing operations, where the predetermined condition is that n consecutive second sharpness evaluation values are in descending order;

if the current number of direction reversing operations is greater than the maximum number of direction reversing operations, determining a maximum value among all candidate target sharpness evaluation values as the target sharpness evaluation value, and determining the fine focusing preferred potential value corresponding to the target sharpness evaluation value; and

if the current number of direction reversing operations is less than or equal to the maximum number of direction reversing operations, determining an opposite direction of the target direction as the target direction, and re-performing the fine focusing operation on the lens in the target direction by the second step.



[0012] In an embodiment, after determining the opposite direction of the target direction as the target direction, the focusing method further includes:
updating the second step, where the second step is negatively correlated with the current number of direction reversing operations.

[0013] To achieve the above object, a focusing apparatus is provided according to the present disclosure. The apparatus includes: a determination module, a coarse focusing module, a fine focusing module, and a micro focusing module.

[0014] The determination module is configured to determine a focus window based on a current image collected by a lens.

[0015] The coarse focusing module is configured to perform a coarse focusing operation on the lens by a first step from a starting point to an ending point of a focusing range of the lens, determine a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value, and set a first potential value corresponding to a maximum value among all first sharpness evaluation values as a coarse focusing preferred potential value, where the first potential value is a modulus value corresponding to a difference between voltages across a potentiometer before and after the lens moves by the first step.

[0016] The fine focusing module is configured to perform a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value.

[0017] The micro focusing module is configured to determine a current position of the lens, and perform a micro focusing operation on the lens to make a sharpness evaluation value of the focus window after the micro focusing operation is performed greater than or equal to the target sharpness evaluation value.

[0018] To achieve the above object, an electronic device is provided according to the present disclosure. The electronic device includes: a memory and a processor. The memory is configured to store a computer program, and the processor is configured to perform the focusing method as described above when executing the computer program.

[0019] To achieve the above object, a computer-readable storage medium storing a computer program is provided according to the present disclosure. The computer program, when executed by a processor, causes the processor to perform the focusing method as described above.

[0020] Based on the above solutions, a focusing method according to the present disclosure includes: determining a focus window based on a current image collected by a lens; performing a coarse focusing operation on the lens by a first step from a starting point to an ending point of a focusing range of the lens, determining a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value, and setting a first potential value corresponding to a maximum value among all the first sharpness evaluation values as a coarse focusing preferred potential value, where the first potential value is a modulus value corresponding to a difference between voltages across a potentiometer before and after the lens moves by the first step; performing a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value; and determining a current position of the lens, and performing a micro focusing operation on the lens to make a sharpness evaluation value of the focus window after the micro focusing operation is performed greater than or equal to the target sharpness evaluation value.

[0021] In the focusing method according to the present disclosure, first, a coarse focusing operation is performed on the lens covering the entire focusing range of the lens to determine a coarse focusing preferred potential value, that is, to roughly determine a focus position and eliminate the influence of noise in the infrared image. Second, a fine focusing operation based on a hill-climbing algorithm is performed from a starting position corresponding to the coarse focusing preferred potential value to determine a lowest target sharpness evaluation value of the focus position. Finally, a micro focusing operation is performed, that is, the lens is adjusted to the focus position based on the target sharpness evaluation value. By performing the fine focusing operation and the micro focusing operation, the influence of multiple local extreme values in the infrared image can be eliminated. Therefore, with the focusing method according to the present disclosure, a better focusing effect can be achieved for the infrared image having large noise and multiple local extreme points, thereby achieving a higher focusing robustness. In addition, a focusing apparatus, an electronic device and a computer-readable storage medium are further provided according to the present disclosure, with which the above technical effects can also be achieved.

[0022] It should be understood that the above general description and the following detailed description are only exemplary, which do not limit the present disclosure.

BRIEF DESCRIPTION OF THE DRAWINGS



[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or in conventional technology, the drawings used in the description of the embodiments or the conventional technology are briefly described below. Apparently, the drawings in the following description show only some embodiments of the present disclosure, and those skilled in the art can obtain other drawings according to the provided drawings without any creative work. The drawings are used to provide a further understanding of the present disclosure, and constitute a part of the specification. The drawings are used to explain the present disclosure together with the following specific embodiments, and are not intended to limit the present disclosure. In the drawings:

Figure 1 is a flow chart of a focusing method according to an exemplary embodiment;

Figure 2 is a flow chart of an algorithm for determining a potential value according to an exemplary embodiment;

Figure 3 is a detailed flow chart of step S103 shown in Figure 1;

Figure 4 is a flow chart of a fine focusing operation in a case of n=3 according to an exemplary embodiment;

Figure 5 is a schematic structural diagram of a focusing apparatus according to an exemplary embodiment; and

Figure 6 is a schematic structural diagram of an electronic device according to an exemplary embodiment.


DETAILED DESCRIPTION OF THE EMBODIMENTS



[0024] The technical solutions in the embodiments of the present disclosure are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present application. Apparently, the embodiments described here are only a part rather than all of the embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative efforts fall into the scope of the present disclosure.

[0025] According to the embodiments of the present disclosure, a focusing method is provided to avoid the failure of focusing due to the infrared image having large noise and multiple local extreme points.

[0026] Reference is made to Figure 1, which shows a flow chart of a focusing method according to an exemplary embodiment. As shown in Figure 1, the method includes the following steps S101 to S104.

[0027] In step S101, a focus window is determined based on a current image collected by a lens.

[0028] The purpose of the embodiment is to perform a focusing process on the lens, that is, to determine a focus position of the lens. The lens may be an infrared lens, and the collected current image may be an infrared image. In a specific implementation, in order to obtain a target having many edges in a field of view to facilitate evaluating by an image quality evaluation function and to improve focusing accuracy, a window selection process may be performed on the current image collected by the lens during the focusing process to select an area of interest, that is, to determine the focus window.

[0029] It can be understood that in this step, the entire current image may be selected as the focus window, but this will cause the amount of calculation performed by the image quality evaluation function to increase exponentially and thereby affect the timeliness of the focusing process. Generally, the lens directly faces a position of a target and the target of interest is in a central area, that is, the window selection process may be performed using a central area method. If the target is not located in the central area, the user can manually select a focus area. Practically, a self-adaptive window focusing method may be adopted in this step, in which the current image is divided into blocks, a gradient of each of the blocks is calculated and ranked, and the first few blocks having the largest gradients are selected as the focus window, thereby achieving self-adaptive window focusing. That is, this step may include: collecting the current image by the lens, and dividing the current image into blocks; and calculating a gradient of each of the blocks, and determining a block having a gradient greater than a preset value as the focus window. The preset value may be flexibly set based on the actual situation of the current image, and is not specifically limited herein.

[0030] In step S102, a coarse focusing operation is performed on the lens by a first step from a starting point to an ending point of a focusing range of the lens, a first sharpness evaluation value of the focus window, when the lens is at a position corresponding to a first potential value, is determined, and a first potential value corresponding to a maximum value among all first sharpness evaluation values is set as a coarse focusing preferred potential value. The first potential value is a modulus value corresponding to a difference between voltages across a potentiometer before and after the lens moves by the first step.

[0031] It should be noted that in an infrared focusing method in the related technology, if there is no object having a large temperature difference in the field of view, an infrared target has no obvious edges or the image has large noise, the sharpness evaluation value obtained by the image quality evaluation function may include multiple local extreme points, and thus the maximum sharpness evaluation value found by simply using a search strategy may be limited to the local extreme points. In view of this, in this step, the lens is driven by a motor to move through the entire focusing range of the lens by a large step (that is, the first step), that is, the coarse focusing operation is performed. The size of the first step may be [0, 1/2] of the entire focusing range of the lens, for example, the size of the first step may be set to 1/4 of the entire focus range of the lens.

[0032] As shown in Figure 2, when driving the lens to move, the motor continuously changes a resistance of a potentiometer, leading to changes in division of the voltage across the potentiometer. In the embodiment, a total voltage inputted across the potentiometer may be 9V or 3.3V. The potential value changes during the lens moves within a range allowed by a limit switch (for limiting a range within which the lens moves), and the total voltage across the potentiometer may be so determined as to enable a larger change of potential. By performing an analog-to-digital conversion, a voltage value can be converted to a specific value, that is, a potential value, and Arm may read the specific potential value using an I2C protocol.

[0033] During the coarse focusing process, a first sharpness evaluation value of the focus window when the lens is at a position corresponding to each of first potential values is recorded, the maximum value RFmax among the first sharpness evaluation values and the first potential value RPmax corresponding to the maximum value RFmax are obtained. Then, in subsequent focusing processes, the focus position is looked for around a position corresponding to the maximum potential value RPmax. Since the position corresponding to RPmax is close to the actual focus position, it can be avoided that the maximum focus position is limited to positions corresponding to local maximum values, the evaluation value has a better monotonicity around the position corresponding to RPmax, and the maximum evaluation value is easier to be found.

[0034] In the embodiment, the image quality evaluation function is not limited, that is, the specific implementation of determining the first sharpness evaluation value is not limited. In an embodiment, the determining a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value includes: performing median filtering on the focus window to obtain an intermediate image when the lens is located at the position corresponding to the first potential value; and constructing an edge gradient map corresponding to the focus window based on the intermediate image, and determining a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window. In specific implementation, due to process and other reasons, the effect of the focusing process may be affected by the noise included in the infrared image, so it is required to perform filtering to remove the noise before calculating the evaluation function. Median filtering is performed instead of Gaussian filtering, so that detailed information can be retained after filtering. By extracting the edges of the image to construct the edge gradient map, part of the noise can be removed and details of the image are clearer. The statistical characteristics of the edge gradient map are calculated as the first sharpness evaluation value of the focus window.

[0035] In an embodiment, the constructing an edge gradient map corresponding to the focus window based on the intermediate image and determining a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window includes: calculating a horizontal gradient and a vertical gradient of the intermediate image, and constructing the edge gradient map corresponding to the focus window based on the horizontal gradient and the vertical gradient; and calculating an image gradient variance of the edge gradient map, and determining the image gradient variance as the first sharpness evaluation value of the focus window. In a specific implementation, the classic Sobel operator may be used in extracting the edges of the image. For example, the edges can be extracted by convolving two 3*3 filters with pixels of the image in the image space.

[0036] The two filters are

and

which can be used to detect gradients in a direction of 0 degrees (horizontal direction) and a direction of 90 degrees (vertical direction), respectively.

[0037] The gradient in the horizontal direction is

and the gradient in the vertical direction is

where * represents a convolution operation, f(x, y) represents a value of a pixel. A Sobel edge value is expressed as:

which can be substituted by the following simple equation to reduce the amount of calculation:



[0038] In a specific implementation, the gradient variance of the edge gradient map may be calculated. A variance of an image characterizes a degree of dispersion of the image. Fewer details included in the image and a smaller degree of dispersion of the image indicate a smaller variance, and more details included in the image and a greater degree of dispersion of the image indicate a larger variance. While calculating the gradient variance of the image to reflect the details of the image, values of points around the peak value point may be magnified to increase a slope of the evaluation value of the image, facilitating finding the peak value. The equation for calculating the gradient variance of the image is as follows:

where G(x, y) represents the calculated edge gradient map, µ represents a mean gradient value of the edge gradient map, and M and N respectively represent a height and a width of the edge gradient map.

[0039] In step S103, a fine focusing operation based on a hill-climbing algorithm is performed on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value.

[0040] The purpose of this step is to search for the maximum sharpness evaluation value, that is, the target sharpness evaluation value DFmax, by using the hill-climbing algorithm around the maximum potential value RPmax. The maximum potential value RPmax obtained in the coarse focusing process may be regarded as a value corresponding to a position near the best focus position of the lens. Since the lens is moved by a large step in the coarse focusing process, and the position corresponding to the maximum value RPmax is still a certain distance away from the actual focus position, it is required to perform a fine focusing process around the position corresponding to the maximum value RPmax.

[0041] The hill-climbing search algorithm is the search strategy used in the fine focusing process. Unlike the Fibonacci search algorithm and the golden section search algorithm, in which the position of the lens is adjusted and the moving direction of the lens is changed frequently and extensively, by the hill-climbing search algorithm, continuous searching can be performed, and unnecessary travel is avoided, thereby saving time and reducing cumulative position errors. The hill-climbing search algorithm works by the following principle: initially, the lens is driven by a motor to move in a certain direction, and if the sharpness evaluation value increases which indicates that the focusing direction is correct, the lens is moved again; if the sharpness evaluation value decreases which indicates that the maximum sharpness evaluation value has been passed and the lens has passed the focus position corresponding to the maximum sharpness evaluation value, the lens should be moved in an opposite direction. In order to make the focusing more accurate, the size of the step may be reduced during focusing operations in the opposite direction to finely search for the maximum value.

[0042] It should be noted that in order to improve the anti-noise performance of the hill-climbing search algorithm, a multi-frame comparison algorithm (such as a three-frame comparison algorithm) may be adopted. According to the multi-frame comparison algorithm, if the sharpness evaluation value continuously decreases or increases for multiple consecutive frames (such as three frames), the motor moves in a reverse direction or a forward direction; otherwise, the motor moves in an original direction, which are described in detail in subsequent embodiments.

[0043] In step S104, a current position of the lens is determined, and a micro focusing operation is performed on the lens to make a sharpness evaluation value of the focus window after the micro focusing operation is performed greater than or equal to the target sharpness evaluation value.

[0044] In this step, the best focus position is obtained by performing the micro focusing operation around the position corresponding to the maximum potential value DPmax based on DFmax which is obtained in the fine focusing process. In this process, the motor drives the lens to move by a very small step. During the moving of the lens, if the sharpness evaluation value of an image collected in real time is greater than or equal to DFmax, it can be determined that the lens is located in the best focus position, and the motor stops rotating; if the sharpness evaluation value of an image collected in real time is less than DFmax, a hill-climbing search is performed, which is similar to the hill-climbing search algorithm in the fine focusing operation, and if the sharpness evaluation value drops continuously, it can be determined that the lens has passed the best focus point, in which case the motor stops rotating and the focusing process is completed.

[0045] In the focusing method according to the present disclosure, first, a coarse focusing operation is performed on the lens covering the entire focusing range to determine a coarse focusing preferred potential value, that is, to roughly determine a focus position, thereby eliminating the influence of noise in the infrared image. Second, a fine focusing operation is performed based on a hill-climbing algorithm from a starting position corresponding to the coarse focusing preferred potential value to determine a lowest target sharpness evaluation value of the focus position. Finally, a micro focusing operation is performed, that is, the lens is adjusted to the focus position based on the target sharpness evaluation value. By performing the fine focusing operation and the micro focusing operation, the influence of multiple local extreme values in the infrared image can be eliminated. Therefore, with the focusing method according to the present disclosure, a better focusing effect can be achieved for the infrared image having large noise and multiple local extreme points, thereby achieving a higher focusing robustness.

[0046] The fine focusing operation is described in detail below. As shown in Figure 3, step S103 in the above embodiment may include the following steps S31 to S36.

[0047] In step S31, a maximum number of direction reversing operations and a target direction are determined.

[0048] In the embodiment, the multi-frame comparison algorithm is adopted. According to the multi-frame comparison algorithm, if the sharpness evaluation value continuously decreases or increases for n consecutive frames, the motor moves the lens in a reverse direction or a forward direction; otherwise, the motor moves the lens in the original direction, where n is an integer greater than 1. In order to further improve the robustness, the hill-climbing algorithm is improved based on potential information in the embodiment. In the fine focusing operation, a second sharpness evaluation value of an i-th image of the focus window is f(i), and a corresponding potential value is p(i); a maximum number of direction reversing operations by the motor is CountMax, a maximum value obtained by performing a k-th reverse focusing operation is Fmax(k) (k<=CountMax), and in this case the potential value is Pmax(k).

[0049] In step S32, the fine focusing operation is performed on the lens in the target direction by a second step. A potential value corresponding to a starting position of the lens when the fine focusing operation is performed for a first time is the coarse focusing preferred potential value, and the second step is smaller than the first step.

[0050] In step S33, a second sharpness evaluation value of the focus window when the lens is at a position corresponding to a second potential value is determined during the fine focusing operation, and a maximum value among all second sharpness evaluation values is set as a candidate target sharpness evaluation value. The second potential value is a modulus value corresponding to a difference between voltages across the potentiometer before and after the lens moves by the second step.

[0051] In step S34, if a predetermined condition is met, it is determined whether a current number of direction reversing operations is greater than the maximum number of direction reversing operations. If the current number is greater than the maximum number, the fine focusing process proceeds to step S35; and if the current number is less than or equal to the maximum number, the fine focusing process proceeds to step S36. The predetermined condition is that n consecutive second sharpness evaluation values are in descending order.

[0052] In step S35, a maximum value among all candidate target sharpness evaluation values is determined as the target sharpness evaluation value, and the fine focusing preferred potential value corresponding to the target sharpness evaluation value is determined.

[0053] In step S36, an opposite direction of the target direction is determined as the target direction, after which the focusing method returns to step S32.

[0054] In a specific implementation, a reverse focusing count k is initialed to 1 in performing the first fine focusing operation, and a potential value corresponding to the starting position of the lens is the coarse focusing preferred potential value. A maximum value among the sharpness evaluation values of images collected at positions corresponding to first n second potential values is obtained as the maximum evaluation value Fmax, and the potential value Pmax corresponding to the maximum evaluation value Fmax, that is, the candidate fine focusing preferred potential value, is recorded. If Fmax is continuously less than sharpness evaluation values of images in next i frames (i<=n), f(i) is assigned to Fmax, Pmax is updated, and the motor continues to move forward. If Fmax is continuously greater than the sharpness evaluation values of images in the next i frames (i<=n), it can be determined that the motor has passed the focus position, the motor rotates in the reverse direction, the reverse focusing count k is increased by 1, Fmax is assigned to Fmax(k), and Pmax is assigned to Pmax (k). The above process is repeated until k is greater than or equal to CountMax, then values of Fmax(k) are ranked so as to obtain a maximum value of Fmax(k), the maximum value of Fmax(k) is assigned to Fmax, and a current potential value Pmax(i) is assigned to Pmax. The above process in case of n=3 is shown in Figure 4.

[0055] It can be understood that in order to make the focus position obtained in the fine focusing operation more accurate, the size of the step may be reduced each time the fine focusing operation is performed in the reverse direction, and the motor repeatedly searches around the focus position. That is, after determining the opposite direction of the target direction as the target direction, the focusing method further includes updating the second step. The second step is negatively correlated with the current number of direction reversing operations.

[0056] In the embodiment, with comprehensive consideration into the focusing effect and the time that the focusing takes, the maximum number CountMax of direction reversing operations can be set to 3. After performing three fine focusing operations, a maximum value among the obtained three candidate target sharpness evaluation values is obtained and determined as the target sharpness evaluation value and is assigned to Dfmax, and DPmax is updated.

[0057] In an embodiment based on the above embodiments, the focusing method according to the present disclosure further includes: performing motion detection on the current image, and if a moving target is detected in the current image, re-performing the coarse focusing operation on the lens by the first step from the starting point to the ending point of the focusing range of the lens.

[0058] It should be understood that during the focusing process, if a moving target enters the field of view, the sharpness evaluation value of the focus window changes greatly, affecting the accuracy of the result of the focusing process. In view of this, motion detection may be performed during the focusing process. If a moving target is detected, it indicates that the focusing environment has changed. In such a case, the focusing operations should be re-performed. The above focusing process is re-performed in the new scene, that is, the coarse focusing operation is performed again.

[0059] A specific algorithm for the motion detection is not limited, for example, a frame difference algorithm may be adopted, which is not described herein. A maximum re-focusing number may be set in the focusing process to avoid the problem of constant focusing due to continuous changed scenes.

[0060] It should be noted that in an embodiment, the motion detection may be performed only on a selected focus window to reduce false triggering of the re-focusing process by a moving target which is not in the focus area. As a changing focal length may cause a change in the size of a focusing object, which may be falsely detected as a moving target by the frame difference algorithm though there is no moving object in the focus area, a strict threshold for determining a moving target may be set. For example, a threshold of a ratio of an area of the moving target to an area of the entire focus window may be set to a high value in a regional focusing process and a central regional focusing process, and a threshold of the number of moving windows may be set to a large value in a self-adaptive window focusing process.

[0061] A focusing apparatus according to the embodiments of the present disclosure is described below. Cross reference can be made to the focusing apparatus described below and the focusing method described above.

[0062] Reference is made to Figure 5, which shows a schematic structural diagram of a focusing apparatus according to an exemplary embodiment. As shown in Figure 5, the apparatus includes a determination module 501, a coarse focusing module 502, a fine focusing module 503, and a micro focusing module 504.

[0063] The determination module 501 is configured to determine a focus window based on a current image collected by a lens.

[0064] The coarse focusing module 502 is configured to perform a coarse focusing operation on the lens by a first step from a starting point to an ending point of a focusing range of the lens, determine a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value, and set a first potential value corresponding to a maximum value among all first sharpness evaluation values as a coarse focusing preferred potential value, where the first potential value is a modulus value corresponding to a difference between voltages across a potentiometer before and after the lens moves by the first step.

[0065] The fine focusing module 503 is configured to perform a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value.

[0066] The micro focusing module 504 is configured to determine a current position of the lens, and perform a micro focusing operation on the lens to make a sharpness evaluation value of the focus window after the micro focusing process is performed greater than or equal to the target sharpness evaluation value.

[0067] In the focusing apparatus according to the present disclosure, first, a coarse focusing operation is performed on the lens covering the entire focusing range of the lens to determine a coarse focusing preferred potential value, that is, to roughly determine a focus position, to eliminate the influence of noise in the infrared image. Second, a fine focusing operation is performed based on a hill-climbing algorithm from a starting position corresponding to the coarse focusing preferred potential value to determine a lowest target sharpness evaluation value of the focus position. Finally, a micro focusing operation is performed, that is, the lens is adjusted to the focus position based on the target sharpness evaluation value. By performing the fine focusing operation and the micro focusing operation, the influence of multiple local extreme values in the infrared image can be eliminated. Therefore, with the focusing apparatus according to the present disclosure, a better focusing effect can be achieved for the infrared image having large noise and multiple local extreme points, thereby achieving a higher focusing robustness.

[0068] In an embodiment based on the above embodiments, the determination module 501 includes a division unit and a first determination unit.

[0069] The blocking unit is configured to collect the current image by the lens, and divide the current image into blocks.

[0070] The first determination unit is configured to calculate a gradient of each of the blocks, and determine a block having a gradient greater than a preset value as the focus window.

[0071] In an embodiment based on the above embodiments, the coarse focusing module 502 includes a first performing unit, a filtering unit, a constructing unit, and a first setting unit.

[0072] The first performing unit is configured to perform the coarse focusing operation on the lens by the first step from the starting point to the ending point of the focusing range of the lens.

[0073] The filtering unit is configured to perform median filtering on the focus window to obtain an intermediate image when the lens is located at the position corresponding to the first potential value.

[0074] The constructing unit is configured to construct an edge gradient map corresponding to the focus window based on the intermediate image, and determine a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window.

[0075] The first setting unit is configured to set the first potential value corresponding to the maximum value among all the first sharpness evaluation values as the coarse focusing preferred potential value.

[0076] In an embodiment based on the above embodiments, the constructing unit includes a first calculating subunit and a second calculating subunit.

[0077] The first calculating subunit is configured to calculate a horizontal gradient and a vertical gradient of the intermediate image, and construct the edge gradient map corresponding to the focus window based on the horizontal gradient and the vertical gradient.

[0078] The second calculating subunit is configured to calculate an image gradient variance of the edge gradient map, and determine the image gradient variance as the first sharpness evaluation value of the focus window.

[0079] In an embodiment based on the above embodiments, the apparatus further includes a detection module.

[0080] The detection module is configured to perform motion detection on the current image, and trigger the coarse focusing module 502 to operate again if a moving target is detected in the current image.

[0081] In an embodiment based on the above embodiments, the fine focusing module 503 includes a second determination unit, a second performing unit, a second setting unit, a judgment unit, a third determination unit, and a fourth determination unit.

[0082] The second determination unit is configured to determine a maximum number of direction reversing operations and a target direction.

[0083] The second performing unit is configured to perform the fine focusing operation on the lens in the target direction by a second step, where a potential value corresponding to a starting position of the lens when the fine focusing operation is performed for a first time is the coarse focusing preferred potential value, and the second step is smaller than the first step.

[0084] The second setting unit is configured to determine a second sharpness evaluation value of the focus window when the lens is at a position corresponding to a second potential value during the fine focusing operation, and set a maximum value among all second sharpness evaluation values as a candidate target sharpness evaluation value, where the second potential value is a modulus value corresponding to a difference between voltages across the potentiometer before and after the lens moves by the second step.

[0085] The judgment unit is configured to, if a predetermined condition is met, determine whether a current number of direction reversing operations is greater than the maximum number of direction reversing operations, where the predetermined condition is that n consecutive second sharpness evaluation values are in descending order, trigger the third determination unit to operate if the current number of direction reversing operations is greater than the maximum number of direction reversing operations, and trigger the fourth determination unit to operate if the current number of direction reversing operations is less than or equal to the maximum number of direction reversing operations.

[0086] The third determination unit is configured to determine a maximum value among all candidate target sharpness evaluation values as the target sharpness evaluation value, and determine the fine focusing preferred potential value corresponding to the target sharpness evaluation value.

[0087] The fourth determination unit is configured to determine an opposite direction of the target direction as the target direction, and trigger the second performing unit to operate again.

[0088] In an embodiment based on the above embodiments, the fourth determination unit is configured to determine an opposite direction of the target direction as the target direction, update the second step, and trigger the second performing unit to operate again. The second step is negatively correlated with the current number of direction reversing operations.

[0089] Operating of the modules in the apparatus according to the above embodiments has been described in detail in the above-described method embodiments, which therefore are not elaborated herein.

[0090] An electronic device is further provided according to the present disclosure. Reference is made to Figure 6, which shows a schematic structural diagram of an electronic device 600 according to an exemplary embodiment. As shown in Figure 6, the device may include a processor 11 and a memory 12. The electronic device 600 may further include a lens 13, a user input apparatus 14, a display 15, and a motor 16.

[0091] The processor 11 is configured to control the overall operation of the electronic device 600 to perform all or some of the steps in the above focusing method. The processor may include an ARM and a DSP. The ARM is configured to perform logic determination, motor drive control, and I2C communication protocol. DSP may be configured to perform calculations of an evaluation function and a hill-climbing algorithm to achieve focusing, and the DSP may further be configured to perform motion detection to re-perform the focusing process if a moving target is detected.

[0092] The memory 12 is configured to store various types of data to support the operation of the electronic device 600, and the data may include codes such as code for focusing, code for motor control, and code for motion detection. The memory 12 may include any type of volatile storage device or non-volatile storage device or a combination thereof, such as a Static Random Access Memory (SRAM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), an Erasable Programmable Read-Only Memory (EPROM), a Programmable Read-Only Memory (PROM), a Read-Only Memory (ROM), a magnetic memory, a flash memory, a magnetic disk, or an optical disk.

[0093] The motor 16 is configured to drive the lens 13 to move. The lens 13, provided with an infrared sensor, is configured to collect an infrared image and send the infrared image to the processor 11 for processing. By using the user input apparatus 14, the user can select a window by drawing a rectangle on a webpage and click a focus button to achieve focusing, thereby realizing interaction. The display 15 is configured to display the infrared image, and the user can view the focusing effect on the display.

[0094] In another embodiment, a computer-readable storage medium storing program instructions is further provided. The program instructions, when executed by a processor, cause the processor to perform the focusing method. For example, the computer-readable storage medium may be the memory 12 storing the program instructions, and the program instructions may be executed by the processor 11 in the electronic device 600 to perform the focusing method.

[0095] Embodiments of the present disclosure are described in a progressive manner, each of the embodiments emphasizes differences from other embodiments, and the same or similar parts among the embodiments can be referred to each other. Since device embodiments are similar to method embodiments, the description thereof is relatively simple, and reference may be made to the description of the method embodiments for relevant parts. It should be noted that for those skilled in the art, improvements and modifications may also be made without departing from the principle of the disclosure. Those improvements and modifications should also fall within the scope of protection of the disclosure.

[0096] It should be further noted that the relationship terminologies such as "first", "second", and the like are only used herein to distinguish one entity or operation from another, rather than to necessitate or imply that the actual relationship or order exists between the entities or operations. Furthermore, terms of "include", "comprise" or any other variants are intended to be non-exclusive. Therefore, a process, method, article or device including a plurality of elements includes not only the elements but also other elements that are not enumerated, or also include the elements inherent for the process, method, article or device. Unless expressively limited otherwise, the statement "comprising (including) one... " does not exclude the case that other similar elements may exist in the process, method, article or device.


Claims

1. A focusing method, comprising:

determining a focus window based on a current image collected by a lens;

performing a coarse focusing operation on the lens by a first step from a starting point to an ending point of a focusing range of the lens, determining a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value, and setting a first potential value corresponding to a maximum value among all first sharpness evaluation values as a coarse focusing preferred potential value, wherein the first potential value is a modulus value corresponding to a difference between voltages across a potentiometer before and after the lens moves by the first step;

performing a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value; and

determining a current position of the lens, and performing a micro focusing operation on the lens to make a sharpness evaluation value of the focus window after the micro focusing process is performed greater than or equal to the target sharpness evaluation value.


 
2. The focusing method according to claim 1, wherein the determining a focus window based on a current image collected by a lens comprises:

collecting the current image by the lens, and dividing the current image into blocks; and

calculating a gradient of each of the blocks, and determining a block having a gradient greater than a preset value as the focus window.


 
3. The focusing method according to claim 1, wherein the determining a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value comprises:

performing median filtering on the focus window to obtain an intermediate image when the lens is located at the position corresponding to the first potential value; and

constructing an edge gradient map corresponding to the focus window based on the intermediate image, and determining a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window.


 
4. The focusing method according to claim 3, wherein the constructing an edge gradient map corresponding to the focus window based on the intermediate image and determining a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window comprises:

calculating a horizontal gradient and a vertical gradient of the intermediate image, and constructing the edge gradient map corresponding to the focus window based on the horizontal gradient and the vertical gradient; and

calculating an image gradient variance of the edge gradient map, and determining the image gradient variance as the first sharpness evaluation value of the focus window.


 
5. The focusing method according to claim 1, further comprising:
performing motion detection on the current image, and re-performing the coarse focusing operation on the lens by the first step from the starting point to the ending point of the focusing range of the lens in a case that a moving target is detected in the current image.
 
6. The focusing method according to any one of claims 1 to 5, wherein the performing a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value comprise:

determining a maximum number of direction reversing operations and a target direction, and performing the fine focusing operation on the lens in the target direction by a second step, wherein a potential value corresponding to a starting position of the lens when the fine focusing operation is performed for a first time is the coarse focusing preferred potential value, and the second step is smaller than the first step;

determining a second sharpness evaluation value of the focus window when the lens is at a position corresponding to a second potential value during the fine focusing operation, and setting a maximum value among all second sharpness evaluation values as a candidate target sharpness evaluation value, wherein the second potential value is a modulus value corresponding to a difference between voltages across the potentiometer before and after the lens moves by the second step;

determining, in a case that a predetermined condition is met, whether a current number of direction reversing operations is greater than the maximum number of direction reversing operations, wherein the predetermined condition is that n consecutive second sharpness evaluation values are in descending order;

determining, in a case that the current number of direction reversing operations is greater than the maximum number of direction reversing operations, a maximum value among all candidate target sharpness evaluation values as the target sharpness evaluation value, and determining the fine focusing preferred potential value corresponding to the target sharpness evaluation value; and

determining, in a case that the current number of direction reversing operations is less than or equal to the maximum number of direction reversing operations, an opposite direction of the target direction as the target direction, and re-performing the fine focusing operation on the lens in the target direction by the second step.


 
7. The focusing method according to claim 6, wherein after determining the opposite direction of the target direction as the target direction, the focusing method further comprises:
updating the second step, wherein the second step is negatively correlated with the current number of direction reversing operations.
 
8. A focusing apparatus, comprising:

a determination module, configured to determine a focus window based on a current image collected by a lens;

a coarse focusing module, configured to perform a coarse focusing operation on the lens by a first step from a starting point to an ending point of a focusing range of the lens, determine a first sharpness evaluation value of the focus window when the lens is at a position corresponding to a first potential value, and set a first potential value corresponding to a maximum value among all first sharpness evaluation values as a coarse focusing preferred potential value, wherein the first potential value is a modulus value corresponding to a difference between voltages across a potentiometer before and after the lens moves by the first step;

a fine focusing module, configured to perform a fine focusing operation based on a hill-climbing algorithm on the lens from a starting position corresponding to the coarse focusing preferred potential value to obtain a target sharpness evaluation value and a fine focusing preferred potential value corresponding to the target sharpness evaluation value; and

a micro focusing module, configured to determine a current position of the lens, and perform a micro focusing operation on the lens to make a sharpness evaluation value of the focus window after the micro focusing process is performed greater than or equal to the target sharpness evaluation value.


 
9. The focusing apparatus according to claim 8, wherein the determination module comprises:

a division unit, configured to collect the current image by the lens, and divide the current image into blocks; and

a first determination unit, configured to calculate a gradient of each of the blocks, and determine a block having a gradient greater than a preset value as the focus window.


 
10. The focusing apparatus according to claim 8, wherein the coarse focusing module comprises:

a first performing unit, configured to perform the coarse focusing operation on the lens by the first step from the starting point to the ending point of the focusing range of the lens;

a filtering unit, configured to perform median filtering on the focus window to obtain an intermediate image when the lens is located at the position corresponding to the first potential value;

a constructing unit, configured to construct an edge gradient map corresponding to the focus window based on the intermediate image, and determine a statistical characteristic of the edge gradient map as the first sharpness evaluation value of the focus window; and

a first setting unit, configured to set the first potential value corresponding to the maximum value among all the first sharpness evaluation values as the coarse focusing preferred potential value.


 
11. The focusing apparatus according to claim 10, wherein the constructing unit comprises:

a first calculating subunit, configured to calculate a horizontal gradient and a vertical gradient of the intermediate image, and construct the edge gradient map corresponding to the focus window based on the horizontal gradient and the vertical gradient; and

a second calculating subunit, configured to calculate an image gradient variance of the edge gradient map, and determine the image gradient variance as the first sharpness evaluation value of the focus window.


 
12. The focusing apparatus according to claim 8, further comprising:
a detection module, configured to perform motion detection on the current image, and trigger, in a case that a moving target is detected in the current image, the coarse focusing module to re-perform the coarse focusing operation on the lens by the first step from the starting point to the ending point of the focusing range of the lens.
 
13. The focusing apparatus according to any one of claims 8 to 12, wherein the fine focusing module comprises:

a second determination unit, configured to determine a maximum number of direction reversing operations and a target direction;

a second performing unit, configured to perform the fine focusing operation on the lens in the target direction by a second step, wherein a potential value corresponding to a starting position of the lens when the fine focusing operation is performed for a first time is the coarse focusing preferred potential value, and the second step is smaller than the first step;a second setting unit, configured to determine a second sharpness evaluation value of the focus window when the lens is at a position corresponding to a second potential value during the fine focusing operation, and set a maximum value among all second sharpness evaluation values as a candidate target sharpness evaluation value, wherein the second potential value is a modulus value corresponding to a difference between voltages across the potentiometer before and after the lens moves by the second step;

a judgment unit, configured to determine, in a case that a predetermined condition is met, whether a current number of direction reversing operations is greater than the maximum number of direction reversing operations, wherein the predetermined condition is that n consecutive second sharpness evaluation values are in descending order, trigger the third determination unit to operate if the current number of direction reversing operations is greater than the maximum number of direction reversing operations, and trigger the fourth determination unit to operate if the current number of direction reversing operations is less than or equal to the maximum number of direction reversing operations;

a third determination unit, configured to determine a maximum value among all candidate target sharpness evaluation values as the target sharpness evaluation value, and determine the fine focusing preferred potential value corresponding to the target sharpness evaluation value; and

a fourth determination unit, configured to determine an opposite direction of the target direction as the target direction, and trigger the second performing unit to operate again.


 
14. An electronic device, comprising:

a memory, configured to store a computer program; and

a processor, configured to perform the focusing method according to any one of claims 1 to 7 when executing the computer program.


 
15. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, causes the processor to perform the focusing method according to any one of claims 1 to 7.
 




Drawing
















Search report









Search report