Focusing method, device, medium and electronic equipment

By constructing a focus model and using the data collected by the image sensor to determine the focus position, the problem of time-consuming traditional focusing methods is solved, fast and accurate focusing is achieved, and production efficiency and accuracy are improved.

CN120075614BActive Publication Date: 2025-08-12ZHEJIANG UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510494469.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-21
Publication Date
2025-08-12
Estimated Expiration
2045-04-21

AI Technical Summary

Technical Problem

The traditional accurate focusing method takes time and affects production efficiency. The focus accuracy is affected by the movement interval, making it difficult to meet the speed and accuracy requirements of modern production lines.

Method used

Sample image data is collected through the image sensor, training sample data sets are constructed, and the initial model is trained to obtain the focus model. The focus model is used to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focus position, and control the movement of the mechanical motion structure.

Benefits of technology

It achieves fast and accurate focus, significantly reducing computing resource consumption, shortening focus time, and improving focus speed and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120075614B_ABST
    Figure CN120075614B_ABST
Patent Text Reader

Abstract

An embodiment of the present application provides a focusing method, applied to an electronic device, which is communicatively connected to an image sensor and a mechanical motion structure. The method comprises: acquiring sample image data via the image sensor; obtaining a training sample dataset based on the sample image data; training an initial model using the training sample dataset until the initial model satisfies preset conditions, thereby obtaining a focusing model; inputting a target array corresponding to the lens module to be tested into the focusing model, using the focusing model to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focus position; and controlling the movement of the mechanical motion structure based on the absolute value and relative direction of the distance. This application enables rapid focusing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of artificial intelligence technology and relates to the field of optical system assembly technology, and in particular to a focusing method, device, medium and electronic equipment. Background Art

[0002] In the current lens module assembly and image quality inspection process, accurately determining the position of the image sensor and the camera focal plane is crucial. The accuracy of this step not only directly affects the final image quality but also has a significant impact on overall production efficiency.

[0003] There are two common traditional methods for accurate focusing. One relies on continuously scanning the lens's modulation transfer function (MTF) curve at different image distances to achieve accurate focus; the other involves capturing multiple images and calculating a focus evaluation function to determine the exact focus position. However, both methods have limitations. These methods are often time-consuming and require significant computing resources. Furthermore, focus accuracy is affected by the movement interval used when scanning the MTF curve (or capturing multiple images). Within the same movement range, smaller movement intervals result in higher focus accuracy, but this also increases the time required. Consequently, traditional methods often result in excessively long accurate focus times, leading to low production efficiency. This makes it difficult to meet the stringent speed and precision requirements of modern, efficient production lines. Summary of the Invention

[0004] The embodiments of the present application provide a focusing method, device, medium, and electronic device, which can predict the focus position of a lens module to be tested through a single image, thereby significantly improving the focusing speed and accuracy.

[0005] A first aspect of an embodiment of the present application provides a focusing method, which is applied to an electronic device, wherein the electronic device is communicatively connected to an image sensor and a mechanical motion structure, and the method includes: collecting sample image data through the image sensor; obtaining a training sample data set based on the sample image data; training an initial model through the training sample data set until the initial model meets preset conditions, thereby obtaining a focusing model; inputting a target array corresponding to the lens module to be tested into the focusing model, and using the focusing model to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focus position; and controlling the movement of the mechanical motion structure according to the absolute value of the distance and the relative direction.

[0006] According to an embodiment of the present application, obtaining a training sample data set based on the sample image data includes: obtaining a corresponding modulation transfer function (MTF) curve based on the sample image data; and obtaining the training sample data set based on the MTF curve and the position of the image sensor.

[0007] According to an embodiment of the present application, before training the initial model using the training sample data set, the focusing method further includes: dividing the training sample data set into a training set and a test set.

[0008] According to an embodiment of the present application, before dividing the training sample data set into a training set and a test set, the focusing method further includes: performing normalization processing on the data in the training sample data set.

[0009] According to an embodiment of the present application, before dividing the training sample data set into a training set and a test set, the focusing method further includes: performing standardization processing on the data in the training sample data set.

[0010] According to an embodiment of the present application, the use of a focus model to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focus position includes: after determining the position where the lens module to be tested is placed, obtaining a first position of the image sensor; controlling the image sensor to move to a second position at a preset distance from the first position through the mechanical motion structure; collecting sample image data through the image sensor, and obtaining a corresponding MTF curve based on the sample image data; obtaining a target array based on the MTF curve and the second position, inputting the target array into the focus model, and using the focus model to output the absolute value of the distance between the current position of the image sensor and the accurate focus position.

[0011] According to a second aspect of an embodiment of the present application, there is provided a focusing device, comprising: an acquisition module for acquiring sample image data through the image sensor; a processing module for obtaining a training sample data set based on the sample image data; a training module for training an initial model through the training sample data set until the initial model meets preset conditions to obtain a focusing model; the processing module is further used to input a target array corresponding to the lens module to be tested into the focusing model, and use the focusing model to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focusing position; the processing module is further used to control the movement of the mechanical motion structure according to the absolute value of the distance and the relative direction.

[0012] A third aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, the focusing method as described above is implemented.

[0013] A fourth aspect of an embodiment of the present application provides an electronic device, comprising: a memory, and a processor, wherein the processor executes computer-readable instructions stored in the memory to implement the focusing method.

[0014] The focusing method provided in the embodiment of the present application collects sample image data through the image sensor in the imaging quality detection system; obtains a training sample data set based on the sample image data; trains an initial model through the training sample data set until the initial model meets preset conditions, thereby obtaining a focusing model; inputs the target array corresponding to the lens module to be tested in the imaging quality detection system into the focusing model, and uses the focusing model to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focusing position; controls the movement of the mechanical motion structure according to the absolute value and relative direction of the distance, thereby achieving fast and accurate focusing. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0016] Figure 1 A schematic diagram of an application environment of a focusing method provided in an embodiment of the present application.

[0017] Figure 2 A flowchart of the focusing method provided in an embodiment of the present application.

[0018] Figure 3 This is a schematic diagram of an image captured when the image sensor provided in an embodiment of the present application is at a first image distance and the corresponding MTF curve.

[0019] Figure 4 This is a schematic diagram of an image captured when the image sensor provided in an embodiment of the present application is at a second image distance and the corresponding MTF curve.

[0020] Figure 5 This is a schematic diagram of an image captured when the image sensor provided in an embodiment of the present application is at the third image distance and the corresponding MTF curve.

[0021] Figure 6 This is a principle block diagram of a focusing device provided in an embodiment of the present application.

[0022] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0023] In order to make the objectives, technical solutions and advantages of this application clearer, this application is described in detail below with reference to the accompanying drawings and specific embodiments.

[0024] It should be noted that, in this application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A alone, A and B together, and B alone, where A and B can be singular or plural. The terms "first," "second," "third," "fourth," and so on (if any) in the specification, claims, and drawings of this application are used to distinguish similar objects, not to describe a specific order or precedence.

[0025] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete manner. The following embodiments and features in the embodiments may be combined with each other unless there is a conflict.

[0026] See also Figure 1 , is a schematic diagram of an application environment of a focusing method provided in an embodiment of the present application. The focusing method is applied to an imaging quality detection system. Figure 1 As shown, the imaging quality detection system includes a light source 1, a reticle 2, a lens module to be tested 3, an image sensor 4, a mechanical motion structure 5 and an electronic device 6. The image sensor 4 and the mechanical motion structure 5 are electrically connected to the electronic device 6.

[0027] In some embodiments of the present application, the light source 1 can generate a light beam that meets requirements, for example, a light beam with a specific wavelength, and the light intensity and uniformity of the light beam meet certain requirements.

[0028] In some embodiments of the present application, the reticle 2 is an optical reticle, an auxiliary tool used to measure and grade optical instruments, used to provide a standard initial pattern. It is usually made of transparent material, has scales and markings, and is used to assist in the precise adjustment and calibration of optical instruments. The principle of the optical reticle is based on the interference and diffraction of light. When a light beam passes through the reticle, interference and diffraction occur, forming light and dark stripes. The spacing and shape of these stripes can provide important information about the performance of the optical instrument. Optical reticles include linear reticles, grid reticles, and circular reticles. Linear reticles are one of the most common types of optical reticles and are used to measure the resolution and focusing performance of optical instruments. Linear reticles can be used to adjust optical instruments such as microscopes, telescopes, and lasers. Grid reticles are optical reticles with a grid structure and are used to measure the distortion and deformation of optical instruments. They can be used to adjust optical instruments such as optical projectors and optical microscopes. Circular reticles are optical reticles with circular scales and are typically used to measure the rotational and angular accuracy of optical instruments. It can be used to adjust optical instruments such as optical turntables and optical gyroscopes.

[0029] In some embodiments of the present application, the lens module 3 under test is an optical system composed of multiple lenses, which is used to further focus and image the light beam modulated by the reticle 2. During this process, the optical properties of the lens module 3 under test (such as focal length and distortion) will affect the imaging results. Therefore, by analyzing the imaging results, the performance of the lens module 3 under test can be evaluated.

[0030] In some embodiments of the present application, the image sensor 4 is used to capture optical image information formed by the lens module 3 under test and transmit the optical image information to the electronic device 6. The electronic device 6 analyzes the image quality based on the received optical image information and determines the performance of the lens module 3 under test based on the image quality.

[0031] In some embodiments of the present application, the mechanical motion structure 5 is used to drive the movement of the image sensor 4. After the electronic device 6 analyzes the image quality based on the optical image information, it can control the movement of the mechanical motion structure 5 based on the performance of the lens module 3 to be tested, adjust the position of the image sensor 4, and move the image sensor 4 to the focal plane position to achieve precise focusing.

[0032] In some embodiments of the present application, when the light beam generated by the light source 1 is irradiated onto the grating plate 2, the light beam can be modulated by the grating plate 2 to form a specific standard initial pattern, and then the modulated light beam is further focused and imaged by the lens module 3 to be tested, and finally projected onto the image sensor 4. The image sensor 4 is used to capture the optical image information after imaging. In order to obtain more comprehensive image information or perform more accurate measurements, the image sensor 4 needs to be able to move precisely under the control of the mechanical motion structure 5. This movement can be translation, rotation or other forms of movement, depending on the application requirements. By combining the mechanical motion structure 5, the image sensor 4 can capture images at different positions or angles, thereby providing richer information and more accurate measurement results.

[0033] According to actual needs, the detection system may also include other auxiliary optical elements, such as filters, relay lenses, etc., to further improve the system performance. Figure 1 Not shown in detail.

[0034] In some possible scenarios, the electronic device 6 may also be connected to the image sensor 4 and / or the mechanical motion structure 5 through a network. The network may be a wired network or a wireless network. The wired network may be any of a local area network, a metropolitan area network, and a wide area network, and may be any of a variety of networks, such as Wireless Fidelity (Wi-Fi), ZigBee Wireless Networks (ZigBee), Ultra Wideband (UWB), and Universal Serial Bus (USB).

[0035] Figure 2 is a flow chart of the focusing method provided in an embodiment of the present application, such as Figure 2 As shown, the focusing method is applied in an electronic device. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.

[0036] Step S1: collecting sample image data through an image sensor.

[0037] In the embodiment of the present application, Figure 1In the imaging quality detection system shown, the image sensor 4 is linked to the mechanical motion structure 5, and the mechanical motion structure 5 moves along the direction of propagation of the light beam generated by the light source 1. The position where the image sensor receives the light to form an image is estimated based on the design value of the lens working distance. Through precise calculation and design, it can be ensured that at a specific working distance, the light beam can be accurately focused on the image sensor 4 to form a clear sample image. The range of motion of the mechanical motion structure 5 can be the position range within which the mechanical motion structure 5 enables the image sensor 4 to receive the sample image. While the mechanical motion structure 5 is moving, the image sensor 4 can continuously and intensively capture sample images to obtain sample image data, and the position information of the mechanical motion structure 5 corresponding to the capture of each sample image is recorded.

[0038] In the embodiment of the present application, by precisely designing the lens working distance, the position at which the image sensor 4 receives the sample image formed by the light beam generated by the light source 1 can be determined. Based on the lens working distance, the range of motion of the mechanical motion structure 5 can be precisely determined, ensuring that the image sensor 4 can always cover the position of the image plane during movement, and ensuring that the image sensor 4 can effectively receive the sample image at any point along the motion trajectory under the control of the mechanical motion structure 5.

[0039] Step S2: obtaining a training sample data set based on the sample image data.

[0040] In an embodiment of the present application, obtaining a training sample data set based on sample image data includes: obtaining a corresponding MTF curve based on the sample image data; and obtaining the training sample data set based on the MTF curve and a position of an image sensor.

[0041] Specifically, the collected sample image data is preprocessed and input into an MTF calculation program to obtain an MTF curve for each sample image. The abscissa of the MTF curve represents spatial frequency in line pairs per millimeter (lp / mm), while the ordinate represents the modulation transfer function value, a dimensionless scalar typically between 0 and 1. The MTF curve is evenly sampled along the abscissa to produce an array of N elements. An array is associated with the image sensor position corresponding to the sample image in the array to produce an array. Assuming the number of sample images collected is M, M sets of data are obtained for training and testing the neural network model. For example, if the collected sample image is T1 and the corresponding image sensor position is P1, an MTF curve is obtained based on sample image T1. The MTF curve is evenly sampled to produce an array of N elements {N1, N2, N3…Ni}, where i is an integer greater than or equal to 1 and less than or equal to N. Based on the array {N1, N2, N3...Ni} and the position P1, a first array {P1, N1, N2, N3...Ni} can be obtained. Then, based on the M sample images, M groups of data can be obtained, and the M groups of data constitute the training sample data set.

[0042] In the embodiment of the present application, the spacing used for equally spaced sampling of the MTF curve along the horizontal axis direction of the MTF curve is smaller than the maximum error value allowed for the focus of the lens module to be tested.

[0043] It should be noted that, since the image sensor is clamped by the mechanical motion structure, the position of the image sensor is the same as the position of the mechanical motion structure. The position of the image sensor in the above training sample data set may be the position of the mechanical motion structure.

[0044] Step S3: train the initial model using the training sample data set until the initial model meets the preset conditions to obtain a focus model.

[0045] In an embodiment of the present application, the initial model is a neural network for data regression problems. The structure of the initial model includes an input layer, a hidden layer, a pooling layer, a fully connected layer, and an output layer. The input layer is used to receive input data (e.g., a training set) and represents the data in the training sample data set in the form of an array (e.g., including the data obtained by adopting the MTF curve and the position of the image sensor). The hidden layer includes several fully connected layers (Fully Connected Layer) or one-dimensional convolutional layers (1D Convolutional Layer) for extracting high-dimensional feature data from the array data; the pooling layer is used to reduce the dimensionality of the extracted feature values, reduce redundant information, and improve training efficiency; the fully connected layer is used to map the extracted high-dimensional feature data to a low-dimensional representation to obtain the target feature vector of the initial model; the output layer is used to output the regression target value, which corresponds to the assembly error or adjustment amount of the core-adjusting optical element.

[0046] In an embodiment of the present application, before training the initial model using the training sample data set, the focusing method further includes: dividing the training sample data set into a training set and a test set.

[0047] In an embodiment of the present application, the training sample data set can be randomly divided into a training set and a test set according to a preset ratio. The preset ratio can be 4:1 or 7:3. For example, 80% of the training sample data set is divided into a training set, and 20% of the training sample data set is divided into a test set. The training set is used to train the model, modulate the weights of the neural network in the model and optimize the model; the test set is used to verify the performance of the model and evaluate the generalization ability of the model. When dividing the data set, it is necessary to ensure the randomness and uniformity of the division to avoid bias in certain feature values or target values in the data set.

[0048] In some embodiments of the present application, before dividing the training sample dataset into a training set and a test set, the focusing method further includes: normalizing the data in the training sample dataset to eliminate the impact of dimensional differences in the eigenvalues of the data in the training sample dataset on training, thereby improving the convergence efficiency of the model. For example, the data in the training sample dataset is scaled to a first range, where the first range is greater than or equal to zero and less than or equal to 1.

[0049] In some embodiments of the present application, before dividing the training sample dataset into a training set and a test set, the focusing method further includes: normalizing the data in the training sample dataset. This eliminates the impact of dimensional differences in the feature values of the data in the training sample dataset on training and improves the convergence efficiency of the model. For example, the data in the training sample dataset is processed into a standard state distribution.

[0050] In some embodiments of the present application, before dividing the training sample dataset into training and test sets, the focusing method further includes formatting the training sample dataset to construct the data in the sample dataset into a data loading format suitable for neural network frameworks (such as TensorFlow, PyTorch, etc.). For example, the data in the sample dataset is processed into tensors or NumPy arrays. If the training sample dataset is large, a data loader can be used to load it batch by batch to improve training efficiency and reduce memory usage.

[0051] In some embodiments of the present application, before dividing the training sample dataset into a training set and a test set, the focusing method further includes: performing data augmentation on the training sample dataset to increase data diversity and improve the robustness of the model. For example, noise data can be added to the training sample dataset, or the training sample dataset can be expanded through methods such as random offset. It should be noted that if the existing training sample dataset can be used to train the model, there is no need to perform data augmentation on the training sample dataset. For example, the amount of data in the training sample dataset is sufficient.

[0052] In some embodiments of the present application, the preset condition includes a loss value corresponding to a preset loss function, such as a regression loss function (e.g., mean squared error (MSE)), being less than a preset loss threshold. The weights of the loss function are modulated to minimize the error between the predicted value and the true value. Data input is fed into the network in batches in the form of arrays, and iterative training is performed using an optimization algorithm (e.g., Adam or SGD) until convergence.

[0053] In some embodiments of the present application, the training process of the focus model can use a supervised training method. Specifically, the training method may include: using the current batch of data in the training set to iteratively update the initial model; using the test set to determine whether the initial model of each update meets the preset conditions; if the preset conditions are not met, using the next batch of data to perform the next update on the initial model according to the optimization algorithm (such as the gradient descent algorithm); repeating the above steps until the initial model meets the preset conditions. The preset conditions may include that the loss value corresponding to the loss function is less than a preset loss threshold, the performance of the focus model (such as accuracy, recall rate, etc.) reaches a preset performance threshold, the number of model iterations reaches a preset number threshold, etc. The above thresholds can be set according to actual needs, and the present application does not impose specific restrictions on this.

[0054] In step S4 , the target array corresponding to the lens module to be tested is input into the focus model, and the absolute value and relative direction of the distance between the current position of the image sensor and the focus position are determined using the focus model.

[0055] In an embodiment of the present application, using a focus model to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focus position includes: after determining the position where the lens module to be tested is placed, obtaining a first position of the image sensor; controlling the image sensor to move to a second position at a preset distance from the first position through a mechanical motion structure; collecting sample image data through the image sensor, and obtaining a corresponding MTF curve based on the sample image data; obtaining a target array based on the MTF curve and the second position, inputting the target array into the focus model, and using the trained focus model to output the absolute value of the distance between the current position of the image sensor and the accurate focus position.

[0056] Specifically, after the focusing model is trained, the focusing model can be used for focusing. In the process of focusing the lens module 3 to be tested in the imaging quality detection system, the lens module 3 to be tested usually has a theoretical focal length after focusing. After the position of the lens module 3 to be tested is determined, the first position of the image sensor can be obtained according to the theoretical focal length. Assume that the first position is position Z. The image sensor is controlled to move to a second position X at a certain distance from the first position Z, sample image data is collected through the image sensor, and the corresponding MTF curve is obtained based on the sample image data; based on the MTF curve and the second position X, a target array is obtained, and the target array is input into the focusing model, and the trained focusing model is used for reasoning to output the absolute value L of the distance between the current position of the image sensor and the accurate focus position. Since the first position Z and the second position X corresponding to the image sensor are both known, the relative direction of the second position X and the first position Z can be obtained.

[0057] Step S5: Control the movement of the mechanical motion structure according to the absolute value of the distance and the relative direction.

[0058] In the embodiment of the present application, the mechanical motion structure 5 is controlled to move a distance L toward the first position Z according to the absolute value of the distance and the relative direction, so as to complete an accurate focusing operation.

[0059] The absolute value of the distance between the second position X and the first position Z of the image sensor should be ensured to be greater than the theoretical maximum focal length error of the lens module to be tested to prevent misjudgment of the relative direction of the second position X and the first position Z.

[0060] In an embodiment of the present application, an image sensor in an imaging quality inspection system collects sample image data; a training sample dataset is obtained based on the sample image data; an initial model is trained using the training sample dataset until the initial model meets preset conditions, thereby obtaining a focus model; a target array corresponding to a lens module to be tested in the imaging quality inspection system is input into the focus model, and the focus model is used to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focus position, and the movement of the mechanical motion structure is controlled based on the absolute value and relative direction of the distance. The focus method disclosed in the present application constructs a training sample dataset for training and testing by associating the MTF curve corresponding to the sample image with the position of the image sensor; an initial model is trained using the constructed training sample dataset to obtain a focus model; the trained focus model is deployed in a production system; the image sensor is moved to a second position X, a certain distance away from the first position Z, and sample image data is collected using the image sensor, and a corresponding MTF curve is obtained based on the sample image data; a target array is obtained based on the MTF curve, and the target array is input into the focus model. The trained focus model is used for inference to output the absolute value L of the distance between the current position of the image sensor and the accurate focus position. Based on the absolute value of the distance L, the mechanical motion structure is controlled to move the image sensor to the focal plane position to achieve precise focusing. Compared with traditional methods that continuously scan the MTF or calculate the focus evaluation function through multiple images, the focusing method provided in this application can complete focusing by collecting a single image, significantly reducing the consumption of computing resources and greatly shortening the time required for accurate focusing. At the same time, it ensures higher accuracy of accurate focusing, greatly improving the focusing speed and accuracy, and has the advantages of convenient operation, high efficiency and reliability.

[0061] Figures 3 to 5 The images captured when the image sensor is located at different image distances on the image side, as well as the MTF curves corresponding to each image, are shown. Comparing the three sets of images, we can intuitively see that MTF has a clear feedback on the degree to which the image sensor deviates from the accurate focus position. For this reason, it is currently a common practice to use the MTF curve to evaluate whether the image sensor has reached the accurate focus position, or to evaluate the degree to which the image sensor is located away from the accurate focus position. Figure 3 The MTF curve corresponding to (a) is Figure 3 (b) Figure 4 The MTF curve corresponding to (c) is Figure 4 (d) in; Figure 5 The MTF curve corresponding to (e) is Figure 5 (f) in . Figure 3 (a) in Figure 4 (c) Figure 5 (e) in Figure 3 (b) Figure 4 (d) and Figure 5 From (f) in the above, we can see that as Figure 3 (a) in Figure 4 (c) and Figure 5 The cross image in (e) is getting increasingly blurred. Figure 3 (b) Figure 4 (d) and Figure 5 The area of the MTF curve corresponding to (f) in the image is getting smaller and smaller, which indicates that the position of the image sensor is getting farther and farther away from the accurate focus position.

[0062] See also Figure 6 , is a functional block diagram of a focusing device provided in an embodiment of the present application. The focusing device 400 includes: an acquisition module 401, configured to acquire sample image data using the image sensor; a processing module 402, configured to obtain a training sample data set based on the sample image data; a training module 403, configured to train an initial model using the training sample data set until the initial model satisfies a preset condition, thereby obtaining a focusing model; the processing module 402 is further configured to input a target array corresponding to the lens module to be tested into the focusing model, and to determine the absolute value and relative direction of the distance between the current position of the image sensor and the focusing position using the focusing model; the processing module 402 is further configured to control the movement of the mechanical motion structure based on the absolute value of the distance and the relative direction.

[0063] Another embodiment of the present application further provides an electronic device. Figure 1 The application environment is only an example. In other exemplary embodiments, the computer program product that implements the focusing method of the embodiment of the present application can also be run on any electronic device with sufficient computing power (such as Figure 1 In the electronic device 6) shown, each step of the focusing method is executed to provide a focusing function.

[0064] See also Figure 7 , is a structural diagram of an electronic device provided in an embodiment of the present application. Figure 7 As shown, in one embodiment of the present application, the electronic device 6 can be a mobile phone, a tablet computer, a smart wearable device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, a netbook, or the like. The embodiment of the present application does not impose any restrictions on the specific type of the electronic device 6.

[0065] like Figure 7As shown, the electronic device 6 may include, but is not limited to, a communication module 101, a memory 102, a processor 103, an input / output (I / O) interface 104, and a bus 105. The processor 103 is coupled to the communication module 101, the memory 102, and the I / O interface 104 via the bus 105.

[0066] Those skilled in the art will understand that the schematic diagram is merely an example of the electronic device 6 and does not constitute a limitation on the electronic device 6. The electronic device 6 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 6 may also include a network access device, etc.

[0067] The communication module 101 may include a wired communication module and / or a wireless communication module. The wired communication module may provide one or more wired communication solutions such as Universal Serial Bus (USB) and Controller Area Network (CAN). The wireless communication module may provide one or more wireless communication solutions such as Wireless Fidelity (Wi-Fi), Bluetooth (BT), mobile communication networks, Frequency Modulation (FM), Near Field Communication (NFC), and Infrared (IR).

[0068] Memory 102 can be used to store computer-readable instructions and / or modules. Processor 103 implements various functions of electronic device 6 by running or executing the computer-readable instructions and / or modules stored in memory 102 and accessing data stored in memory 102. Memory 102 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as sound playback or image playback); the data storage area may store data generated based on the use of electronic device 6. Memory 102 may include non-volatile and volatile memory, such as a hard disk, internal memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash card, at least one disk storage device, a flash memory device, or other storage devices.

[0069] The memory 102 may be an external memory and / or an internal memory of the electronic device 6. Furthermore, the memory 102 may be a physical memory such as a memory stick, a TF card (Trans-flash Card), and the like.

[0070] The processor 103 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor. The processor 103 is the computing core and control center of the electronic device 6. It utilizes various interfaces and lines to connect various parts of the entire electronic device 6 and execute the operating system of the electronic device 6 as well as various installed applications and program codes.

[0071] Exemplarily, the computer-readable instructions may be divided into one or more modules / sub-modules / units, one or more of which are stored in the memory 102 and executed by the processor 103 to complete the present application. One or more modules / sub-modules / units may be a series of computer-readable instruction segments capable of performing specific functions, and the computer-readable instruction segments are used to describe the execution process of the computer-readable instructions in the electronic device 6. For example, the computer-readable instructions may be divided into multiple modules of the aforementioned focusing device.

[0072] If the modules / units integrated in the electronic device 6 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also instruct the relevant hardware to complete them through computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of each of the above-mentioned method embodiments can be implemented.

[0073] Computer-readable instructions include computer-readable instruction code, which may be in source code form, object code form, executable file, or some intermediate form. Computer-readable media may include any entity or device capable of carrying computer-readable instruction code, recording media, USB flash drives, mobile hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), and random access memory (RAM).

[0074] Combine Figure 2 , the memory 102 in the electronic device 6 stores computer-readable instructions, and the processor 103 can execute the computer-readable instructions stored in the memory 102 to implement the following Figure 2 Focusing method shown.

[0075] Specifically, the specific implementation method of the processor 103 for the above computer readable instructions can refer to Figure 2 The description of the relevant steps in the corresponding embodiments will not be repeated here.

[0076] The I / O interface 104 is used to provide a channel for user input or output. For example, the I / O interface 104 can be used to connect various input and output devices, such as a mouse, keyboard, touch device, display screen, etc., so that the user can enter information or visualize information.

[0077] The bus 105 is at least used to provide a channel for mutual communication among the communication module 101 , the memory 102 , the processor 103 , and the I / O interface 104 in the electronic device 6 .

[0078] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of modules is merely a logical function division, and other division methods may be used in actual implementation.

[0079] Modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, that is, they may be located in one place or distributed across multiple network elements. Some or all of these modules may be selected to achieve the purpose of this embodiment based on actual needs.

[0080] In addition, the functional modules in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0081] Therefore, the embodiments should be considered in all respects as illustrative and non-restrictive, and the scope of the present application is defined by the appended claims rather than the foregoing description, and all changes that come within the meaning and range of equivalents of the claims are intended to be embraced therein. Any reference to a figure in a claim should not be construed as limiting the claim to which it relates.

[0082] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices may also be implemented by a single unit or device through software or hardware. Terms such as first and second are used to indicate names and do not imply any particular order.

[0083] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application and are not intended to limit the present application. Although the present application has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present application.

Claims

1. A focusing method, applied to an electronic device, wherein the electronic device is communicatively connected to an image sensor and a mechanical motion structure, characterized in that: The method comprises: collecting sample image data by the image sensor; Obtaining a training sample data set based on the sample image data; Training an initial model using the training sample data set until the initial model meets a preset condition, thereby obtaining a focus model; Inputting a target array corresponding to the lens module to be tested into the focus model, and using the focus model to determine the absolute value of the distance and the relative direction between the current position of the image sensor and the focus position, including: after determining the position where the lens module to be tested is placed, obtaining a first position of the image sensor; controlling the image sensor to move to a second position having a preset distance from the first position through the mechanical motion structure; collecting sample image data through the image sensor, and obtaining a corresponding MTF curve based on the sample image data; obtaining a target array based on the MTF curve and the second position, inputting the target array into the focus model, and using the focus model to output the absolute value of the distance between the current position of the image sensor and the accurate focus position; and determining the relative direction based on the first position and the second position, wherein the absolute value of the distance between the second position and the first position is greater than the theoretical maximum focal length error of the lens module to be tested; The movement of the mechanical motion structure is controlled according to the absolute value of the distance and the relative direction.

2. The focusing method according to claim 1, wherein: The obtaining of a training sample data set based on the sample image data comprises: Obtaining a corresponding modulation transfer function (MTF) curve based on the sample image data; The training sample data set is obtained based on the MTF curve and the position of the image sensor.

3. The focusing method according to claim 1, wherein: Before training the initial model using the training sample data set, the focusing method further includes: The training sample dataset is divided into training set and test set.

4. The focusing method according to claim 3, wherein: Before dividing the training sample data set into a training set and a test set, the focusing method further includes: performing normalization processing on the data in the training sample data set.

5. The focusing method according to claim 3, wherein: Before dividing the training sample data set into a training set and a test set, the focusing method further includes: performing standardization processing on the data in the training sample data set.

6. The focusing method according to claim 3, wherein: Before dividing the training sample data set into a training set and a test set, the focusing method further includes: formatting the training sample data set.

7. A focusing device, characterized in that: The focusing device comprises: An acquisition module, configured to acquire sample image data through an image sensor; A processing module, configured to obtain a training sample data set based on the sample image data; A training module, configured to train an initial model using the training sample data set until the initial model meets a preset condition, thereby obtaining a focus model; The processing module is further configured to input a target array corresponding to the lens module to be tested into the focus model, and determine an absolute value of a distance and a relative direction between a current position of the image sensor and a focus position using the focus model, including: obtaining a first position of the image sensor after determining a position where the lens module to be tested is placed; controlling the image sensor to move to a second position having a preset distance from the first position through a mechanical motion structure; collecting sample image data through the image sensor, and obtaining a corresponding MTF curve based on the sample image data; obtaining a target array based on the MTF curve and the second position, inputting the target array into the focus model, and outputting an absolute value of a distance between the current position of the image sensor and an accurate focus position using the focus model; and determining the relative direction based on the first position and the second position, wherein the absolute value of the distance between the second position and the first position is greater than a theoretical maximum focal length error of the lens module to be tested; The processing module is further configured to control the movement of the mechanical motion structure according to the absolute value of the distance and the relative direction.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, the focusing method according to any one of claims 1 to 6 is implemented.

9. An electronic device, characterized in that: include: Memory, and A processor, wherein the processor executes computer-readable instructions stored in the memory to implement the focusing method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and system for testing batch focus of camera modules

    CN109451304A

  • Camera focusing method and focusing method based on recurrent neural network

    CN113747041A