Focusing method and device, medium and electronic equipment
By using a single image to predict the focus position, using the focus model to determine the position relationship of the image sensor and control the movement of the mechanical motion structure, the problems of long time and low accuracy of the traditional focus method are solved, and fast and accurate focus is achieved, which is suitable for the needs of modern and efficient production lines.
Patent Information
- Application Number
- CN202510494469.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-21
- Publication Date
- 2025-05-30
- Estimated Expiration
- 2045-04-21
AI Technical Summary
The traditional accurate focusing method takes a long time and requires a lot of computing resources. The accurate focusing accuracy is affected by the movement interval when scanning MTF curves or multiple images taken, making it difficult to meet the dual strict requirements of modern efficient production lines for speed and accuracy.
The focus position of the lens module to be tested is predicted through a single image, the image sensor is used to collect sample image data, the training sample data set is constructed based on the sample image data, the initial model is trained to obtain 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 is determined by using the focus model, and the movement of the mechanical motion structure is controlled to achieve fast and accurate focus.
It significantly improves focus speed and accuracy, reduces the consumption of computing resources, and can achieve accurate focus in a short time, which is suitable for the needs of modern and efficient production lines.
Smart Images

Figure CN120075614A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of artificial intelligence technology, relates to the field of optical system assembly technology, and particularly relates to a focusing method, device, medium, and electronic device. Background Art
[0002] In the current lens module assembly and imaging quality detection processes, accurately determining the position of the image sensor and the camera focal plane is crucial. The accuracy of this link not only directly affects the final imaging quality but also has a significant impact on the overall production efficiency.
[0003] There are mainly two common methods for traditional accurate focusing. One is to rely on continuously scanning the modulation transfer function (MTF) curves of the lens at different image distances to achieve accurate focusing; the other is to determine the accurate focusing position by taking multiple images and calculating the focus evaluation function. However, both of these methods have certain limitations. The above two accurate focusing methods often require a long time and a large amount of computing resources. Moreover, the accurate focusing accuracy is affected by the moving interval when scanning the MTF curve (or taking multiple images). In the same moving range, the smaller the moving interval, the higher the accurate focusing accuracy. But at the same time, the required time will also be longer. It can be seen that traditional accurate focusing methods usually result in too long accurate focusing time, thereby reducing the production efficiency. This situation is difficult to meet the dual strict requirements of speed and accuracy for modern high-efficiency production lines. Summary of the Invention
[0004] Embodiments of this application provide a focusing method, device, medium, and electronic device, which can predict the focusing position of a lens module to be measured through a single image, greatly improving the focusing speed and accuracy.
[0005] A first aspect of an embodiment of this application provides a focusing method, which is applied to an electronic device. The electronic device is communicatively connected to an image sensor and a mechanical motion structure. 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 a preset condition to obtain a focusing model; inputting a target array corresponding to the lens module to be measured into the focusing model, and using the focusing model to determine the absolute value of the distance and the relative direction between the current position of the image sensor and the focusing position; controlling the mechanical motion structure to move according to the absolute value of the distance and the relative direction.
[0006] According to an embodiment of the present application, the obtaining of the 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 with 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 using of the focusing model to determine the absolute value of the distance and the relative direction between the current position of the image sensor and the focusing position includes: after determining the position where the lens module to be measured 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 movement 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 focusing model, and using the focusing model to output the absolute value of the distance between the current position of the image sensor and the accurate focusing position.
[0011] A second aspect of the embodiments of the present application provides a focusing device, including: a collection module, configured to collect sample image data through the 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 through the training sample data set until the initial model meets a preset condition to obtain a focusing model; the processing module is further configured to input a target array corresponding to the lens module to be measured into the focusing model, and use the focusing model to determine the absolute value of the distance and the relative direction between the current position of the image sensor and the focusing position; the processing module is further configured to control the mechanical movement structure to move according to the absolute value of the distance and the relative direction.
[0012] A third aspect of the embodiments of the present application provides a computer-readable storage medium, which stores at least one instruction, and when the at least one instruction is executed by a processor, the above-mentioned focusing method is implemented.
[0013] A fourth aspect of an embodiment of the present application provides an electronic device, including: a memory and a processor, where the processor executes computer-readable instructions stored in the memory to implement the focusing method described above.
[0014] The focusing method provided by an embodiment of the present application collects sample image data through an image sensor in an 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 a preset condition to obtain a focusing model; inputs a target array corresponding to a lens module to be measured in the imaging quality detection system into the focusing model, and uses the focusing model to determine the absolute value of the distance and the relative direction between the current position of the image sensor and the focusing position, and controls a mechanical motion structure to move according to the absolute value of the distance and the relative direction to achieve fast and accurate focusing. Description of the Drawings
[0015] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0016] Figure 1 It is a schematic diagram of an application environment of a focusing method provided by an embodiment of the present application.
[0017] Figure 2 It is a schematic flowchart of the focusing method provided by an embodiment of the present application.
[0018] Figure 3 It is a schematic diagram of a picture collected when the image sensor is at a first image distance and the corresponding MTF curve provided by an embodiment of the present application.
[0019] Figure 4 It is a schematic diagram of a picture collected when the image sensor is at a second image distance and the corresponding MTF curve provided by an embodiment of the present application.
[0020] Figure 5 It is a schematic diagram of a picture collected when the image sensor is at a third image distance and the corresponding MTF curve provided by an embodiment of the present application.
[0021] Figure 6 It is a schematic block diagram of a focusing device provided by an embodiment of the present application.
[0022] Figure 7 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Detailed Embodiments
[0023] To make the objectives, technical solutions, and advantages of this application clearer, the following provides a detailed description of this application in conjunction with the accompanying drawings and specific embodiments.
[0024] It should be noted that in this application, "at least one" means one or more, and "a plurality" means two or more than two. "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone, where A and B can be singular or plural. The terms "first", "second", "third", "fourth", etc. (if any) in the specification, claims, and drawings of this application are used to distinguish similar objects, rather than to describe a specific order or sequence.
[0025] In the embodiments of this application, words such as "exemplary" or "for example" are used to represent examples, illustrations, or explanations. Any embodiment or design solution described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Rather, the use of words such as "exemplary" or "for example" is intended to present relevant concepts in a specific manner. Without conflict, the following embodiments and the features in the embodiments can be combined with each other.
[0026] Please refer to Figure 1 , which is a schematic diagram of the application environment of a focusing method provided by the embodiments of this application. Among them, this focusing method is applied to an imaging quality detection system. As Figure 1 shown, this imaging quality detection system includes a light source 1, a reticle 2, a lens module to be measured 3, an image sensor 4, a mechanical motion structure 5, and an electronic device 6. Among them, the image sensor 4 and the mechanical motion structure 5 are in telecommunication connection with the electronic device 6.
[0027] In some embodiments of this application, the light source 1 can generate a beam that meets the requirements. For example, a beam with a specific wavelength, and both the light intensity and uniformity of the beam meet certain requirements.
[0028] In some embodiments of the present application, the reticle 2 is an optical reticle, which is an auxiliary tool for measuring and dividing optical instruments and is used to provide a standard initial pattern. It is usually made of a transparent material and has scales and marks for assisting in precisely adjusting and calibrating optical instruments. The principle of the optical reticle is based on the interference and diffraction phenomena of light. When a light beam passes through the reticle, interference and diffraction occur, forming bright and dark fringes. The spacing and morphology of these fringes can provide important information about the performance of optical instruments. The optical reticle includes a linear reticle, a grid reticle, a circular reticle, etc. The linear reticle is one of the most common types of optical reticles and is used to measure the resolution and focusing performance of optical instruments. The linear reticle can be used to adjust optical instruments such as microscopes, telescopes, and lasers. The grid reticle is an optical reticle with a grid structure and is used to measure the distortion and deformation of optical instruments. It can be used to adjust optical instruments such as optical projectors and optical microscopes. The circular reticle is an optical reticle with circular scales and is usually used to measure the rotation and angular accuracy of optical instruments. It can be used to adjust optical turntables, optical gyroscopes, etc.
[0029] In some embodiments of the present application, the lens module 3 to be measured is an optical system, which can be composed of multiple lenses and is used to further focus and image the light beam modulated by the reticle 2. During this process, the optical characteristics (such as focal length, distortion, etc.) of the lens module 3 to be measured will affect the imaging result. Therefore, by analyzing the imaging result, the performance of the lens module 3 to be measured can be evaluated.
[0030] In some embodiments of the present application, the image sensor 4 is used to capture the optical image information after imaging by the lens module 3 to be measured and send 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 to be measured according to the image quality.
[0031] In some embodiments of the present application, the mechanical motion structure 5 is used to drive the image sensor 4 to move. After the electronic device 6 analyzes the image quality based on the optical image information, it can control the motion of the mechanical motion structure 5 according to the performance of the lens module 3 to be measured, adjust the position of the image sensor 4, so that the mechanical motion structure 5 moves 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 irradiates the reticle 2, the reticle 2 can modulate the light beam to form a specific standard initial pattern. Then, the modulated light beam is further focused and imaged by the lens module under test 3, and finally projected onto the image sensor 4. The image sensor 4 is used to capture the optical image information after imaging. 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 motion, 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 requirements, the detection system may further include other auxiliary optical elements, such as filters, relay lenses, etc., to further improve the system performance. The above structure will be adjusted according to actual requirements in the specific implementation manner, and the examples Figure 1 are not shown in detail.
[0034] In some possible scenarios, the electronic device 6 can also be network-connected to the image sensor 4 and / or the mechanical motion structure 5. The network can be wired network communication or wireless network communication. The wired network can be any one of a local area network, a metropolitan area network, and a wide area network, and the wireless network can be any one of Wireless Fidelity (Wi-Fi), ZigBee Wireless Networks (ZigBee), Ultra Wideband (UWB), Universal Serial Bus (USB), etc.
[0035] Figure 2 is a flowchart of the focusing method provided by the embodiments of the present application. As Figure 2 shown, the focusing method is applied to an electronic device. According to different requirements, the order of the steps in this flowchart can be changed, and some steps can be omitted.
[0036] Step S1, collect sample image data through the image sensor.
[0037] In the embodiments of the present application, Figure 1In the imaging quality detection system shown, the image sensor 4 is linked with the mechanical motion structure 5, and the mechanical motion structure 5 moves along the direction of the light beam generated by the light source 1. The position where the image sensor receives light to form an image is estimated according to the designed 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 movement range of the mechanical motion structure 5 can be the position range where the mechanical motion structure 5 enables the image sensor 4 to receive the sample image. While the mechanical motion structure 5 is moving, the sample images can be continuously and densely collected by the image sensor 4 to obtain sample image data, and the position information of the mechanical motion structure 5 corresponding to each collected sample image is recorded.
[0038] In the embodiment of the present application, by precisely designing the lens working distance, the position of the sample image formed by the image sensor 4 receiving the light beam generated by the light source 1 can be determined. Based on the lens working distance, the movement range of the mechanical motion structure 5 can be precisely determined to ensure that the image sensor 4 can always cover the position of the image plane during the movement, and ensure that the image sensor 4 can effectively receive the sample image at any point on the movement trajectory under the control of the mechanical motion structure 5.
[0039] Step S2: Obtain a training sample data set based on the sample image data.
[0040] In the embodiment of the present application, obtaining a training sample data set based on the sample image data includes: obtaining the corresponding 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.
[0041] Specifically, the collected sample image data is preprocessed, and the sample image data is input into the MTF calculation program to obtain the MTF curve of each sample image. Among them, the abscissa in the MTF curve represents the spatial frequency, with the unit of line pairs per millimeter (lp / mm), and the ordinate represents the modulation transfer function value, which is a dimensionless scalar, and its value is usually between 0 and 1. The MTF curve is sampled at equal intervals along the abscissa direction of the MTF curve to obtain an array including N elements. An array is associated with the position of the image sensor corresponding to the sample image corresponding to the array to obtain an array. Assuming that the number of collected sample images is M, then M sets of data are obtained for training and testing the neural network model. For example, the collected sample image is T1, and the position of the corresponding image sensor is P1. Based on the sample image T1, the MTF curve is obtained, and the MTF curve is sampled at equal intervals to obtain an array including 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, the first array {P1, N1, N2, N3... Ni} can be obtained. Then, based on M sample images, M sets of data can be obtained, and the M sets of data constitute the training sample data set.
[0042] In the embodiment of the present application, the sampling interval for sampling the MTF curve at equal intervals along the abscissa direction of the MTF curve is less than the maximum error value allowed for the focus of the lens module to be measured.
[0043] It should be noted that since the image sensor is clamped by a 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 can be the position of the mechanical motion structure.
[0044] Step S3, training the initial model with the training sample data set until the initial model meets the preset conditions to obtain the focus model.
[0045] In the embodiment of the present application, the initial model is a neural network for data regression problems. Among them, the structure of the initial model includes an input layer, a hidden layer, a pooling layer, a fully connected layer, and an output layer. Among them, the input layer is used to receive input data (for example, a training set), and represent the data in the training sample dataset in the form of an array (for example, including the data obtained by sampling the MTF curve and the position of the image sensor). The hidden layer contains several fully connected layers (Fully Connected Layer) or one-dimensional convolutional layers (1D Convolutional Layer), which are used to extract high-dimensional feature data from the array data; the pooling layer is used to reduce the dimension of the extracted feature values, reduce redundant information, and improve the 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, corresponding to the assembly error or adjustment amount of the centering optical element.
[0046] In the embodiment of the present application, before training the initial model with the training sample dataset, the focusing method further includes: dividing the training sample dataset into a training set and a test set.
[0047] In the embodiment of the present application, the training sample dataset can be randomly divided into a training set and a test set according to a preset ratio. Among them, the preset ratio can be 4:1 or 7:3. For example, 80% of the training sample dataset is divided into the training set, and 20% of the training sample dataset is divided into the test set. Among them, 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 dataset, it is necessary to ensure the randomness and uniformity of the division to avoid bias in certain feature values or target values in the dataset.
[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 influence of the dimensional difference of the feature values of the data in the training sample dataset on the training and improve 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: standardizing the data in the training sample dataset. To eliminate the influence of the dimensional difference of the feature values of the data in the training sample dataset on the training and improve the convergence efficiency of the model. For example, the data in the training sample dataset is processed into a standard normal distribution.
[0050] In some embodiments of the present application, 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 to construct the data in the sample data set into a data loading format suitable for a neural network framework (such as TensorFlow, PyTorch, etc.). For example, the data in the sample data set is processed into a tensor (Tensor) or a NumPy array. If the amount of data in the training sample data set is large, a data loader can be used to load it batch by batch, improving the training efficiency and reducing memory occupancy.
[0051] In some embodiments 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 data augmentation on the training sample data set to increase data diversity and improve the robustness of the model. For example, noise data can be added to the training sample data set, or the training sample data set can be expanded by methods such as random offset. It should be noted that if the existing training sample data set can be used to train the model, there is no need to perform data augmentation on the training sample data set. For example, the amount of data in the training sample data set is large enough.
[0052] In some embodiments of the present application, the preset condition includes that the loss value corresponding to the preset loss function is less than the preset loss threshold, and the preset loss function includes a regression loss function (such as mean square error, MSE). The weights of the loss function are modulated to minimize the error between the predicted value and the true value. The data input is passed into the network batch by batch in the form of an array, and iterative training is performed in combination with an optimization algorithm (such as Adam or SGD) until convergence.
[0053] In some embodiments of the present application, the training process of the focusing model can use a supervised training method. Specifically, the training method can include: iteratively updating and training the initial model using the data of the current batch in the training set; using the test set to determine whether the initial model updated each time reaches the preset condition. If the preset condition is not reached, the initial model is updated next time using the data of the next batch according to the optimization algorithm (such as the gradient descent algorithm); repeating the above steps until the initial model meets the preset condition. Among them, the preset condition can be that the loss value corresponding to the loss function is less than the preset loss threshold, the performance of the focusing model (such as accuracy, recall, etc.) reaches the preset performance threshold, the number of iterations of the model reaches the preset number threshold, etc. Among them, the above various thresholds can be set according to actual needs, and the present application does not make specific limitations on this.
[0054] Step S4, input the target array corresponding to the lens module to be measured into the focusing model, and use the focusing model to determine the absolute value of the distance and the relative direction between the current position of the image sensor and the focusing position.
[0055] In the embodiment of the present application, determining the absolute value of the distance and the relative direction between the current position of the image sensor and the focusing position by using the focusing model includes: after determining the position where the lens module to be measured is placed, obtaining the 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 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 focusing model, and using the trained focusing model to output the absolute value of the distance between the current position of the image sensor and the accurate focusing position.
[0056] Specifically, after the focusing model is trained, the focusing model can be used for focusing. During the process of focusing on the lens module 3 to be measured in the imaging quality detection system, generally, the lens module 3 to be measured has a theoretical focal length after being fixed-focus. When the position where the lens module 3 to be measured is placed 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. Control the image sensor to move to a second position X at a certain distance from the first position Z, collect sample image data through the image sensor, and obtain a corresponding MTF curve based on the sample image data; obtain a target array based on the MTF curve and the second position X, input the target array into the focusing model, and use the trained focusing model for inference to output the absolute value L of the distance between the current position of the image sensor and the accurate focusing position. Since both the first position Z and the corresponding second position X of the image sensor are known, the relative direction between the second position X and the first position Z can be obtained.
[0057] Step S5, controlling the mechanical motion structure to move according to the absolute value of the distance and the relative direction.
[0058] In the embodiment of the present application, controlling the mechanical motion structure 5 to move a distance L in the direction of the first position Z according to the absolute value of the distance and the relative direction can complete the accurate focusing operation.
[0059] It should be ensured that the absolute value of the distance between the second position X and the first position Z of the image sensor is greater than the theoretical maximum focal length error of the lens module to be measured to prevent misjudging the relative direction between the second position X and the first position Z.
[0060] In the embodiments of the present application, sample image data is collected by an image sensor in an imaging quality detection system; a training sample data set is obtained based on the sample image data; an initial model is trained by the training sample data set until the initial model meets a preset condition to obtain a focusing model; a target array corresponding to a lens module to be measured in the imaging quality detection system is input into the focusing model, and the absolute value of the distance and the relative direction between the current position of the image sensor and the focusing position are determined by using the focusing model, and the mechanical motion structure is controlled to move according to the absolute value of the distance and the relative direction. The focusing method disclosed in the present application associates the MTF curve corresponding to the sample image with the position of the image sensor to construct a training sample data set for training and testing; uses the constructed training sample data set to train the initial model and obtains a focusing model. The trained focusing model is deployed to a production system; the image sensor is moved to a second position X at a certain distance from the first position Z, sample image data is collected by the image sensor, and the corresponding MTF curve is obtained based on the sample image data; a target array is obtained based on the MTF curve, the target array is input into the focusing model, and the trained focusing 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 focusing position. According to 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 accurate focusing. Compared with the traditional method of continuously scanning MTF or calculating a focusing evaluation function through multiple images, the focusing method provided in the present application can complete focusing by collecting one picture, significantly reducing the consumption of computing resources, greatly shortening the time required for focusing, while ensuring higher focusing accuracy, greatly improving the focusing speed and accuracy, and having the advantages of convenient operation, high efficiency and reliability.
[0061] Figures 3 to 5 The figures show the pictures collected when the image sensor is at different image distances on the image side, and the MTF curves corresponding to each picture. By comparing the three groups of figures, it can be intuitively seen that MTF has an obvious feedback on the degree of deviation of the image sensor from the accurate focusing position. Exactly because of this, it is a current common practice to evaluate whether the image sensor reaches the accurate focusing position or evaluate the degree of the position of the image sensor away from the accurate focusing position according to the MTF curve. Among them, Figure 3 the MTF curve corresponding to (a) in Figure 3 is Figure 4 the one in (b); Figure 4 the MTF curve corresponding to (c) in Figure 5 is Figure 5 the one in (d); Figure 3 the MTF curve corresponding to (e) in Figure 4 is Figure 5 the one in (f). From Figure 3 the (a) in Figure 4 the (c) inFigure 5 As can be seen from (f) in Figure 3 (a) in Figure 4 (c) in Figure 5 and (e) in Figure 3 (b) in Figure 4 (d) in Figure 5 and (f) in
[0062] become increasingly blurred, Figure 6 and the area corresponding to the MTF curve corresponding to (b), (d), and (f) in
[0063] Another embodiment of the present application further provides an electronic device. Figure 1 The application environment of Figure 1 is only given as an example. In some other exemplary embodiments, the computer program product implementing the focusing method of the embodiments of the present application can also run on any electronic device with sufficient computing power (such as
[0064] Please refer to Figure 7 for a schematic structural diagram of an electronic device provided by an embodiment of the present application. As Figure 7 shown, in an 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 notebook computer, a netbook, etc. The specific type of the electronic device 6 is not limited in the embodiments of the present application.
[0065] As 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 respectively coupled to the communication module 101, the memory 102, and the I / O interface 104 through the bus 105.
[0066] Those skilled in the art can understand that the schematic diagram is only an example of the electronic device 6, and does not constitute a limitation on the electronic device 6. It may include more or fewer components than those shown, or combine some 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 of the solutions for wired communication such as Universal Serial Bus (USB), Controller Area Network (CAN), etc. The wireless communication module may provide one or more of the solutions for wireless communication such as Wireless Fidelity (Wi-Fi), Bluetooth (BT), mobile communication network, Frequency Modulation (FM), near field communication (NFC), Infrared (IR) technology, etc.
[0068] The memory 102 can be used to store computer-readable instructions and / or modules. The processor 103 realizes various functions of the electronic device 6 by running or executing the computer-readable instructions and / or modules stored in the memory 102, and by calling the data stored in the memory 102. The memory 102 may mainly include a program storage area and a data storage area. Among them, the program storage area may store an operating system, applications required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device 6, etc. The memory 102 may include non-volatile and volatile memories, such as: hard disk, memory, plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, at least one magnetic disk storage device, flash memory device, or other storage devices.
[0069] The memory 102 can be an external memory and / or an internal memory of the electronic device 6. Further, the memory 102 can be a memory in a physical form, such as a memory stick, a TF card (Trans-flash Card), and so on.
[0070] The processor 103 can be a Central Processing Unit (CPU), or can also be 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 the processor can also be any conventional processor, etc. The processor 103 is the operation core and control center of the electronic device 6, connecting all parts of the entire electronic device 6 through various interfaces and circuits, and executing the operating system of the electronic device 6 and various installed application programs, program codes, etc.
[0071] Exemplarily, the computer-readable instructions can be divided into one or more modules / sub-modules / units. One or more modules / sub-modules / units are stored in the memory 102 and executed by the processor 103 to complete the present application. One or more modules / sub-modules / units can be a series of computer-readable instruction segments capable of completing 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 can be divided into multiple modules of the above-mentioned 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 such an understanding, to implement all or part of the processes in the above-mentioned embodiment methods of the present application, it can also be completed by computer-readable instructions instructing relevant hardware. The computer-readable instructions can be stored in a computer-readable storage medium, and when the computer-readable instructions are executed by the processor, the steps of the above-mentioned various method embodiments can be implemented.
[0073] Among them, the computer-readable instructions include computer-readable instruction codes, which can be in the form of source code, object code, executable files, or some intermediate forms, etc. The computer-readable medium can include: any entity or device capable of carrying the computer-readable instruction codes, recording media, USB flash drives, external hard drives, magnetic disks, optical discs, computer memories, read-only memories (ROM, Read-Only Memory), and random access memories (RAM, Random Access Memory).
[0074] In combination 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 focusing method as Figure 2 shown.
[0075] Specifically, for the specific implementation method of the above computer-readable instructions by the processor 103, reference can be made to Figure 2 the description of the relevant steps in the corresponding embodiments, which will not be elaborated 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, a keyboard, a touch device, a display screen, etc., so that the user can input information or visualize the information.
[0077] The bus 105 is at least used to provide a communication channel between the communication module 101, the memory 102, the processor 103, and the I / O interface 104 in the electronic device 6.
[0078] In several embodiments provided in the present 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 only a logical function division, and there can be other division methods in actual implementation.
[0079] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0080] In addition, in each embodiment of the present application, the various functional modules can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above integrated unit can be implemented in the form of hardware or in the form of a combination of hardware and software functional modules.
[0081] Therefore, from any perspective, the embodiments should be regarded as exemplary and non-limiting. The scope of this application is defined by the appended claims rather than the above description. Thus, all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be encompassed by this application. Any reference signs in the claims should not be construed as limiting the claims concerned.
[0082] In addition, it is obvious that the term "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of elements or devices may also be implemented by one element or device through software or hardware. The terms first, second, etc. are used to denote names and do not denote any particular order.
[0083] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and not to limit them. Although this application has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of this application can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of this application.
Claims
1. A focusing method, applied to an electronic device, wherein the electronic device is communicatively connected with an image sensor and a mechanical motion structure, characterized in that: The method comprises: Collecting sample image data by means of the image sensor; Obtaining a training sample data set based on the sample image data; Training the initial model through the training sample data set until the initial model meets the preset conditions to obtain a focusing model; Inputting the target array corresponding to the lens module to be tested into the focus model, and using the 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; 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, characterized in that: 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, characterized in that: Before training the initial model using the training sample data set, the focusing method further includes: The training sample data set is divided into a training set and a test set.
4. The focusing method according to claim 3, characterized in that: Before dividing the training sample data set into a training set and a test set, the focusing method further includes: normalizing the data in the training sample data set.
5. The focusing method according to claim 3, characterized in that: 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, characterized in that: 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. The focusing method according to claim 6, characterized in that: Determining the absolute value and relative direction of the distance between the current position of the image sensor and the focus position by using the focus model 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 having a preset distance from the first position by the mechanical motion structure; Collecting sample image data by the image sensor, and obtaining a corresponding MTF curve based on the sample image data; A target array is obtained based on the MTF curve and the second position, the target array is input into a focus model, and the focus model is used to output an absolute value of a distance between a current position of the image sensor and an accurate focus position.
8. A focusing device, characterized in that: The focusing device comprises: An acquisition module, used for acquiring sample image data through the image sensor; A processing module, used for obtaining a training sample data set based on the sample image data; A training module, used for training an initial model through the training sample data set until the initial model meets a preset condition to obtain a focus model; The processing module is further used to input the target array corresponding to the lens module to be tested into the focus model, and use the 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; 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.
9. 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 7 is implemented.
10. 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 8.
Citation Information
Patent Citations
Detection method of camera module
CN107147907A
Method and system for testing batch focus of camera modules
CN109451304A
Camera focusing method and focusing method based on recurrent neural network
CN113747041A
Optical lens centering device, image acquisition device and method
CN116300129A
Assembly method and assembly equipment of camera module
CN117395483A