Focusing method, device and medium of lens module
By using stepping movement and pixel mean calculation methods in the lens module, the problem of error in traditional focusing algorithms in small image sensors is solved, and the accurate focus and efficient adaptability of the lens module are achieved.
Patent Information
- Application Number
- CN202211591538.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-12
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2042-12-12
AI Technical Summary
Traditional focus algorithms have errors in the field of image sensors with sizes below 200x200, resulting in the inability to focus correctly, mainly due to the small number of effective pixels and the easy occurrence of bad points or stains during the assembly process of the lens module, which interferes with too much data.
By controlling the lens module to move in step mode, the target image is taken and the focus reference image after each step is recorded, the average pixel value of the dark area and the bright area and its difference are calculated, and the position at which the absolute value is the best is determined as the maximum Focus position, reduce calculation amount and eliminate stain interference.
It realizes accurate focus of the lens module, is suitable for modules with good performance and many bad points, improves focus efficiency and adaptability, and can adapt to image sensors of different models and specifications.
Smart Images

Figure CN115883965B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image sensors, and in particular to a focusing method, device and medium of a lens module. Background Art
[0002] There are many types of traditional focusing algorithms, but they are not suitable for mass production testing of image sensors with a size below 200x200. Because sensors with a size below 200x200 have a small number of effective pixels, once the sensor itself has bad pixels, the lens is contaminated, or the lens module is mixed with dust particles during the assembly process, the proportion of error pixels will be too high. In extreme cases, the proportion of error pixels can reach more than 30%. In this case, because there is too much interference data and too little effective data, traditional focusing algorithms are prone to errors, resulting in inability to focus correctly. Therefore, a new focusing method, device and medium for lens modules are urgently needed to improve the above problems. Summary of the invention
[0003] The object of the present invention is to provide a focusing method, device and medium for a lens module, wherein the method is used to achieve accurate focusing of the lens module.
[0004] In a first aspect, the present invention provides a focusing method for a lens module, comprising: controlling the lens module to move in a stepwise manner, capturing a target image and recording a focus reference image corresponding to a travel position of the lens module after each stepping movement; calculating a dark area pixel mean and a bright area pixel mean of each recorded focus reference image; and an absolute value of a difference between the dark area pixel mean and the bright area pixel mean; determining the travel position corresponding to the focus reference image when the absolute value is the largest as an optimal focus position; and controlling the lens module to move to the optimal focus position.
[0005] The method of the present invention has the following beneficial effects: the present invention controls the lens module to move in a step-by-step manner, captures the target image and records the focus reference image corresponding to the stroke position of the lens module after each step-by-step movement; calculates the dark area pixel average and the bright area pixel average of each recorded focus reference image; and the absolute value of the difference between the dark area pixel average and the bright area pixel average; the focusing method of the present invention can eliminate the influence of the spot focus result, which is beneficial to reduce the amount of calculation and improve the focusing efficiency. The present invention determines that the stroke position corresponding to the focus reference image when the absolute value is the maximum is the optimal focus position; and controls the lens module to move to the optimal focus position. The focusing method of the present invention facilitates real-time judgment of the quality of the lens module focus according to the size of the absolute value, and can find the optimal focal length of the lens module focus.
[0006] Optionally, after recording the focus reference image, it also includes: extracting pixel values of the focus reference image to form a first array; taking pixel values in the first array whose values are within a first threshold to form a second array; the second array is used to characterize the pixel values of the bright area; taking pixel values in the first array whose values are within a second threshold to form a third array; the third array is used to characterize the pixel values of the dark area; the minimum value of the first threshold is greater than the maximum value of the second threshold.
[0007] Optionally, the formation of the second array and the third array also includes: deleting the pixel values within the domain value of bright bad dots and the pixel values within the domain value of dark bad dots in the first array to generate a fourth array; sorting the fourth array by size to generate a fifth array; taking the pixel values within the first threshold value in the fifth array to form the second array; taking the pixel values within the second threshold value in the fifth array to form the third array. The beneficial effect is that the focusing method of the present application eliminates the pixel values corresponding to dark bad dots and bright bad dots by deleting the pixel values that take the minimum value and the maximum value in the first array, which is conducive to avoiding the bad pixel values interfering with the focus, and makes the present application not only applicable to the normal focus of modules with good performance, but also applicable to modules with many bad dots and stains.
[0008] Optionally, taking pixel values in the fifth array whose values are within a first threshold to form a second array includes: obtaining the number of pixel values contained in the fifth array; calculating a first sample number based on the number of pixel values; taking several pixel values with the largest values from the fifth array to form a second array; the number of pixel values in the second array is the first sample number; taking pixel values in the fifth array whose values are within a second threshold to form a third array includes: taking several pixel values with the smallest values from the fifth array to form a third array; the number of pixel values in the third array is the first sample number.
[0009] Optionally, calculating the mean pixel value of the bright area includes: calculating the second sample number according to the first sample number; taking the pixel value in the middle of the second array to form a sixth array; the number of prime values in the sixth array is the second sample number; calculating the first average value according to the sixth array; calculating the third threshold according to the first average value; taking the pixel value in the second array within the third threshold to calculate the mean pixel value of the bright area. Its beneficial effect is that the present invention calculates the third threshold by using the first average value to further filter the interference point pixels, making the focusing method of the present invention more adaptable. At the same time, the present invention uses the first average value to calculate the third threshold, even if there are individual differences between different image sensors, even image sensors of completely different models and specifications can achieve focusing, and there is no need to change the parameters when calculating the third threshold from the first average value, which is convenient for simplifying the test steps and improving production efficiency.
[0010] Optionally, calculating the mean pixel value of the dark area includes: taking the pixel values in the middle of the third array to form a seventh array; the number of prime values in the seventh array is the second sample number; calculating the second average value based on the seventh array; calculating the fourth threshold value based on the second average value; taking the pixel values in the third array that are within the fourth threshold value to calculate the mean pixel value of the dark area.
[0011] Optionally, determining that the travel position corresponding to the focus reference image when the absolute value is the largest is the optimal focus position includes: comparing the absolute value calculated before the lens module moves with the absolute value calculated after the lens module moves; when the prior absolute value is larger, controlling the lens module to continue to step along the direction of the last step movement; when the subsequent absolute value is larger, controlling the lens module to step in the opposite direction of the last step movement.
[0012] Optionally, before controlling the lens module to photograph the reference object, the method further includes: before controlling the lens module to photograph the target image for the first time, resetting the focal length of the lens module to an initial focal length.
[0013] In a second aspect, the present invention provides a focusing device for a lens module, which is used for the method described in any one of the first aspects, and includes: a lens module, a focusing module, a storage module and a processing module; the lens module is electrically connected to the processing module, and is used to capture a target image according to the instructions of the processing module and record a focus reference image corresponding to the stroke position of the lens module after each step movement; the focusing module is electrically connected to the processing module, and is used to drive the lens module to move in a step-by-step manner according to the instructions of the processing module; the processing module is used to calculate the dark area pixel mean and the bright area pixel mean of each recorded focus reference image; and the absolute value of the difference between the dark area pixel mean and the bright area pixel mean; determine that the stroke position corresponding to the focus reference image when the absolute value is the largest is the optimal focus position; control the lens module to move to the optimal focus position; the storage module is used to store the stroke position of the lens module after each step movement, the focus reference image corresponding to the stroke position after each step movement, and the absolute value calculated before each step movement.
[0014] Optionally, the focusing module includes a motor; when the motor rotates forward during operation, it is used to drive the lens module closer to the target image; when the motor rotates reversely during operation, it is used to drive the lens module away from the target image.
[0015] In a third aspect, the present invention provides a readable storage medium, wherein the readable storage medium stores a program, and when the program is executed, it implements any possible design method of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A schematic diagram of a flow chart of a focusing method of a lens module provided by the present invention;
[0017] Figure 2 A focus reference image taken by a lens module facing a reference object provided by the present invention;
[0018] Figure 3 A schematic structural diagram of a focusing device of a lens module provided by the present invention.
[0019] Numbers in the figure:
[0020] 10. Focusing device; 11. Lens module; 12. Processing module; 13. Storage module; 14. Focusing module. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solutions and advantages of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used herein should be understood by people with general skills in the field to which the present invention belongs. "Including" and similar words used in this article mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects.
[0022] Figure 1 A schematic flow chart of a focusing method for a lens module provided by the present invention.
[0023] In view of the problems existing in the existing technology, such as Figure 1 As shown, the present invention provides a focusing method for a lens module, comprising:
[0024] S101, controlling the lens module to move in a stepping manner, capturing a target image and recording a focus reference image corresponding to a stroke position of the lens module after each stepping movement.
[0025] S102, calculating the mean value of pixels in the dark area and the mean value of pixels in the bright area of each recorded focus reference image, and the absolute value of the difference between the mean value of pixels in the dark area and the mean value of pixels in the bright area.
[0026] S103, determining the stroke position corresponding to the focus reference image when the absolute value is the maximum as the best focus position, and controlling the lens module to move to the best focus position.
[0027] Figure 2 A focus reference image is taken by a lens module toward a reference object provided by the present invention.
[0028] Specifically, Figure 2 As shown, the target image can be a black and white grid image.
[0029] In some other embodiments, the target image may be a black and white stripe pattern.
[0030] In some other embodiments, the target image may also be any image that is fully mixed in black and white. The image that is fully mixed in black and white includes but is not limited to a black and white grid image and a black and white stripe image; when the width of the color block and the stripe are the same, the black and white mixing degree of the black and white grid image is higher than the black and white mixing degree of the black and white stripe image; the higher the black and white mixing degree is, the more conducive it is to obtaining an accurate focusing result.
[0031] Exemplarily, the pixel values corresponding to the dark areas in this embodiment are the smallest a pixel values among all the pixel values in the focus reference image; the pixel values corresponding to the bright areas in this embodiment are the largest a pixel values among all the pixel values in the focus reference image; a is the value obtained by rounding off 0.2 times the number of all pixels in the focus reference image.
[0032] It is worth noting that the present invention controls the lens module to move in a step-by-step manner, captures the target image and records the focus reference image corresponding to the stroke position of the lens module after each step-by-step movement. Calculate the dark area pixel mean and the bright area pixel mean of each recorded focus reference image. And the absolute value of the difference between the dark area pixel mean and the bright area pixel mean. The focusing method of the present invention can eliminate the influence of the stain focus result, which is beneficial to reduce the amount of calculation and improve the focusing efficiency. The present invention determines that the stroke position corresponding to the focus reference image when the absolute value is the maximum is the optimal focus position. Control the lens module to move to the optimal focus position. The focusing method of the present invention is convenient for judging the quality of the lens module focus in real time according to the size of the absolute value, and can find the optimal focal length of the lens module focus.
[0033] In some embodiments, after recording the focus reference image, it also includes: extracting pixel values of the focus reference image to form a first array; taking pixel values in the first array whose values are within a first threshold to form a second array; the second array is used to characterize the pixel values of the bright area; taking pixel values in the first array whose values are within a second threshold to form a third array; the third array is used to characterize the pixel values of the dark area; the minimum value of the first threshold is greater than the maximum value of the second threshold.
[0034] Specifically, the first array A1 includes all pixel values of the focus reference image. The focus reference image is obtained by photographing an 8-bit image sensor, the maximum pixel value in the focus reference image is 255, and the minimum pixel value in the focus reference image is 0. The minimum value of the first threshold is 245; the maximum value of the second threshold is 10.
[0035] It is worth noting that the focus reference image can be obtained by taking an n-bit image sensor, where n is any positive integer greater than 3, and the maximum pixel value in the focus reference image is 2. n -1, the minimum pixel value in the focus reference image is 0. The minimum value of the first threshold can be 2 n -11; the maximum value of the second threshold may be 10.
[0036] In some embodiments, the formation of the second array and the third array also includes: deleting the pixel values within the domain value of bright bad dots and the pixel values within the domain value of dark bad dots in the first array to generate a fourth array; sorting the fourth array by size to generate a fifth array; taking the pixel values within the first threshold value in the fifth array to form the second array; taking the pixel values within the second threshold value in the fifth array to form the third array. The focusing method of the present application eliminates the pixel values corresponding to dark bad dots and bright bad dots by deleting the pixel values that take the minimum value and the maximum value in the first array, which is beneficial to avoid the bad pixel values interfering with the focus, and makes the present application not only applicable to the normal focus of modules with good performance, but also applicable to modules with many bad dots and stains.
[0037] Specifically, the pixel values of [0, 10] and [245, 255] in the first array A1 are deleted to generate a fourth array A2. The pixel values in the fourth array A2 are arranged in ascending order to generate a fifth array A3. The pixel values in the fifth array A3 whose values are within the first threshold are taken to form a second array B1. The pixel values in the fifth array A2 whose values are within the second threshold are taken to form a third array B2. The first threshold is set to [179, 255]; the second threshold is set to [0, 76].
[0038] In some other embodiments, the first array A1 may be deleted from [0, 31] and [2 n -31,2 n -1], where n is any positive integer greater than 4, to generate a fourth array A2. The pixel values in the fourth array A2 can also be arranged in descending order to generate a fifth array A3. The pixel values in the fifth array A3 are taken to be between [2 n-1 -1, 2 n The pixel values in the fifth array are taken to form the second array B1. n-1 -1] to form the third array B2.
[0039] In some embodiments, selecting pixel values in the fifth array whose values are within the first threshold to form a second array includes: obtaining the number of pixel values contained in the fifth array. Calculating a first sample number based on the number of pixel values. Taking a number of pixel values with the largest values from the fifth array to form a second array. The number of pixel values in the second array is the first sample number. Taking pixel values in the fifth array whose values are within the second threshold to form a third array includes: taking a number of pixel values with the smallest values from the fifth array to form a third array. The number of pixel values in the third array is the first sample number.
[0040] Specifically, selecting pixel values in the fifth array A3 whose values are within the first threshold to form the second array B1 includes: obtaining the number i of pixel values included in the fifth array A3. Calculating a first sample number j according to the number i of pixel values. The first sample number j is a value obtained by rounding 0.3 times the number i of pixel values.
[0041] A plurality of pixel values with the largest values are selected from the fifth array to form a second array B1. The number of pixel values in the second array B1 is the first sample number j, and pixel values with values within the second threshold are selected from the fifth array A3 to form a third array B2. The number of pixel values in the third array B2 is the first sample number j.
[0042] In some other embodiments, the pixel values in the fifth array A3 whose values are within the first threshold are taken to form the second array B1, and n is any positive integer. The first sample number j only needs to satisfy that j is less than the number i of pixel values included in the fifth array A3.
[0043] In some embodiments, calculating the mean pixel value of the bright area includes: calculating the second sample number according to the first sample number. Taking the pixel value in the middle of the second array to form a sixth array. Calculating the first average value according to the sixth array. Calculating the third threshold according to the first average value. Taking the pixel values in the second array that are within the third threshold value to calculate the mean pixel value of the bright area. The present invention calculates the third threshold value through the first average value to further filter the interference point pixels, so that the focusing method of the present invention is more adaptable. At the same time, the present invention uses the first average value to calculate the third threshold value. Even if there are individual differences between different image sensors, even image sensors of completely different models and specifications can achieve focusing, there is no need to change the parameters when calculating the third threshold value from the first average value, which is convenient for simplifying the test steps and improving production efficiency.
[0044] Specifically, the second sample number k is calculated according to the first sample number j. The second sample number k is a value obtained by rounding 0.2 times the first sample number j.
[0045] Take the k pixel values in the middle of the second array B1 to form a sixth array B3. Calculate the first average value avg1 according to the sixth array B3. Calculate the third threshold interval [x1, x2] according to the first average value avg1, where x1 is the value obtained by rounding 0.8 times the first average value avg1; x2 is the value obtained by rounding 1.2 times the first average value avg1. Take the pixel values in the second array B1 that are within the third threshold interval, and calculate the average value, which is the bright area pixel average avg2.
[0046] In some other embodiments, for the second sample number k, it only needs to satisfy that k is less than the first sample number j. For the third threshold interval [m1, m2], it only needs to satisfy that the minimum value m1 of the third threshold interval is less than the first average value avg1, and the maximum value m2 of the third threshold interval is greater than the first average value avg1.
[0047] In some embodiments, calculating the mean pixel value of the dark area includes: taking pixel values in the middle of the third array to form a seventh array. Calculating a second mean value based on the seventh array. Calculating a fourth threshold based on the second mean value. Taking pixel values in the third array that are within the fourth threshold to calculate the mean pixel value of the dark area.
[0048] Specifically, k pixel values in the middle of the third array B2 are taken to form a seventh array B4. The second average value avg3 is calculated based on the seventh array B4. The fourth threshold [y1, y2] is calculated based on the second average value avg3, wherein y1 is a value obtained by rounding 0.8 times the second average value avg3; y2 is a value obtained by rounding 1.2 times the second average value avg3. The pixel values in the third array B2 that are within the fourth threshold are taken, and the calculated average is the dark area pixel average avg4.
[0049] It is worth noting that, in some other embodiments, for the second sample number k, it only needs to satisfy that k is less than the first sample number j. For the fourth threshold interval [m3, m4], it only needs to satisfy that the minimum value m3 of the fourth threshold interval is less than the second average value avg3, and the maximum value m3 of the fourth threshold interval is greater than the second average value avg3.
[0050] In some embodiments, determining that the stroke position corresponding to the focus reference image when the absolute value is the maximum is the optimal focus position includes: comparing the absolute value calculated before the lens module moves with the absolute value calculated after the lens module moves. When the former absolute value is greater, the lens module is controlled to continue to move in a stepwise manner in the direction of the last stepping movement. When the latter absolute value is greater, the lens module is controlled to move in a stepwise manner in the opposite direction of the last stepping movement.
[0051] Specifically, the distance of each step movement of the lens module is half of the distance of the last step movement. This setting is conducive to efficiently finding the best focus position.
[0052] In other embodiments, the distance of each step movement of the lens module is smaller than the distance of the last step movement.
[0053] In some embodiments, before controlling the lens module to photograph a reference object, the method further includes: before controlling the lens module to photograph a target image for the first time, resetting the focal length of the lens module to an initial focal length.
[0054] Specifically, resetting the focal length of the lens module to an initial focal length is configured to control the lens module to move to a preset stroke position.
[0055] In some other specific embodiments, the focal length of the lens module is reset to the initial focal length to control the lens module to move to the best focusing position at the last focusing.
[0056] The present invention provides a readable storage medium, wherein a program is stored in the readable storage medium, and when the program is executed, any possible design method in the above-mentioned embodiments is implemented.
[0057] It is worth noting that if the method is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling an electronic device to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk.
[0058] Figure 3 A schematic structural diagram of a focusing device of a lens module provided by the present invention.
[0059] like Figure 3 As shown, the present invention provides a focusing device for a lens module, which is used in any of the methods described in the above embodiments, and includes: a lens module 11, a focusing module 14, a storage module 13, and a processing module 12. The lens module 11 is electrically connected to the processing module 12, and is used to capture a target image according to the instructions of the processing module 12 and record a focus reference image corresponding to the stroke position of the lens module 11 after each step movement. The focusing module 14 is electrically connected to the processing module 12, and is used to control the lens module 11 to move in a step-by-step manner according to the instructions of the processing module 12. The processing module 12 is used to calculate the mean pixel value of the dark area and the mean pixel value of the bright area of each recorded focus reference image. And the absolute value of the difference between the mean pixel value of the dark area and the mean pixel value of the bright area. Determine that the stroke position corresponding to the focus reference image when the absolute value is the largest is the best focus position. Control the lens module 11 to move to the best focus position. The storage module 13 is used to store the stroke position of the lens module 11 after each stepping movement, the focus reference image corresponding to the stroke position after each stepping movement, and the absolute value calculated before each stepping movement.
[0060] Specifically, the lens module 11 is configured as an image sensor or an image sensor chip, the storage module 13 is configured as a memory, and the processing module 12 is configured as a processor.
[0061] It can be understood that the memory in this embodiment can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DR RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0062] It should be noted that the processor in this embodiment can be an image processing chip or an integrated circuit chip, which has the ability to process image signals. In the implementation process, each step of the above method embodiment can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above processor can be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in this embodiment can be implemented or executed.
[0063] In some embodiments, the focusing module 14 includes a motor. When the motor rotates forward during operation, it is used to drive the lens module 11 to approach the target image. When the motor rotates reversely during operation, it is used to drive the lens module 11 to move away from the target image.
[0064] In some other embodiments, when the motor is working, it is used to drive the lens module 11 to approach the target image when it rotates in the reverse direction. When the motor is working, it is used to drive the lens module 11 to move away from the target image when it rotates in the forward direction.
[0065] In some other embodiments, the motors may be provided in two numbers, one of which is used to drive the lens module 11 to approach the target image, and the other of which is used to drive the lens module 11 to move away from the target image.
[0066] Although the embodiments of the present invention are described in detail above, it is obvious to those skilled in the art that various modifications and variations can be made to these embodiments. However, it should be understood that such modifications and variations are within the scope and spirit of the present invention as described in the claims. Moreover, the present invention described herein may have other embodiments and may be implemented or realized in a variety of ways.
Claims
1. A focusing method for a lens module, characterized in that: include: Control the lens module to move in a stepping manner, capture the target image and record the focus reference image corresponding to the travel position of the lens module after each stepping movement; Extracting pixel values of the focus reference image to form a first array; deleting pixel values within the bright bad point domain value and pixel values within the dark bad point domain value in the first array to generate a fourth array; sorting the fourth array by size to generate a fifth array; Obtain the number of pixel values contained in the fifth array; calculate the first sample number according to the number of pixel values; take a number of pixel values with the largest values from the fifth array to form a second array; the number of pixel values in the second array is the first sample number; the second array is used to represent the pixel values of the bright area; Taking a number of pixel values with the smallest values from the fifth array to form a third array; the number of pixel values in the third array is the number of the first samples; the third array is used to represent the pixel values of the dark area; The values in the second array are within a first threshold, and the values in the third array are within a second threshold; the minimum value of the first threshold is greater than the maximum value of the second threshold; Calculate the mean value of pixels in the dark area and the mean value of pixels in the bright area of each recorded focus reference image; and the absolute value of the difference between the mean pixel value of the dark area and the mean pixel value of the bright area; Determine the stroke position corresponding to the focus reference image when the absolute value is the maximum as the optimal focus position; Control the lens module to move to the optimal focus position.
2. The method according to claim 1, characterized in that Calculating the mean value of pixels in the bright area includes: Calculate the second sample number based on the first sample number; take the pixel value in the middle of the second array to form a sixth array; the number of prime values in the sixth array is the second sample number; calculate the first average value based on the sixth array; calculate the third threshold value based on the first average value; take the pixel values in the second array that are within the third threshold value to calculate the pixel mean of the bright area.
3. The method according to claim 2, characterized in that Calculating the mean value of pixels in the dark area includes: The pixel values in the middle of the third array are taken to form a seventh array; the number of prime values in the seventh array is the second sample number; a second average value is calculated based on the seventh array; a fourth threshold is calculated based on the second average value; and pixel values in the third array that are within the fourth threshold are taken to calculate the dark area pixel mean.
4. The method according to claim 1, characterized in that Determining the travel position corresponding to the focus reference image when the absolute value is the maximum as the optimal focus position includes: Compare the absolute value calculated before the lens module moves with the absolute value calculated after the lens module moves; when the former absolute value is larger, control the lens module to continue to move in the direction of the last step movement; when the latter absolute value is larger, control the lens module to move in the opposite direction of the last step movement.
5. The method according to claim 1, characterized in that Also includes: Before controlling the lens module to capture a target image for the first time, the focal length of the lens module is reset to an initial focal length.
6. A focusing device for a lens module, used in the method according to any one of claims 1 to 5, characterized in that: include: Lens module, focusing module, storage module and processing module; The lens module is electrically connected to the processing module, and is used to capture a target image according to an instruction of the processing module and record a focus reference image corresponding to a stroke position of the lens module after each stepping movement; The focusing module is electrically connected to the processing module, and is used to drive the lens module to move in a step-by-step manner according to the instructions of the processing module; The processing module is used to calculate the mean value of pixels in the dark area and the mean value of pixels in the bright area of each recorded focus reference image; and the absolute value of the difference between the mean pixel value of the dark area and the mean pixel value of the bright area; determining the stroke position corresponding to the focus reference image when the absolute value is the maximum as the best focus position; and controlling the lens module to move to the best focus position; The storage module is used to store the stroke position of the lens module after each stepping movement, the focus reference image corresponding to the stroke position after each stepping movement, and the absolute value calculated before each stepping movement.
7. A readable storage medium, wherein a program is stored in the readable storage medium, characterized in that: When the program is executed, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Automatic focusing control system and control method for lens module based on MTF (Modulation Transfer Function)
CN114666485A
Focusing method, electronic device, and computer readable storage medium
WO2020259179A1
