Automatic focusing method of infrared lens, infrared imaging equipment and storage medium

By calculating the difference and gradient information between infrared images and blurred images, rapid autofocus of infrared lenses is achieved, solving the problem of inaccurate focusing of infrared images in outdoor applications and improving imaging quality and dynamic target tracking capabilities.

CN121728348APending Publication Date: 2026-03-24YANTAI IRAY TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-31
Publication Date
2026-03-24

Smart Images

  • Figure CN121728348A_ABST
    Figure CN121728348A_ABST
Patent Text Reader

Abstract

The invention provides an automatic focusing method of an infrared lens, an infrared imaging device and a storage medium, and the method carries out the out-of-focus judgment based on the difference between an original infrared image and a blurred image, does not depend on the specific image content or contrast ratio, and achieves the accurate focusing of an infrared scene lacking obvious edges and textures. And the out-of-focus state can be detected by capturing the overall change of high-frequency noise and details in the image, so that the problem that the out-of-focus detection of a traditional gradient algorithm in a weak texture scene is invalid is effectively avoided. In the focusing process, automatic focusing is carried out according to the change of the second definition evaluation value of the focusing image, the detection speed is high, high-frequency motion in the focusing process can be quickly responded, and quick automatic focusing is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of infrared device control technology, and in particular to an automatic focusing method for an infrared lens, an infrared imaging device, and a storage medium. Background Technology

[0002] Infrared technology has been widely applied in various fields such as security monitoring, industrial inspection, forest fire prevention, and fire rescue. Large infrared pan-tilt-zoom (PTZ) cameras and similar devices are often deployed in unattended areas to perform functions such as fire detection, vehicle and pedestrian tracking, and intrusion prevention. These functions require continuously clear infrared images. However, in practical outdoor applications, due to factors such as temperature fluctuations, continuous lens zoom, and poor focus of zoom lenses, infrared images are prone to deviating from optimal focus, resulting in blurred images.

[0003] Compared to visible light images, infrared images inherently have lower resolution, coarser object edges, and lower contrast, making traditional autofocus algorithms based on contrast or gradients difficult to apply directly. Currently, most infrared devices still rely on manual focusing or limited autofocus through preset cruise points, resulting in low efficiency and reliability. Summary of the Invention

[0004] To address the existing technical problems, this application provides an autofocus method, an infrared imaging device, and a storage medium for an infrared lens that enables fast and reliable autofocus.

[0005] In a first aspect, an autofocus method for an infrared lens is provided, the method comprising: Acquire a sequence of infrared images captured by an infrared camera; Based on the difference between the infrared image and its blurred image, calculate the first sharpness evaluation value of each frame of the infrared image sequence. If the first sharpness evaluation value of N consecutive frames of infrared images is lower than the threshold, the motor of the infrared lens is controlled to focus and the focused image is acquired in real time. Calculate a second sharpness evaluation value based on the gradient information of the focused image; Based on the changes in the second sharpness evaluation value of the continuously focused images, a maximum evaluation value is determined, and autofocus is performed based on the maximum evaluation value.

[0006] In a second aspect, an infrared imaging device is provided, including an infrared lens, a motor, and a controller. The motor is mechanically coupled to the optical components of the infrared lens; the controller is electrically connected to the motor; the controller includes a processor and a memory connected to the processor, the memory storing a computer program executable by the processor, the computer program being executed by the processor to perform the steps of the focusing method of the infrared lens described in the above embodiments.

[0007] Thirdly, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the above-described focusing method for an infrared lens.

[0008] The autofocus method for infrared lenses provided in the above embodiments first calculates a first sharpness evaluation value for each frame of the infrared image sequence based on the difference between the original infrared image and its blurred image. If the first sharpness evaluation value of N consecutive frames of infrared images is lower than a threshold, the infrared lens is determined to be out of focus. Then, the motor of the infrared lens is controlled to adjust the focus. A second sharpness evaluation value is calculated based on the gradient information of the continuously adjusted images. Autofocus is then performed based on changes in the second sharpness evaluation value. This method determines out-of-focus based on the difference between the original infrared image and its blurred image, without relying on specific image content or contrast. Even in infrared scenes lacking obvious edges and textures, it can detect out-of-focus states by capturing the overall changes in high-frequency noise and details in the image, effectively avoiding the problem of ineffective out-of-focus detection in weak-texture scenes by traditional gradient-based algorithms. During the focusing process, the second sharpness evaluation value is calculated based on the gradient information of the adjusted image, and autofocus is performed based on changes in the second sharpness evaluation value. The detection speed is fast, and it can quickly respond to high-frequency movements during the focusing process, achieving rapid autofocus.

[0009] The infrared imaging device and storage medium provided in the above embodiments belong to the same concept as the corresponding automatic focusing method embodiments of infrared lenses, and thus have the same technical effects as the corresponding automatic focusing method embodiments of infrared lenses, which will not be repeated here. Attached Figure Description

[0010] Figure 1 This is a structural block diagram of an infrared imaging device in one embodiment.

[0011] Figure 2 This is a flowchart of an automatic focusing method for an infrared lens in one embodiment.

[0012] Figure 3 This is a flowchart of an autofocus method for an infrared lens in another embodiment.

[0013] Figure 4This is a flowchart of an autofocus method for an infrared lens in yet another embodiment. Detailed Implementation

[0014] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0015] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0016] In the following description, the phrase "some embodiments" refers to a subset of all possible embodiments. It should be noted that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.

[0017] In the following description, the terms "first, second, and third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, and third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0018] Infrared technology has been widely applied in various fields such as security monitoring, industrial inspection, forest fire prevention, and fire rescue. Large infrared pan-tilt-zoom (PTZ) cameras and similar devices are often deployed in unattended areas to perform functions such as fire detection, vehicle and pedestrian tracking, and intrusion prevention. These functions require continuously clear infrared images. However, in practical outdoor applications, due to factors such as temperature fluctuations, continuous lens zoom, and poor focus of zoom lenses, infrared images are prone to deviating from optimal focus, resulting in blurred images.

[0019] Compared to visible light images, infrared images inherently have lower resolution, coarser object edges, and lower contrast, making traditional autofocus algorithms based on contrast or gradients difficult to apply directly. Currently, most infrared devices still rely on manual focusing or limited autofocus through preset cruise points, resulting in low efficiency and reliability.

[0020] To address this problem, the first aspect of this application provides an autofocus method for an infrared lens. This method can be used in infrared imaging devices, such as handheld infrared imaging devices, vehicle-mounted infrared night vision devices, and infrared monitoring devices. Infrared imaging devices such as... Figure 1 As shown, it includes an infrared camera 10, a motor 20, and a controller 30.

[0021] The infrared lens 10 is used to receive and converge the infrared radiation of the target object to form an infrared image on the imaging sensor. It contains at least one movable optical component, such as an optical lens group or lens, which adjusts the imaging focus by changing its axial position.

[0022] The motor 20 is mechanically coupled to the movable optical component of the infrared lens 10. The motor 20 is preferably a stepper motor, which drives the optical component of the infrared lens 10 to move back and forth along the optical axis under the drive of a control signal, so as to achieve focus adjustment.

[0023] The controller 30 includes a processor and a memory connected to the processor. The memory stores a computer program that can be executed by the processor. The computer program is executed by the processor to implement the autofocus method of this application, which is used to send control signals to the motor 20 to control the motor 20 to drive the optical components of the infrared lens 10 to move back and forth along the optical axis to achieve autofocus.

[0024] The autofocus method for this infrared lens first calculates the first sharpness evaluation value of each frame in the infrared image sequence based on the difference between the original infrared image and its blurred image. If the first sharpness evaluation value of N consecutive frames of infrared images is lower than a threshold, the infrared lens is determined to be out of focus. Then, the motor of the infrared lens is controlled to adjust the focus, and autofocus is performed based on the changes in the second sharpness evaluation value of the continuously adjusted images. This method determines out-of-focus based on the difference between the original infrared image and its blurred image, without relying on specific image content or contrast. Even in infrared scenes lacking obvious edges and textures, it can detect the out-of-focus state by capturing the overall changes in high-frequency noise and details in the image, effectively avoiding the problem of ineffective out-of-focus detection in weak texture scenes by traditional gradient-based algorithms. During the focusing process, the second sharpness evaluation value is calculated based on the gradient information of the adjusted image, and autofocus is performed based on the changes in the second sharpness evaluation value of the adjusted image. The detection speed is fast, and it can quickly respond to high-frequency movements during the focusing process, achieving rapid autofocus.

[0025] like Figure 2 As shown, the autofocus method of this infrared lens includes: Step 202: Obtain the infrared image sequence captured by the infrared lens.

[0026] In practical applications, the controller 30 periodically acquires infrared image sequences at a preset acquisition frequency or sampling time interval. For example, in a fixed infrared imaging device used for environmental monitoring, this interval can be set to 1 minute or longer. In a dynamic infrared imaging device used for handheld detection, this interval can be set to 0.1 seconds or shorter. This acquisition frequency or time interval can be configured according to the needs of the application scenario, or it can be set by the user according to their requirements.

[0027] Step 204: Based on the difference between the infrared image and its blurred image, calculate the first sharpness evaluation value of each frame of the infrared image in the infrared image sequence.

[0028] Infrared images are characterized by low contrast and weak texture. Traditional sharpness assessment algorithms based on contrast or gradient are inadequate for accurately estimating their out-of-focus state.

[0029] The sharpness evaluation function used in this embodiment specifically calculates the difference between the infrared image and its blurred image. That is, based on the difference between the infrared image and its blurred image, the first sharpness evaluation value of each frame of the infrared image in the infrared image sequence is calculated.

[0030] By blurring the original infrared image, a blurred image is obtained to filter out high-frequency details. Blurring techniques such as Gaussian blurring or mean blurring can be used. The greater the difference between the original infrared image and its blurred image, the more high-frequency information remains in the original infrared image, indicating a clearer original image. Conversely, the smaller the difference between the original infrared image and its blurred image, the less high-frequency information the original image contains, indicating a more blurred original infrared image.

[0031] This sharpness evaluation method utilizes the difference between the original infrared image and its blurred image for assessment, independent of external information and specific image content. In other words, the difference between the infrared image and its blurred image evaluates the amount of information remaining in the original infrared image after blurring. Infrared images may lack rich structural texture, but the thermal noise, fixed pattern noise, and random noise inevitably introduced during the imaging process are themselves significant high-frequency signals. Therefore, the evaluation method based on the difference between the infrared image and its blurred image essentially utilizes various high-frequency noises as effective feature signals, without relying on image content edges, textures, or other features for evaluation. This allows for stable and accurate determination of the defocus state of infrared images even under low contrast and weak texture conditions.

[0032] Step 206: If the first sharpness evaluation value of N consecutive frames of infrared images is lower than the threshold, control the motor of the infrared lens to focus and acquire focused images in real time.

[0033] If the first sharpness evaluation value of N consecutive infrared images is lower than the threshold, it is determined to be out of focus. The controller controls the movement of the infrared lens motor to focus and acquires focused images in real time. For example, one focused image is acquired for each movement. N can be three frames. If the first sharpness evaluation value of three consecutive infrared images is lower than the threshold, it is determined to be out of focus. If the first sharpness evaluation value of multiple consecutive infrared images is greater than or equal to the threshold, it is determined to be sharp.

[0034] Step 208: Calculate the second sharpness evaluation value based on the gradient information of the focused image.

[0035] For an image, its gradient is a vector representing the direction and rate of change of brightness at each pixel. Sharp images typically have sharp edges and rich textures; these areas are represented by significant changes in pixel values ​​over short distances, i.e., large gradient magnitudes. Therefore, based on gradient information, the sum of horizontal gradients, the sum of vertical gradients, or a weighted sum of the horizontal and vertical gradients can be calculated as a second sharpness evaluation value. Sharp images usually have sharper edges and richer details, thus yielding a larger second sharpness evaluation value based on gradient information; while blurry images have smooth edges and lost high-frequency details, resulting in a smaller second sharpness evaluation value. Due to this characteristic, the second sharpness evaluation value is highly sensitive to changes in focus position. When the lens is accurately focused, the image is sharpest, and the second sharpness evaluation value reaches its maximum; when out of focus, the image is blurry, and the second sharpness evaluation value decreases. The relationship between the second sharpness evaluation value and lens position typically exhibits a unimodal function relationship, with the peak position being the optimal focus point. This characteristic makes it very suitable for autofocus.

[0036] In one embodiment, the second sharpness evaluation value is calculated based on the gradient information of the focused image. This can be any one of calculating the sum of the horizontal gradient, the sum of the vertical gradient, or a weighted sum of the horizontal and vertical gradients of the focused image.

[0037] Among them, the horizontal gradient sum refers to the sum of the absolute values ​​of the horizontal gradients of all pixels in the image, which mainly reflects the total intensity of the vertical edges in the image.

[0038] The sum of vertical gradients is obtained by summing the absolute values ​​of the vertical gradients of all pixels in an image, and mainly reflects the total intensity of the horizontal edges in the image.

[0039] Considering the edge direction distribution characteristics of different application scenarios, the calculation type of the second sharpness evaluation value can be configured. In monitoring scenarios dominated by vertical structures, such as forests and cities, the horizontal gradient sum can be configured as the sharpness evaluation value. In scenarios with significant horizontal structures (such as horizons and sea levels), the vertical gradient sum can be configured as the sharpness evaluation value. In this embodiment, the second sharpness evaluation value is obtained by calculating any one of the horizontal gradient sum, vertical gradient sum, or a weighted sum of the horizontal and vertical gradient sums of the focused image. This sharpness evaluation method, through the statistical accumulation of pixel gradients across the entire image, has a certain degree of resistance to local noise.

[0040] Step 210: Determine the maximum evaluation value based on the change of the second sharpness evaluation value of the continuously focused image, and perform autofocus based on the maximum evaluation value.

[0041] In this embodiment, a second sharpness evaluation value of the focused image is continuously calculated, and the trend of this value changing with the lens position is monitored in real time. During the focusing process, the system continuously records and updates the maximum evaluation value encountered and its corresponding lens position. When the maximum evaluation value is found, the controller stops the motor and drives the lens to the position corresponding to the maximum evaluation value, completing precise focusing.

[0042] The aforementioned autofocus method for infrared lenses first calculates a first sharpness evaluation value for each frame in the infrared image sequence based on the difference between the original infrared image and its blurred image. If the first sharpness evaluation value of N consecutive frames is below a threshold, the infrared lens is determined to be out of focus. Then, the lens's motor is controlled to refocus. A second sharpness evaluation value is calculated based on the gradient information of the continuously refocused images. Autofocus is then performed based on changes in this second sharpness evaluation value. This method determines out-of-focus based on the difference between the original infrared image and its blurred image, independent of specific image content or contrast. Even in infrared scenes lacking obvious edges and textures, it can detect out-of-focus states by capturing overall changes in high-frequency noise and details in the image, effectively avoiding the problem of ineffective out-of-focus detection in weak-texture scenes by traditional gradient-based algorithms. During the focusing process, the second sharpness evaluation value is calculated based on the gradient information of the refocused image, and autofocus is performed based on changes in this value. This results in fast detection speed and rapid response to high-frequency movements during the focusing process, achieving fast autofocus.

[0043] In one embodiment, the first sharpness evaluation value of each frame of infrared image in the infrared image sequence is calculated based on the difference between the infrared image and its blurred image. This includes: blurring each frame of infrared image in the infrared image sequence to obtain the blurred image corresponding to the infrared image; comparing the infrared image with its corresponding blurred image, calculating the normalized difference value, and obtaining the first sharpness evaluation value of the infrared image.

[0044] Specifically, Gaussian blur or mean blur algorithms are used to smooth the infrared image in order to filter out high-frequency details and noise in the image and obtain the corresponding blurred image.

[0045] By comparing the original infrared image with its blurred image pixel by pixel, the absolute difference between the two is calculated to obtain a difference map. Then, the cumulative value of the entire difference map is calculated as the original difference value. To eliminate the influence of overall image brightness, contrast, and scene content on the evaluation results, the original difference value is normalized to obtain the first sharpness evaluation value.

[0046] The sharpness evaluation method in this embodiment utilizes only the image's own information, without requiring any prior templates or ideal images for reference. Through normalization operations, the sharpness evaluation method can adapt to infrared scenes with varying brightness, contrast, and content, outputting reliable sharpness evaluation values.

[0047] In one embodiment, such as Figure 3 As shown, an autofocus method for an infrared lens further includes: Step 302: Obtain the infrared image sequence captured by the infrared lens.

[0048] The specific implementation process of this step is similar to that of step 202, and will not be repeated here.

[0049] Step 304: Based on the difference between the infrared image and its blurred image, calculate the first sharpness evaluation value of each frame of the infrared image in the infrared image sequence.

[0050] Specifically, each frame of the infrared image sequence is blurred to obtain a blurred image corresponding to the infrared image; the infrared image is compared with its corresponding blurred image, and the normalized difference value is calculated to obtain the first sharpness evaluation value of the infrared image.

[0051] Step 306: Dynamically determine the threshold based on the first sharpness evaluation value of the M consecutive infrared images.

[0052] In this embodiment, the first sharpness evaluation value used for defocus judgment is obtained based on the difference between the infrared image and its blurred image. This sharpness evaluation method uses the difference between the original infrared image and its blurred image for evaluation, without relying on external information or specific image content. Therefore, the first sharpness evaluation value is a relative sharpness based on the angle of image information, that is, how much more high-frequency information is added relative to its own blurred image, rather than an absolute sharpness value.

[0053] However, different infrared scenes have different thermal radiation distributions, and the first sharpness evaluation value obtained based on the difference between the infrared image and its blurred image under different environments and scenes varies greatly. Therefore, if a static threshold is used for defocus judgment, it will be inaccurate.

[0054] In this embodiment, by dynamically determining the threshold based on the first sharpness evaluation value of M consecutive infrared images, the threshold used to determine defocus can change with the scene. When the system is focused on a new scene, it can learn the range of the first sharpness evaluation value of that scene in a sharp state and set the threshold based on this.

[0055] In this way, the threshold can be adaptively determined according to different environments, improving the accuracy of infrared devices in judging defocusing in complex environments.

[0056] Step 308: Determine whether the first sharpness evaluation value of N consecutive infrared images is lower than the threshold, where M < N. If so, proceed to step 310.

[0057] By setting M < N, the threshold can be quickly adjusted to adapt to the scene before a stable judgment is made on whether the image is out of focus. If the first sharpness evaluation value of N consecutive frames of infrared images is lower than the threshold, the infrared lens is judged to be out of focus.

[0058] Step 310: Control the motor of the infrared lens to focus and acquire focused images in real time.

[0059] Step 312: Calculate the second sharpness evaluation value based on the gradient information of the focused image.

[0060] Step 314: Determine the maximum evaluation value based on the change of the second sharpness evaluation value of the continuously focused image, and perform autofocus based on the maximum evaluation value.

[0061] In this embodiment, defocus detection is based on the difference between the original infrared image and its blurred image, independent of specific image content or contrast. Even in infrared scenes lacking obvious edges and textures, defocus can be detected by capturing overall changes in high-frequency noise and details within the image, effectively avoiding the ineffectiveness of traditional gradient-based algorithms in weak-texture scenes. By dynamically determining the threshold based on the first sharpness evaluation value of M consecutive infrared images, the threshold can be adaptively and dynamically determined according to different environments, achieving accurate defocus detection for infrared devices in complex environments. During the focusing process, automatic focusing is performed based on changes in the second sharpness evaluation value of the focused image, resulting in fast detection speed and rapid response to high-frequency movements during focusing, achieving fast automatic focusing.

[0062] like Figure 3 As shown, the step of dynamically determining the threshold based on the first sharpness evaluation value of M consecutive infrared images includes: Step 3061: Set the initial threshold to the current threshold.

[0063] The system presets an initial threshold T0, and first sets the current threshold T = T0.

[0064] Step 3062: If the first sharpness evaluation value of the M consecutive infrared images is lower than the current threshold, then update the current threshold based on the first sharpness evaluation value of the M infrared images.

[0065] Specifically, if the first sharpness evaluation value of M consecutive infrared images is lower than the current threshold, the scene is determined to have degraded, and the current threshold is updated based on the first sharpness evaluation value of the M infrared images. For example, if M is 2, when the first sharpness evaluation value of 2 consecutive infrared images is lower than the current threshold, the current threshold is updated based on the first sharpness evaluation value of the 2 consecutive infrared images. This allows for adaptive threshold reduction when the scene is weak.

[0066] In one embodiment, the current threshold can be updated to the minimum value among the first sharpness evaluation values ​​of the M-frame infrared images.

[0067] Specifically, when the first sharpness evaluation value of M consecutive infrared images is lower than the current threshold, it indicates that the scene's sharpness level has consistently fallen below the previous judgment standard, meaning the scene has deteriorated. At this point, to adapt to the new scene conditions, the current threshold is updated to the minimum value among these M first sharpness evaluation values. Assume the current threshold T is 0.6, and M=2. If the first sharpness evaluation values ​​of two consecutive infrared images are 0.55 and 0.52 respectively, both lower than 0.6, then the current threshold T is updated to the smaller of these two first sharpness evaluation values, resulting in a new threshold T=0.52. This threshold is then used to judge the next frame of the infrared image.

[0068] This adaptive threshold adjustment can quickly adapt to scene degradation and avoid frequent refocusing due to excessively high thresholds.

[0069] In one embodiment, the current threshold can be updated to the average value of the first sharpness evaluation value of the M-frame infrared images.

[0070] When the first sharpness evaluation value of M consecutive frames is lower than the current threshold, the average of these M frames' first sharpness evaluation values ​​is taken as the new threshold. This method considers the overall performance of the most recent M frames, rather than extreme values. Updating the threshold using the average value smooths out fluctuations in individual frames, making threshold adjustments more stable. It reflects the average level of recent scene sharpness, making the new threshold more representative. Compared to the minimum value method, the average value method avoids setting the threshold too low, thus maintaining a certain level of focus sensitivity.

[0071] Assuming the current threshold T = 0.6, M = 2, and the first sharpness evaluation values ​​for two consecutive frames are 0.55 and 0.52, according to this embodiment, the current threshold T is updated to the average of the first sharpness evaluation values ​​of these two frames, and the new threshold T = 0.535.

[0072] This adaptive threshold adjustment method is relatively stable and can reflect the average level of recent sharpness, avoiding overly aggressive threshold adjustments due to occasional fluctuations in a single frame.

[0073] Step 3063: If the current threshold is lower than the initial threshold and the first sharpness evaluation value of the current frame infrared image is higher than the current threshold, then update the current threshold according to the initial threshold and the first sharpness evaluation value of the current frame infrared image.

[0074] Specifically, if the current threshold is lower than the initial threshold, it means the threshold was lowered due to scene degradation. When the first sharpness evaluation value of the current frame infrared image is higher than the current threshold, it means the sharpness of the current image is higher than the adjusted threshold. Therefore, when the current threshold is lower than the initial threshold and the first sharpness evaluation value of the current frame infrared image is higher than the current threshold, it indicates that the current scene has improved. At this time, threshold restoration is needed, appropriately increasing the current threshold towards the initial threshold to adapt to the improved scene.

[0075] In one embodiment, the current threshold is updated to the smaller of the initial threshold and the first sharpness evaluation value of the current frame's infrared image. This method of threshold restoration ensures that the restored threshold does not exceed the initial threshold, nor does it exceed the first sharpness evaluation value of the current frame's infrared image. This approach appropriately increases the threshold while avoiding overly aggressive threshold settings due to excessively high values ​​in a single frame.

[0076] In one embodiment, the current threshold is updated to the average of the initial threshold and the first sharpness evaluation value of the current frame infrared image. This method of threshold recovery takes into account both the initial benchmark and the current actual scene, allowing the threshold to smoothly transition to an intermediate value. This method has a relatively large adjustment range and can approach the initial threshold more quickly.

[0077] The dynamic threshold adjustment process in this embodiment can automatically detect scene degradation and adaptively lower the threshold, and automatically detect scene recovery and adaptively restore the threshold. This allows it to adapt to different environments and scenes, determine the defocus detection threshold, and improve the accuracy of defocus detection by infrared imaging equipment in various environments.

[0078] In one embodiment, such as Figure 4 As shown, an autofocus method for an infrared lens includes: Step 402: Obtain the infrared image sequence captured by the infrared lens.

[0079] Step 404: Based on the difference between the infrared image and its blurred image, calculate the first sharpness evaluation value of each frame of the infrared image in the infrared image sequence.

[0080] Specifically, each frame of the infrared image sequence is blurred to obtain a blurred image corresponding to the infrared image; the infrared image is compared with its corresponding blurred image, and the normalized difference value is calculated to obtain the first sharpness evaluation value of the infrared image.

[0081] Step 406: Dynamically determine the threshold based on the first sharpness evaluation value of the M consecutive infrared images.

[0082] Specifically, let the initial threshold be the current threshold; if the first sharpness evaluation value of M consecutive infrared images is lower than the current threshold, then update the current threshold based on the minimum value among the first sharpness evaluation values ​​of the M infrared images; if the current threshold is lower than the initial threshold and the first sharpness evaluation value of the current frame infrared image is higher than the current threshold, then update the current threshold based on the smaller value among the initial threshold and the first sharpness evaluation value of the current frame infrared image.

[0083] This step enables automatic detection of scene degradation and adaptive threshold lowering, as well as automatic detection of scene recovery and adaptive threshold restoration. This allows for adaptation to different environments and scenarios, determining the defocus detection threshold, and improving the accuracy of defocus detection by infrared imaging equipment in various environments.

[0084] Step 408: If the first sharpness evaluation value of N consecutive frames of infrared images is lower than the threshold, determine the search direction for instructing the motor of the infrared lens to perform focusing search and initialize the maximum evaluation value.

[0085] By setting M < N, the threshold can be quickly adjusted to adapt to the scene before a stable judgment is made on whether the image is out of focus. If the first sharpness evaluation value of N consecutive frames of infrared images is lower than the threshold, the infrared lens is judged to be out of focus.

[0086] During autofocus, the second sharpness rating of the image exhibits a unimodal function relationship with the lens position. The peak position is the optimal focus point. Therefore, to improve search efficiency, methods such as bidirectional probing can be used to determine the search direction.

[0087] Specifically, the motor's current position is recorded as the initial position, and an infrared image of this position is acquired, with its second sharpness evaluation value calculated. Then, the motor is controlled to move forward one preset step length to reach the forward detection position. An infrared image is acquired at the forward detection position, and its second sharpness evaluation value is calculated. Next, the motor is controlled to move in the opposite direction from the forward detection position back to the initial position, and then continues to move in the opposite direction by the same preset step length to reach the reverse detection position. An infrared image is acquired at the reverse detection position, and its second sharpness evaluation value is calculated.

[0088] If the second sharpness evaluation value of the forward detection position is the largest, the forward direction is determined as the search direction. The second sharpness evaluation value of the forward detection position is used as the initial maximum evaluation value, and the forward detection position is used as the search starting point.

[0089] If the second sharpness evaluation value of the reverse detection position is the largest, the reverse direction is determined as the search direction. The second sharpness evaluation value of the reverse detection position is used as the initial maximum evaluation value, and the reverse detection position is used as the search starting point.

[0090] If the second sharpness rating at the initial position is the highest, it means the current position is close to the optimal focus, and the second sharpness rating at the current position can be used as the initial maximum rating. The search direction can be either forward or reverse.

[0091] Step 410: Control the motor of the infrared lens to focus and acquire focused images in real time.

[0092] Step 412: Calculate the second sharpness evaluation value based on the gradient information of the focused image.

[0093] Step 414: Determine whether the second sharpness evaluation value of the currently focused image is greater than the maximum evaluation value. If yes, proceed to step 416. If no, proceed to step 418.

[0094] Step 416: Update the maximum evaluation value to the second sharpness evaluation value of the currently focused image, and record the position of the maximum evaluation value. After step 416, return to step 410 and control the motor to continue searching for focus.

[0095] Step 418: Control the motor to move to the position where the current maximum evaluation value is located.

[0096] In this embodiment, during autofocus, the second sharpness evaluation value of the image and the lens position exhibit a single-peak function relationship. The peak position is the optimal focus point. First, a two-way trial-and-error method is used to determine the search direction and initialize the maximum evaluation value. Then, the lens is moved along this search direction and focused images are acquired. The second sharpness evaluation value is calculated in real time based on the gradient information of the focused images and compared with the currently recorded maximum evaluation value. If the second sharpness evaluation value of the current focused image is greater than the maximum evaluation value, the maximum evaluation value and its position are updated, and the search continues; if the second sharpness evaluation value of the current focused image, or multiple consecutive focused images, is found to be less than the maximum evaluation value, it is considered that the peak value has been exceeded, the search stops, and the lens is driven to the position corresponding to the maximum evaluation value to complete focusing.

[0097] During the peak search process of autofocus, the change in the image's second sharpness evaluation value should theoretically exhibit a smooth, single-peak curve. However, in actual infrared imaging, due to image noise or scene changes, the second sharpness evaluation value may fluctuate or jitter. To reduce the interference of these factors on focusing, the search can be stopped only when the second sharpness evaluation value of several consecutive focusing images is lower than the maximum evaluation value. This improves the accuracy of autofocus.

[0098] This method improves search efficiency by first determining the search direction and the maximum evaluation value to accurately determine the search direction.

[0099] The focusing method of the infrared lens in this application has the following effects: 1. By judging defocus based on the difference between the original infrared image and its blurred image, it does not depend on specific image content or contrast. Even for infrared scenes lacking obvious edges and textures, it can detect the defocus state by capturing the overall changes in high-frequency noise and details in the image, effectively avoiding the problem of traditional gradient-based algorithms failing to detect defocus in weak texture scenes.

[0100] 2. The threshold is dynamically determined based on the first sharpness evaluation value of M consecutive infrared images. This allows for adaptive determination of the threshold used for defocus detection based on different environments, improving the accuracy of defocus detection by infrared devices in complex environments.

[0101] 3. After detecting defocusing, first determine the search direction and the maximum evaluation value. Based on the change of the second sharpness evaluation value of the continuously focused image, determine the maximum evaluation value and perform automatic focusing based on the maximum evaluation value. This can improve focusing efficiency and enable fully automatic, high-precision focusing of infrared devices in complex environments.

[0102] 4. From change detection and focus calculation to position adjustment, no manual intervention is required, which meets the requirement of infrared monitoring equipment to continuously ensure the clarity of infrared images under unattended conditions, thereby significantly improving the imaging quality and dynamic target tracking capability of infrared equipment in complex scenarios such as security monitoring and industrial inspection.

[0103] In another aspect, this application also provides a computer-readable storage medium storing a computer program. When executed by a processor, this computer program implements the various processes of the above-described infrared lens focusing method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0104] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0105] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0106] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. An autofocus method for an infrared lens, characterized in that, The method includes: Acquire a sequence of infrared images captured by an infrared camera; Based on the difference between the infrared image and its blurred image, calculate the first sharpness evaluation value of each frame of the infrared image sequence. If the first sharpness evaluation value of N consecutive frames of infrared images is lower than the threshold, the motor of the infrared lens is controlled to focus and the focused image is acquired in real time. Calculate a second sharpness evaluation value based on the gradient information of the focused image; Based on the changes in the second sharpness evaluation value of the continuously focused images, a maximum evaluation value is determined, and autofocus is performed based on the maximum evaluation value.

2. The focusing method for an infrared lens according to claim 1, characterized in that, The step of calculating a first sharpness evaluation value for each frame of the infrared image sequence based on the difference between the infrared image and its blurred image includes: The infrared images in each frame of the infrared image sequence are blurred to obtain the blurred images corresponding to the infrared images; The infrared image is compared with its corresponding blurred image, and the normalized difference value is calculated to obtain the first sharpness evaluation value of the infrared image.

3. The focusing method for an infrared lens according to claim 1, characterized in that, The method further includes: The threshold is dynamically determined based on the first sharpness evaluation value of the infrared images in M ​​consecutive frames; where M < N.

4. The focusing method for an infrared lens according to claim 2, characterized in that, The step of dynamically determining the threshold based on the first sharpness evaluation value of the infrared images in M ​​consecutive frames includes: Let the initial threshold be the current threshold; If the first sharpness evaluation value of M consecutive infrared images is lower than the current threshold, then the current threshold is updated based on the first sharpness evaluation value of the M infrared images.

5. The focusing method for an infrared lens according to claim 4, characterized in that, The step of updating the current threshold based on the first sharpness evaluation value of the M-frame infrared images includes updating the current threshold to the minimum or average value of the first sharpness evaluation values ​​of the M-frame infrared images.

6. The focusing method for an infrared lens according to claim 4, characterized in that, The method further includes: If the current threshold is lower than the initial threshold and the first sharpness evaluation value of the current frame infrared image is higher than the current threshold, then the current threshold is updated according to the initial threshold and the first sharpness evaluation value of the current frame infrared image.

7. The focusing method for an infrared lens according to claim 6, characterized in that, The step of updating the current threshold based on the initial threshold and the first sharpness evaluation value of the current frame infrared image includes: updating the current threshold to the smaller or average value of the initial threshold and the first sharpness evaluation value of the current frame infrared image.

8. The focusing method for an infrared lens according to any one of claims 1 to 7, characterized in that, Prior to the step of controlling the motor of the infrared lens to perform focusing, the method further includes: Determine the search direction for instructing the motor of the infrared lens to perform focusing search and initialize the maximum evaluation value; The step of determining the maximum evaluation value based on the changes in the second sharpness evaluation value of the continuously focused images, and performing automatic focusing based on the maximum evaluation value, includes: If the second sharpness evaluation value of the current focused image is greater than the maximum evaluation value, then the maximum evaluation value is updated to the second sharpness evaluation value of the current focused image, and the position of the maximum evaluation value is recorded; If the second sharpness evaluation value of the current focused image or multiple consecutive frames of the current focused image is less than the maximum evaluation value, then the motor is controlled to move to the position where the current maximum evaluation value is located.

9. An infrared imaging device, comprising an infrared lens, a motor, and a controller, wherein the motor is mechanically coupled to an optical component of the infrared lens; the controller is electrically connected to the motor; the controller includes a processor and a memory connected to the processor, the memory storing a computer program executable by the processor, the computer program being executed by the processor to perform the steps of the focusing method of the infrared lens according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the focusing method for an infrared lens as described in any one of claims 1 to 8.