Automatic focusing method, infrared thermal imager and storage medium
By combining temperature images and infrared images to automatically acquire the focus area and adjust the focal length based on iterative cycles, the problem of cumbersome manual focus in the prior art is solved, and the simplification and clarity optimization of autofocus are achieved.
Patent Information
- Application Number
- CN202510393180.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-31
- Publication Date
- 2025-07-04
AI Technical Summary
The existing automatic focus method requires manual alignment of the target or selecting the target position in the image. When the target moves or the lens moves, it needs to be refocused, which is cumbersome.
By acquiring the temperature image and infrared image, determining the coordinate value of the target temperature, generating an infrared grayscale image and determining the focus area, calculating the initial clarity, controlling the rotation of the focus motor to adjust the focal length, and iterating the focal length based on the cycle to achieve the clearest state.
It realizes automatic acquisition of the focus area and iteratively adjusting the focus length through looping and iteratively to make the image reach the clearest state, simplifying the operation process.
Smart Images

Figure CN120264137A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of infrared thermal imaging technology, and particularly relates to an autofocus method, an infrared thermal imager, and a storage medium. Background Art
[0002] Autofocus aims to automatically adjust the lens focus instead of manual operation to make the image reach the clearest state, and is widely used in the field of infrared thermal imaging. Existing autofocus methods are divided into two types: based on laser ranging and image contrast. The autofocus method based on laser ranging calculates the best focal length by measuring the distance between the target and the lens. The autofocus method based on image contrast calculates the image sharpness and performs iterative control on the motor to find the position that makes the image clearest, thereby achieving autofocus. When it is necessary to focus on a specified target or an area of interest temperature in the image, the existing methods require manual alignment of the lens with the target or selection of the position of the target in the image. When the target moves or the lens moves, refocusing is required, and the operation is cumbersome.
[0003] It should be noted that the information disclosed in the above background art section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to those of ordinary skill in the art.
[0004] Content of the Application
[0005] In view of at least one of the above technical problems, this application provides an autofocus method, an infrared thermal imager, and a storage medium, which solve the problems that manual alignment of the lens with the target or selection of the position of the target in the image is required, and refocusing is required when the target moves or the lens moves, and the operation is cumbersome.
[0006] In a first aspect, this application provides an autofocus method, including the following steps:
[0007] Step S100: Obtain a temperature image and an infrared image, and determine the coordinate value of the target temperature according to the temperature image;
[0008] Step S200: Generate an infrared grayscale image according to the infrared image, and determine the focus area according to the infrared grayscale image and the coordinate value of the target temperature;
[0009] Step S300: Calculate the initial sharpness of the focus area;
[0010] Step S400: Control the focusing motor to rotate to make the lens step in the first direction, obtain the focused focus area, and calculate the focusing sharpness of the focused focus area;
[0011] Step S500: Determine whether the focusing sharpness is greater than the initial sharpness;
[0012] Step S600, if not, configure the value of the initial clarity as the value of the focused clarity, control the focusing motor to rotate to step the lens in the second direction, and decrement the iteration count by one;
[0013] Step S700, when the iteration count is not zero, execute Step S400 again until the iteration count is zero, then end the focusing.
[0014] One of the technical solutions in the above technical solutions has at least the following advantages or beneficial effects: This method can combine the temperature information in the temperature image, automatically obtain the focusing area, and then adjust the focal length position based on cyclic iteration, so as to make the image reach the clearest state.
[0015] In some alternative implementation manners, the second direction is opposite to the first direction.
[0016] In some alternative implementation manners, the distance for controlling the focusing motor to rotate to step the lens in the second direction is half of the distance for controlling the focusing motor to rotate to step the lens in the first direction.
[0017] In some alternative implementation manners, the initial value of the iteration count is an adjustable parameter and is pre-configured.
[0018] In some alternative implementation manners, the focusing area is a rectangular range, and the coordinates of the center point of the rectangle of the focusing area are the coordinate values of the target temperature.
[0019] In some alternative implementation manners, the calculation formula for the width of the focusing area is as follows:
[0020]
[0021] In the formula, w is the width of the focusing area, W is the width of the infrared image, and a is an adjustable parameter;
[0022] The calculation formula for the height of the focusing area is as follows:
[0023]
[0024] In the formula, h is the height of the focusing area, H is the height of the infrared image, and a is an adjustable parameter.
[0025] In some alternative implementation manners, calculating the initial clarity of the focusing area includes:
[0026] Obtain the image of the focusing area of the infrared image and convert the image of the focusing area into a grayscale image of the focusing area;
[0027] Use the Sobel algorithm to calculate the gradient image of the grayscale image of the focusing area, and the value of each pixel point of the gradient image represents the gradient magnitude of that pixel point;
[0028] Take the absolute value of the values of all pixel points in the gradient image and sum them up, and use the summation result as the initial clarity.
[0029] In some alternative implementation manners, after determining whether the focusing clarity is greater than the initial clarity, it further includes:
[0030] If so, configure the value of the initial clarity to the value of the focusing clarity, and execute step S400 again.
[0031] In a second aspect, the present application provides an infrared thermal imager, including: a computer-readable storage medium storing a computer program and a processor, and when the computer program is read and run by the processor, an autofocus method is implemented.
[0032] In a third aspect, the present application provides a computer-readable storage medium storing a computer program, and when the computer program is read and run by the processor, an autofocus method is implemented.
[0033] The following further describes the present application in conjunction with the drawings and embodiments. Description of the Drawings
[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required to be used in the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0035] Figure 1 It is a flowchart of the autofocus method provided by the embodiment of the present application; Detailed Embodiments
[0036] In order to make the above objects, features, and advantages of the present application more obvious and understandable, the following will describe the detailed embodiments of the present application in conjunction with the drawings. Many specific details are set forth in the following description in order to fully understand the present application. However, the present application can be implemented in many other ways different from those described herein. Those skilled in the art can make similar improvements without departing from the connotation of the present application. Therefore, the present application is not limited by the specific embodiments disclosed below.
[0037] Existing autofocus methods are divided into two types: laser ranging-based and image contrast-based. The laser ranging-based autofocus method measures the distance between the target and the lens to calculate the optimal focal length. The image contrast-based autofocus method calculates the image sharpness and iteratively controls the motor to find the position that makes the image the sharpest, thus achieving autofocus. When focusing on a specified target or an area of interest in temperature in the image, the existing methods require manual alignment of the lens to the target or selection of the position of the target in the image. When the target moves or the lens moves, refocusing is required, and the operation is cumbersome. This method can combine the temperature information in the temperature image, automatically obtain the focus area, and then adjust the focal length position based on cyclic iteration to make the image reach the sharpest state.
[0038] As Figure 1 shown, this embodiment provides an autofocus method, including the following steps: step S100 to step S700.
[0039] Step S100, obtain a temperature image and an infrared image, and determine the coordinate value of the target temperature according to the temperature image.
[0040] In step S100, the infrared thermal imager collects the temperature distribution data of the target area through the built-in infrared detector to generate a temperature image. The temperature image is stored in the form of a two-dimensional matrix, and each pixel point corresponds to a temperature value. At the same time, the infrared thermal imager collects the infrared radiation information of the target area through the infrared imaging module to generate an infrared image. The infrared image has a corresponding relationship with the temperature image in space.
[0041] Among them, the target temperature can be the highest temperature, the lowest temperature or the temperature target of interest in the temperature image.
[0042] Step S200, generate an infrared grayscale image according to the infrared image, and determine the focus area according to the infrared grayscale image and the coordinate value of the target temperature.
[0043] In step S200, an infrared grayscale image is generated from the infrared image, and the focus area is determined according to the infrared grayscale image and the coordinate value of the target temperature, so as to highlight the detail features.
[0044] It should be noted that the focus area is a rectangular range, and the coordinate of the center point of the rectangle of the focus area is the coordinate value of the target temperature.
[0045] The calculation formula for the width of the focus area is as follows:
[0046]
[0047] In the formula, w is the width of the focus area, W is the width of the infrared image, and a is an adjustable parameter;
[0048] The calculation formula for the height of the focus area is as follows:
[0049]
[0050] In the formula, h is the height of the focus area, H is the height of the infrared image, and a is an adjustable parameter.
[0051] Step S300, calculate the initial sharpness of the focus area.
[0052] Calculating the initial sharpness of the focus area may include: Step S310 to Step S330, specifically as follows:
[0053] Step S310, obtain the focus area image of the infrared image and convert the focus area image into a focus area grayscale image.
[0054] In Step S310, since the range of the focus area has been determined in Step S200, obtaining the image within this range in the infrared image is the focus area image. Subsequently, convert the focus area image into a focus area grayscale image.
[0055] Step S320, calculate the gradient image of the focus area grayscale image using the Sobel algorithm. The value of each pixel point in the gradient image represents the gradient magnitude of that pixel point.
[0056] In this Step S320, the Sobel algorithm is a classic image edge detection algorithm. Based on gradient calculation, it extracts the spatial grayscale change features in the image and is widely used in fields such as image sharpness evaluation and contour extraction. In the autofocus scenario of an infrared thermal imager, the Sobel algorithm is used to calculate the gradient values of the focus area grayscale image, thereby evaluating the image sharpness. In addition, the Sobel algorithm only requires simple convolution and summation operations, which is suitable for resource-constrained scenarios such as embedded systems and meets the real-time autofocus requirements of infrared thermal imagers. Moreover, the Sobel algorithm has a strong response to edges in both horizontal and vertical directions, can effectively characterize the sharpness of image details, and thus improve the accuracy of sharpness evaluation. At the same time, compared with other edge detection operators (such as Prewitt), the weights of the middle row / column in the Sobel kernel are larger, which can smooth some noise interference.
[0057] Step S330, take the absolute value of all pixel point values in the gradient image and sum them, and use the summation result as the initial sharpness.
[0058] Step S400, control the focus motor to rotate to make the lens step along the first direction, obtain the focused focus area, and calculate the focus sharpness of the focused focus area;
[0059] In step S400, the calculation method of the focusing clarity is the same as that of the initial clarity. For details, refer to the above steps S310 to S330.
[0060] Step S500: Determine whether the focusing clarity is greater than the initial clarity.
[0061] In step S500, by comparing the magnitudes of the adjusted clarity and the initial clarity, the clarity of the focusing area after focusing is further determined.
[0062] Step S600: If not, configure the value of the initial clarity as the value of the focusing clarity, control the focusing motor to rotate to make the lens step in the second direction, and decrement the iteration count by one.
[0063] In step S600, the second direction is opposite to the first direction. And the distance that the focusing motor is controlled to rotate to make the lens step in the second direction is half of the distance that the focusing motor is controlled to rotate to make the lens step in the first direction. The initial value of the iteration count is an adjustable parameter and is pre-configured.
[0064] Step S700: When the iteration count is not zero, execute step S400 again until the iteration count is zero, and then end the focusing.
[0065] As Figure 1 shown, for example, when the focusing clarity is less than the initial clarity, that is, after focusing, the focusing area becomes blurred. At this time, make the value of the initial clarity equal to the value of the focusing clarity, and then control the focusing motor to rotate to make the lens step in the second direction. At this time, the iteration count is decremented by one. When the iteration count is not zero, start to execute step S400 again until the iteration count is zero, and then end the focusing.
[0066] As Figure 1 shown, in some embodiments, after determining whether the focusing clarity is greater than the initial clarity, it further includes:
[0067] If so, configure the value of the initial clarity as the value of the focusing clarity, and execute step S400 again.
[0068] For example, when the focusing clarity is greater than the initial clarity, that is, after focusing, the focusing area becomes clear. At this time, make the value of the initial clarity equal to the value of the focusing clarity, and then re-execute step S400.
[0069] In a second aspect, the present application provides an infrared thermal imager, including: a computer-readable storage medium storing a computer program and a processor. When the computer program is read and run by the processor, the automatic focusing method is implemented.
[0070] In a third aspect, the present application provides a computer-readable storage medium storing a computer program which, when read and executed by a processor, implements the autofocus method.
[0071] Wherein, on the computer-readable storage medium, there is stored a computer program which, when executed by a processor, implements the autofocus method of the embodiments of the present application.
[0072] To implement the above embodiments, in an embodiment of one aspect of the present application, there is provided a computer program which, when executed by a processor, implements the autofocus method of the embodiments of the present application.
[0073] This embodiment may employ any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device.
[0074] The computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal may take various forms, including - but not limited to - an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device.
[0075] The program code contained on the computer-readable medium may be transmitted by any appropriate medium, including - but not limited to - wireless, wire, optical fiber, RF, etc., or any suitable combination of the above.
[0076] Computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's electronic device, partially on the user's electronic device, executed as an independent software package, partially on the user's electronic device and partially on a remote electronic device, or entirely on a remote electronic device or server. In the case of a remote electronic device, the remote electronic device can be connected to the user's electronic device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external electronic device (e.g., by connecting through the Internet using an Internet service provider).
[0077] In the description of the embodiments of this application, unless otherwise specified, " / " means "or". For example, A / B can mean A or B; "and / or" in this article is merely a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of this application, "a plurality of" means two or more than two.
[0078] In the description of the embodiments of this application, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features.
[0079] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been generally described according to their functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of this application.
[0080] The above are only the preferred embodiments of the present application and do not impose any formal restrictions on the present application. Any person skilled in the art can, without departing from the scope of the technical solution of the present application, make many possible changes and modifications to the technical solution of the present application by using the methods and technical contents disclosed above, or modify it into equivalent embodiments with equivalent changes. Therefore, all equivalent changes made according to the shape, structure and principle of the present application without departing from the content of the technical solution of the present application shall be covered by the protection scope of the present application.
Claims
1. An autofocus method, characterized in that, Including the following steps: Step S100: Obtain a temperature image and an infrared image, and determine the coordinate value of the target temperature according to the temperature image; Step S200: Generate an infrared grayscale image according to the infrared image, and determine the focus area according to the infrared grayscale image and the coordinate value of the target temperature; Step S300: Calculate the initial sharpness of the focus area; Step S400: Control the focusing motor to rotate to make the lens step in the first direction, obtain the focused focus area, and calculate the focusing sharpness of the focused focus area; Step S500: Determine whether the focusing sharpness is greater than the initial sharpness; Step S600: If not, configure the value of the initial sharpness as the value of the focusing sharpness, control the focusing motor to rotate to make the lens step in the second direction, and decrement the iteration count by one; Step S700: When the iteration count is not zero, execute Step S400 again until the iteration count is zero, and then end the focusing.
2. The autofocus method according to claim 1, wherein The second direction is opposite to the first direction.
3. The autofocus method according to claim 1, wherein The distance that the focusing motor is controlled to rotate to make the lens step in the second direction is half of the distance that the focusing motor is controlled to rotate to make the lens step in the first direction.
4. The autofocus method according to claim 1, wherein The initial value of the iteration count is an adjustable parameter and is pre-configured.
5. The autofocus method according to claim 1, wherein The focus area is a rectangular range, and the coordinates of the center point of the rectangle of the focus area are the coordinate values of the target temperature.
6. The autofocus method according to claim 5, characterized in that The calculation formula for the width of the focus area is as follows: In the formula, w is the width of the focus area, W is the width of the infrared image, and a is an adjustable parameter; The calculation formula for the height of the focus area is as follows: In the formula, h is the height of the focus area, H is the height of the infrared image, and a is an adjustable parameter.
7. The autofocus method according to claim 1, wherein The calculation of the initial sharpness of the focus area includes: Obtain the focus area image of the infrared image, and convert the focus area image into a focus area grayscale image; Use the Sobel algorithm to calculate the gradient image of the focus area grayscale image, and the value of each pixel point in the gradient image represents the gradient magnitude of the pixel point; Take the absolute value of all pixel point values in the gradient image and sum them, and use the summation result as the initial sharpness.
8. The autofocus method according to claim 1, characterized in that, After determining whether the focusing sharpness is greater than the initial sharpness, it further includes: If so, configure the value of the initial sharpness as the value of the focusing sharpness, and execute Step S400 again.
9. An infrared thermal imager, characterized in that, Including: A computer-readable storage medium storing a computer program and a processor, when the computer program is read and run by the processor, implementing the automatic focusing method according to any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, when the computer program is read and run by the processor, implementing the automatic focusing method according to any one of claims 1-8.
Citation Information
Cited By
Image acquisition method and related device
CN121567956A