Autofocus method, electronic device, and storage medium

By calculating the center displacement of the light spot and matching the motor position, fast and stable autofocus is achieved, solving the problems of long time consumption and poor compatibility in existing technologies, and is applicable to a variety of camera types.

CN121174041BActive Publication Date: 2026-04-17SHENZHEN ANGSTROM EXCELLENCE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN ANGSTROM EXCELLENCE TECH CO LTD
Filing Date
2025-11-19
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing autofocus methods are time-consuming, noise-sensitive, and have poor stability, and are incompatible with area scan cameras and line scan cameras.

Method used

By identifying light spots in images captured by the camera, calculating the displacement of the center position of the light spot area, and using a calibration database or motor position matching model to determine the motor focusing position, automatic focusing of a single frame image is achieved.

Benefits of technology

It improves focusing speed from seconds to milliseconds, enhances robustness to image noise and spot morphology changes, and is compatible with traditional area scan and high-speed line scan cameras.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121174041B_ABST
    Figure CN121174041B_ABST
Patent Text Reader

Abstract

The application provides an automatic focusing method, an electronic device and a storage medium. The method comprises the following steps: obtaining a first light spot area and a second light spot area by performing light spot identification on a first image collected by a camera; calculating a displacement of a center position of the first light spot area and a center position of the second light spot area in a horizontal direction according to the first light spot area and the second light spot area; performing motor position matching according to the displacement to obtain a motor focusing position matched with the displacement, and driving the motor to the motor focusing position to complete automatic focusing. The above method can be compatible with automatic focusing of traditional area array cameras and high-speed linear array cameras; the automatic focusing process can be completed by using only a single frame of image, the focusing speed is improved, the focusing process can be reduced from seconds to milliseconds, and the device throughput is improved; the calculation of the light spot center displacement adopts a single-dimensional displacement feature in the horizontal direction, and the robustness to image noise and light spot shape change can be enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of camera technology, and more particularly to an autofocus method, electronic device, and storage medium. Background Technology

[0002] Online autofocus (AF) technology is one of the core technologies in machine vision, microscopic imaging, semiconductor inspection, and optical measurement. Its purpose is to adjust the position of motors in the optical system to achieve the clearest image of the observed object on the image sensor, enabling fast, accurate, and stable autofocus, which improves equipment efficiency and measurement accuracy. Currently, most existing autofocus methods are based on the sharpness function evaluation method. This method requires controlling a motor to move the lens or sample stage along the optical axis (Z-axis) stepwise from a starting position to an ending position, acquiring multiple frames. At each motor position, a pause is made and one frame is acquired. A specific sharpness evaluation function is used to calculate the sharpness evaluation value of that frame. All motor positions and their corresponding sharpness evaluation values ​​are fitted into a sharpness evaluation curve. By searching for the extreme points of this curve, the motor position corresponding to the extreme points is determined as the optimal focusing position. Such methods generally have the following drawbacks: they require multiple frames of imaging for traversal, which is time-consuming; the sharpness evaluation is sensitive to image noise, and the searched extreme points are prone to shift, making it impossible to ensure stability; they are affected by factors such as hardware vibration and changes in image texture, resulting in large errors in repeated positioning results; and they can only be applied to the optical systems of area scan cameras, and are not compatible with the optical systems of line scan cameras. Summary of the Invention

[0003] In view of this, embodiments of this application provide an autofocus method, electronic device, and storage medium, aiming to solve one of the problems of the prior art, such as long time consumption, noise sensitivity, poor stability, poor repeatability, and incompatibility with area scan cameras and line scan cameras.

[0004] A first aspect of this application provides an autofocus method, comprising: performing spot recognition on a first image captured by a camera to obtain a first spot region and a second spot region; calculating the horizontal displacement between the center position of the first spot region and the center position of the second spot region based on the first spot region and the second spot region; performing motor position matching based on the displacement to obtain a motor focusing position matching the displacement; and driving the motor to the motor focusing position to complete autofocus.

[0005] In one possible implementation, the step of performing spot recognition on the first image to obtain the first spot region and the second spot region includes: performing binarization processing on the first image to obtain a binary image corresponding to the first image; and using a preset matching template to match and locate the binary image to obtain the first spot region and the second spot region from the binary image.

[0006] In one possible implementation, before calculating the horizontal displacement between the center positions of the first and second light spot regions based on the first and second light spot regions, the method further includes: calculating the coordinates of the arithmetic mean center of the first light spot region as the first center position coordinates corresponding to the first light spot region, and calculating the coordinates of the arithmetic mean center of the second light spot region as the second center position coordinates corresponding to the second light spot region; or calculating the coordinates of the geometric center of the connected domain of the first light spot region as the first center position coordinates corresponding to the first light spot region, and calculating the coordinates of the geometric center of the connected domain of the second light spot region as the second center position coordinates corresponding to the second light spot region; or calculating the coordinates of the Gaussian fitting center of the first light spot region as the first center position coordinates corresponding to the first light spot region, and calculating the coordinates of the Gaussian fitting center of the second light spot region as the second center position coordinates corresponding to the second light spot region.

[0007] In one possible implementation, the step of calculating the horizontal displacement between the center positions of the first and second light spot regions based on the first and second light spot regions includes: calculating the difference between the horizontal coordinate values ​​in the coordinates of the first and second center positions, and determining the absolute value of the difference as the horizontal displacement between the center positions of the first and second light spot regions.

[0008] In one possible implementation, a preset calibration database is queried based on the displacement, and a motor focusing position matching the displacement is obtained based on the calibration data pre-stored in the calibration database. The calibration data includes a mapping relationship between the calibration displacement and the calibration motor position and / or a mapping relationship between the calibration displacement curve and the calibration motor position. Alternatively, the displacement is input into a preset motor position matching model for position matching, and a motor focusing position matching the displacement is output.

[0009] In one possible implementation, the method further includes performing a moving average filtering process on the calibration data pre-stored in the calibration database.

[0010] In one possible implementation, if the camera is a line scan camera, and the first image is a sequence of row images continuously acquired by the line scan camera, the method further includes: performing spot recognition on each row image in the row image sequence to obtain a first spot region and a second spot region corresponding to each row image; calculating the horizontal displacement between the center position of the first spot region and the center position of the second spot region based on the first spot region and the second spot region corresponding to each row image; performing curve plotting on the calculated displacement corresponding to each row image in the row image sequence to obtain a displacement curve; performing motor position matching based on the displacement curve to obtain a motor focusing position matching the displacement curve; and driving the motor to the motor focusing position to complete autofocus.

[0011] In one possible implementation, before the step of performing spot recognition on the first image acquired by the camera, the method further includes: performing image preprocessing on the first image, wherein the image preprocessing includes downsampling and / or filtering.

[0012] A third aspect of this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the electronic device, wherein the processor executes the computer program to implement the steps of the autofocus method provided in the first aspect.

[0013] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the autofocus method provided in the first aspect.

[0014] The fifth aspect of this application provides a computer program product that, when run on an electronic device, causes the electronic device to execute the steps of the autofocus method provided in the first aspect.

[0015] The autofocus method, electronic device, and storage medium provided in this application have the following beneficial effects:

[0016] By performing spot recognition on the first image captured by the camera, a first spot region and a second spot region are obtained. Based on the first and second spot regions, the horizontal displacement between the center positions of the first and second spot regions is calculated. The motor position is matched based on the displacement to obtain the motor focusing position that matches the displacement, and the motor is driven to the motor focusing position. This autofocus process is compatible with the autofocus of traditional area scan cameras and high-speed line scan cameras. Moreover, the autofocus process can be completed with only a single frame image, which improves the focusing speed and reduces the focusing process from seconds to milliseconds, thereby increasing the device throughput. By using a single-dimensional displacement feature in the horizontal direction to calculate the spot center displacement, the robustness to image noise and changes in spot shape can be enhanced. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a flowchart illustrating the implementation of an autofocus method provided in an embodiment of this application.

[0019] Figure 2 This is a flowchart of a method for obtaining a first spot region and a second spot region in the autofocus method provided in the embodiments of this application.

[0020] Figure 3 This is a flowchart illustrating another implementation of the autofocus method provided in the embodiments of this application.

[0021] Figure 4 This is a basic structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0022] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of this application with unnecessary detail.

[0023] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.

[0024] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0025] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."

[0026] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0027] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized. "A plurality" means "two or more."

[0028] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0029] This application aims to provide an autofocus method based on the mapping of spot center displacement and motor position, which eliminates the need for sharpness evaluation, traversal scanning, and single-frame image for focusing. This method achieves a focusing speed of <50 milliseconds (ms), a repeatability accuracy of <±1 micrometer (µm), and compatibility with autofocus of traditional area scan cameras and high-speed line scan cameras.

[0030] The autofocus method provided in this application can be applied to semiconductor manufacturing and inspection technology scenarios such as wafer defect detection, lithography machine autofocus, and chip bonding alignment; microscopy and medical imaging scenarios such as digital pathological slide scanning, cell microscopy imaging, and endoscope focusing; machine vision and industrial automation technology scenarios such as precision part size measurement, LCD / OLED panel inspection, and QR code / barcode recognition; optical measurement instrument technology scenarios such as rapid focusing of laser confocal sensors, spectrometers, and optical profilometers; and electronic technology scenarios such as rapid focusing modules of mobile phone cameras and drone vision systems.

[0031] In some embodiments of this application, please refer to Figure 1 , Figure 1 This is a flowchart illustrating the implementation of an autofocus method provided in an embodiment of this application. Figure 1 As shown, it may specifically include steps S11 to S13.

[0032] S11: Perform spot recognition on the first image captured by the camera to obtain the first spot area and the second spot area.

[0033] In this embodiment, the focusing process of the optical system is specifically achieved by controlling the movement of the lens group inside the lens via a motor, and adjusting the relative positions of the lens groups within the lens, thereby changing the distance from the center of the light source to the focal point (i.e., the focal length), so that the subject forms a clear image on the photosensitive element. It is understood that the motor can be a voice coil motor, a linear motor, or a stepper motor with a lead screw, and the light source can be an 850nm LED or a 405nm laser diode, etc. In this embodiment, the first image is the image captured by the camera when the motor in the optical system is not in the optimal focusing position. Specifically, the first image can be a two-dimensional image captured by an area scan camera, or a one-dimensional image sequence continuously captured by a line scan camera. When performing spot recognition on the first image, target detection algorithms such as threshold segmentation, edge detection, and template matching can be used to locate the position of the spot in the first image. Then, based on the position of the spot, a region of interest is generated, thus obtaining the spot region in the first image. Since the optical system is designed using beam splitters, dual light sources, or other optical elements, during imaging, if the motor in the optical system is not in the optimal focusing position, two separate light spots will be formed on the image sensor. Automatic focusing can be achieved by calculating the relative positional changes of these two light spots. Therefore, in this embodiment, by performing light spot recognition on the first image, two light spot regions can be obtained: the first light spot region and the second light spot region.

[0034] In one specific implementation, before performing spot recognition on the first image captured by the camera, image preprocessing can be performed on the first image to suppress image noise, thereby improving the accuracy and stability of autofocus. Specifically, image preprocessing includes downsampling and / or filtering. In this embodiment, downsampling can be performed using quarter-sampling, and filtering can be performed using a 21x21 kernel Gaussian filter. In other implementations, filtering can also be performed using median filtering or mean filtering.

[0035] S12: Based on the first light spot region and the second light spot region, calculate the horizontal displacement between the center position of the first light spot region and the center position of the second light spot region.

[0036] In this embodiment, a two-dimensional coordinate system can be established, where the horizontal direction is the x-axis and the vertical direction is the y-axis. The first image is placed in the two-dimensional coordinate system, and the obtained first and second spot regions are displayed in the first image. For the first spot region, the arithmetic mean center of the first spot region can be calculated based on the coordinate values ​​and grayscale values ​​of the pixels within the first spot region. This arithmetic mean center of the first spot region is determined as the first center position corresponding to the first spot region, and the coordinates of this first center position are obtained. Similarly, for the second spot region, the arithmetic mean center of the first spot region can be calculated based on the coordinate values ​​and grayscale values ​​of the pixels within the first spot region. This arithmetic mean center of the first spot region is determined as the second center position corresponding to the first spot region, and the coordinates of this second center position are obtained. For example, the calculation formula used to calculate the arithmetic mean center can be:

[0037]

[0038] Where I(x) i y i (x) represents the grayscale value of a pixel. i y i ) represents the pixel coordinates, and N represents the number of pixels in the image.

[0039] Furthermore, after obtaining the coordinates of the first center position and the second center position, the difference can be calculated by subtracting the x-coordinate value of the first center position from the x-coordinate value of the second center position. The absolute value of this difference is then determined as the horizontal displacement between the center positions of the first and second light spot regions.

[0040] In one specific implementation, the coordinates of the geometric center of the connected domain of the first light spot region can be calculated as the first center position coordinates corresponding to the first light spot region, and the coordinates of the geometric center of the connected domain of the second light spot region can be calculated as the second center position coordinates corresponding to the second light spot region. Alternatively, the coordinates of the Gaussian fitting center of the first light spot region can be calculated as the first center position coordinates corresponding to the first light spot region, and the coordinates of the Gaussian fitting center of the second light spot region can be calculated as the second center position coordinates corresponding to the second light spot region.

[0041] S13: Match the motor position according to the displacement to obtain the motor focusing position that matches the displacement, and drive the motor to the motor focusing position to complete the autofocus.

[0042] In this embodiment, a calibration database can be pre-established, containing a large amount of calibration data. This calibration data can represent the mapping relationship between calibration displacement and calibration motor position. When matching the motor position based on the displacement, the calibration database can be queried based on the displacement to calculate the similarity between the displacement and the calibration displacement in the mapping relationship. The mapping relationship corresponding to the calibration displacement with the highest similarity or the similarity reaching a preset threshold is determined as the mapping relationship that matches the displacement. Then, the corresponding calibration motor position is obtained from the matching mapping relationship and determined as the motor focusing position that matches the displacement. By driving the motor to the motor focusing position, the automatic focusing process of the optical system can be completed. This embodiment determines the motor focusing position by matching the calibration database, which can avoid the uncertainty of each real-time curve fitting process, improve stability, and achieve high repeatability accuracy.

[0043] In one specific implementation, for a pre-built calibration database, the pre-stored calibration data in the calibration database can be subjected to a moving average filter to improve the smoothness of the calibration data. By finding the index with the smallest absolute difference, the optimal motor position corresponding to that index can be directly output, improving the accuracy of autofocus. It can be understood that this absolute difference refers to the absolute value of the difference between the horizontal displacement of the calculated center position of the first light spot region and the center position of the second light spot region and the calibration displacement.

[0044] In one specific implementation, a large amount of historical focusing data and / or focusing experience data can be used to construct model training data samples. It is understood that each model training data sample includes calibration displacement data as model input and calibration motor position data as model output. A motor position matching model is pre-constructed using machine learning algorithms. The constructed model training data samples are then used to train the motor position matching model to a convergent state, enabling it to predict the motor's focusing position based on displacement. During motor position matching, the displacement calculated based on the first and second light spot regions is input into the converged motor position matching model. The converged model then performs data fitting and prediction based on the displacement to obtain the predicted optimal focusing position, which is then output as the motor's focusing position.

[0045] As can be seen from the above, the autofocus method provided in this application identifies light spots in the first image captured by the camera to obtain a first light spot region and a second light spot region; based on the first and second light spot regions, it calculates the horizontal displacement between the center position of the first light spot region and the center position of the second light spot region; it performs motor position matching based on the displacement to obtain a motor focusing position that matches the displacement, and drives the motor to the motor focusing position to complete autofocus. The autofocus process can be completed with only a single frame image, which improves the focusing speed and reduces the focusing process from seconds to milliseconds, thereby increasing the device throughput; moreover, the calculation of the light spot center displacement adopts a single-dimensional displacement feature in the horizontal direction, which can enhance the robustness to image noise and changes in light spot shape.

[0046] In some embodiments of this application, please refer to Figure 2 , Figure 2 This is a flowchart illustrating a method for obtaining a first light spot region and a second light spot region in an autofocus method provided in an embodiment of this application. Figure 2 As shown, it may specifically include steps S21 to S22.

[0047] S21: Perform binarization processing on the first image to obtain a binary image corresponding to the first image;

[0048] S22: Use a preset matching template to match and locate the binary image, and obtain the first spot region and the second spot region from the binary image.

[0049] In this embodiment, to efficiently and accurately segment the light spot from the background, the first image can be binarized first to perform light spot recognition based on the binary image, obtaining the first and second light spot regions from the binary image. In one specific implementation, the Otsu's algorithm (Otsu's algorithm) can be used to convert the first image into a binary image. In other specific implementations, a fixed threshold method, an adaptive threshold method, or other image segmentation algorithms can also be used to convert the first image into a binary image. A preset matching template includes two boxes of interest, one in the upper left and one in the lower right. By using this preset matching template to perform normalized cross-correlation matching on the binary image, the first and second light spot regions corresponding to the positions of the two light spots in the binary image can be quickly located.

[0050] In one specific implementation, after obtaining the first and second spot regions, frequency domain filtering preprocessing can be performed on the images corresponding to the first and second spot regions. Signal dimensionality reduction processing can then be performed on the preprocessed images to obtain corresponding row projection signal curves and column projection signal curves. Based on these curves, peak detection is performed to obtain the coordinates of the four corner points corresponding to each spot. For each spot, a rectangular frame can be drawn based on the coordinates of its four corner points; this rectangular frame represents the spot region for precise localization. Based on this localization method, the anti-interference capability, positioning accuracy, and positioning stability of spot recognition can be improved in low-light, high-noise, and low-contrast environments.

[0051] In some embodiments of this application, when calculating the arithmetic mean center of the spot regions for the first and second spot regions obtained based on binary images, specifically, all binarized white pixels in the spot regions can be traversed, and the arithmetic mean of the coordinates of all white pixels can be calculated as the center position coordinates of the spot regions. For example, the calculation formula used to calculate the arithmetic mean center can be:

[0052]

[0053] Among them, (x i y i ) represents the coordinates of the white pixel, and N represents the number of white pixels in the image.

[0054] This embodiment calculates the spot center by using the binarized white pixels in the spot region, which reduces algorithm complexity, computational load, and focusing speed, and is easy to implement on embedded systems or FPGAs. Moreover, the spot center calculation process does not rely on contour finding, and has better robustness to discontinuous and irregular spots.

[0055] In some embodiments of this application, please refer to Figure 3 , Figure 3 This is a flowchart illustrating another implementation of the autofocus method provided in an embodiment of this application. Figure 3 As shown, it may specifically include steps S31 to S33.

[0056] S31: Perform spot recognition on each row image in the row image sequence to obtain the first spot region and the second spot region corresponding to each row image;

[0057] S32: Based on the first spot area and the second spot area corresponding to each row of images, calculate the horizontal displacement between the center position of the first spot area and the center position of the second spot area, and perform curve plotting on the calculated displacement corresponding to each row of the row image sequence to obtain the displacement curve.

[0058] S33: Perform motor position matching based on the displacement curve to obtain a motor focusing position that matches the displacement curve, and drive the motor to the motor focusing position to complete automatic focusing.

[0059] In this embodiment, if the image sensor in the optical system is a line scan camera, during autofocus, the motor carries the lens group or sample for unidirectional continuous scanning, while the line scan camera continuously acquires images at high speed, which constitutes a row image sequence. The row image sequence contains multiple sequentially arranged one-dimensional row images, where the light spot in each row image represents the light spot state at the instantaneous motor position. In this embodiment, by identifying the light spots one by one in the row images of the row image sequence, the first and second light spot regions corresponding to each row image can be obtained. Then, for each row image's corresponding first and second light spot regions, the horizontal displacement between the center positions of the first and second light spot regions is calculated, resulting in a displacement array. By plotting multiple displacement data points in this displacement array, a displacement curve is obtained, representing the real-time displacement curve as the motor scanning position changes during image acquisition by the line scan camera. It can be understood that one displacement data point in the displacement array corresponds to one row image in the row image sequence. The pre-stored calibration data in the calibration database can also be represented as a mapping relationship between the calibration displacement curve and the calibration motor position. When matching the motor position based on the displacement curve, the calibration database can be queried based on the displacement curve to calculate the similarity between the displacement curve and the calibration displacement curve in the mapping relationship. The mapping relationship corresponding to the calibration displacement curve with the highest similarity or the similarity reaching a preset threshold is determined as the mapping relationship that matches the displacement curve. Then, the corresponding calibration motor position is obtained from the matching mapping relationship and determined as the motor focusing position that matches the displacement curve. By driving the motor to the motor focusing position, the automatic focusing process of the optical system can be completed. In this embodiment, the optical system based on a line scan camera acquires images through the working mode of "continuous motor scanning - continuous camera acquisition" during the automatic focusing process. This fully utilizes the high-speed characteristics of the line scan sensor, is suitable for ultra-high-speed online detection scenarios, and can eliminate the mechanical pause time caused by the working mode of "motor stepping - motor stopping - camera acquisition" in the prior art. The motor does not need to step and stop, the movement is smoother, the system efficiency is maximized, and the focusing speed is effectively improved.

[0060] In one specific implementation, the motor position matching of a line scan camera during autofocus can also be achieved by training a motor position matching model. Specifically, when constructing the model training data samples, the model input consists of calibration displacement curve data, and the model output consists of calibration motor position data. The process of constructing the motor position matching model and implementing motor position matching is essentially the same as the process described above for area scan cameras during autofocus, and will not be elaborated further here.

[0061] It is understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0062] In some embodiments of this application, please refer to Figure 4 , Figure 4 This is a basic structural block diagram of an electronic device provided in an embodiment of this application. Figure 4 As shown, the electronic device 4 in this embodiment includes a processor 41, a memory 42, and a computer program 43 stored in the memory 42 and executable on the processor 41, such as a program for an autofocus method. When the processor 41 executes the computer program 43, it implements the steps of each of the aforementioned autofocus method embodiments. Please refer to the relevant descriptions in the embodiments for details, which will not be repeated here.

[0063] For example, the computer program 43 can be divided into one or more modules (units) for performing the various steps in the above method embodiments. The one or more modules are stored in the memory 42 and executed by the processor 41 to complete this application. The one or more modules can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 43 in the electronic device 4.

[0064] The electronic device may include, but is not limited to, a processor 41 and a memory 42. Those skilled in the art will understand that... Figure 4 This is merely an example of electronic device 4 and does not constitute a limitation on electronic device 4. It may include more or fewer components than shown, or combine certain components, or different components. For example, the electronic device may also include input / output devices, network access devices, buses, etc.

[0065] The processor 41 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0066] The memory 42 can be an internal storage unit of the electronic device 4, such as a hard disk or memory. The memory 42 can also be an external storage device of the electronic device 4, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory 42 can include both internal and external storage units of the electronic device 4. The memory 42 is used to store the computer program and other programs and data required by the electronic device. The memory 42 can also be used to temporarily store data that has been output or will be output.

[0067] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.

[0068] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, can implement the steps in the various method embodiments described above. In this embodiment, the computer-readable storage medium can be either non-volatile or volatile.

[0069] This application provides a computer program product that, when run on a mobile terminal, enables the mobile terminal to implement the steps described in the various method embodiments.

[0070] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0071] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0072] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0073] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. An auto-focusing method characterized by, include: Perform spot recognition on the first image captured by the camera to obtain the first spot region and the second spot region; Based on the first light spot region and the second light spot region, calculate the horizontal displacement between the center position of the first light spot region and the center position of the second light spot region; Matching the motor position based on the displacement to obtain a motor focusing position that matches the displacement, and driving the motor to the motor focusing position to complete automatic focusing, includes: querying a preset calibration database based on the displacement, and obtaining a motor focusing position that matches the displacement based on the calibration data pre-stored in the calibration database, wherein the calibration data includes the mapping relationship between calibration displacement and calibration motor position and / or the mapping relationship between calibration displacement curve and calibration motor position; The camera is a line scan camera, the first image is a sequence of row images continuously acquired by the line scan camera, and the method further includes: Spot recognition is performed on each row of the row image sequence to obtain the first spot region and the second spot region corresponding to each row image. Based on the first and second spot regions corresponding to each row of images, the horizontal displacement between the center positions of the first and second spot regions is calculated. The calculated displacements for each row of the image sequence are then plotted to obtain a displacement curve. The displacement curve represents the real-time displacement curve as the motor scanning position changes during the image acquisition process of the line scan camera. According to the displacement curve, a motor position matching is performed, a motor focusing position matched with the displacement curve is obtained, and the motor is driven to the motor focusing position to complete the auto-focusing; wherein, during the auto-focusing of the optical system of the linear array camera, the motor continuously scans The camera continuously acquires images in the working mode.

2. The autofocusing method of claim 1, wherein, The step of performing spot recognition on the first image to obtain the first spot region and the second spot region includes: The first image is binarized to obtain a binary image corresponding to the first image; The binary image is matched and located using a preset matching template to obtain the first spot region and the second spot region from the binary image.

3. The autofocusing method according to claim 2, wherein Before the step of calculating the horizontal displacement of the center positions of the first and second light spot regions based on the first and second light spot regions, the method further includes: Calculate the coordinates of the center of the arithmetic mean of the first spot region as the first center position coordinates corresponding to the first spot region, and calculate the coordinates of the center of the arithmetic mean of the second spot region as the second center position coordinates corresponding to the second spot region; or Calculate the coordinates of the geometric center of the connected domain of the first light spot region as the first center position coordinates corresponding to the first light spot region, and calculate the coordinates of the geometric center of the connected domain of the second light spot region as the second center position coordinates corresponding to the second light spot region; or The coordinates of the Gaussian fitting center of the first light spot region are calculated as the first center position coordinates of the first light spot region, and the coordinates of the Gaussian fitting center of the second light spot region are calculated as the second center position coordinates of the second light spot region.

4. The autofocusing method according to claim 3, wherein The step of calculating the horizontal displacement of the center positions of the first and second light spot regions based on the first and second light spot regions includes: Calculate the difference between the horizontal coordinate value in the first center position coordinate and the horizontal coordinate value in the second center position coordinate, and determine the absolute value of the difference as the horizontal displacement between the center position of the first light spot area and the center position of the second light spot area.

5. The auto-focusing method according to claim 1, wherein The method further includes: The calibration data pre-stored in the calibration database is subjected to moving average filtering.

6. The autofocusing method according to any one of claims 1 to 5, characterized in that, Before the step of spot recognition on the first image captured by the camera, the following steps are also included: The first image is preprocessed, wherein the image preprocessing includes downsampling and / or filtering.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1-6.

8. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 7. When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Shooting parameter automatic adjustment method and device, storage medium and industrial camera

    CN115225820A

  • Focusing method and imaging system

    CN118444468A