Focusing calibration algorithm and system for assembling camera lens by Monte Carlo tree search
By constructing a three-dimensional Monte Carlo tree search space and a local sharpness matrix, the physical configuration of the camera lens was optimized, solving the false peak problem caused by lens tilt and improving imaging quality and production efficiency.
Patent Information
- Application Number
- CN202511852604.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2045-12-10
AI Technical Summary
In the current camera lens assembly process, traditional one-dimensional focus calibration algorithms cannot identify and compensate for geometric anomalies caused by lens-sensor axis tilt, resulting in multi-peak characteristics of the sharpness evaluation function. The hill-climbing algorithm falls into the pseudo-peak trap, affecting image quality and production efficiency.
A three-dimensional Monte Carlo tree search space is constructed. Combining the lens focus position, horizontal tilt angle, and vertical tilt angle, the initial tilt angle is calculated through the local sharpness matrix. The upper confidence bound strategy is applied to optimize the lens physical configuration. The search tree is updated through backpropagation, and the optimal three-dimensional configuration is iteratively optimized.
It significantly improves the full field-of-view clarity of the camera, reduces the failure rate of edge area recognition, and ensures the consistency of imaging quality and the production capacity and product quality stability of automated production lines.
Smart Images

Figure CN121309800A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision technology, and more specifically, to a Monte Carlo tree search algorithm and system for camera lens assembly focus calibration. Background Technology
[0002] In automated camera module production, focus calibration, as a core step in ensuring image quality, directly determines the accuracy of barcode recognition and payment security of terminal devices such as vending machines. Existing technologies include Chinese patent application CN120147584A, which discloses a method and system for displaying 3D images based on indoor spatial positioning. This method uses multiple cameras to acquire head and facial coordinates, performs coordinate matching and transformation, and achieves accurate 3D image display. Chinese patent application CN105787892A discloses a Monte Carlo noise removal method based on machine learning. This method constructs a neural network to denoise Monte Carlo rendered images, significantly improving image quality during low-sample-rate rendering.
[0003] However, existing technologies still have significant shortcomings in camera focus calibration: when the lens-sensor axis is tilted, traditional one-dimensional focus calibration algorithms cannot identify and compensate for this geometric anomaly, resulting in the sharpness evaluation function exhibiting multi-peak characteristics. Specifically, when the lens is horizontally tilted, although the optical axis is not perpendicular to the sensor plane, the focal plane at a certain point on the optical axis may coincide with the sensor plane. Due to the tilt of the imaging plane, objects at different positions within the field of view are actually in different out-of-focus states. The sharpness evaluation function calculates the global sharpness index (such as gradient variance) for the entire image, allowing different combinations of focus positions and tilt angles to produce "seemingly optimized" global sharpness values, forming a "pseudo-peak" trap. Traditional hill-climbing algorithms get caught in these pseudo-peaks, while the original Monte Carlo Tree Search (MCTS) algorithm only operates in two-dimensional focus position space, completely ignoring the key degree of freedom of image plane tilt, and thus cannot find the true global optimum. For example, in the barcode recognition scenario of unmanned vending machines, when the focal plane of a batch of cameras is slightly tilted, resulting in multiple false peaks in the sharpness function, the hill-climbing algorithm will stabilize at the wrong suboptimal focus, which will significantly increase the failure rate of edge barcode recognition, and the imaging quality of the entire batch of cameras will be substandard, resulting in a decrease in product yield and an increase in rework costs, which will seriously restrict the production efficiency and product quality consistency of automated production lines. Summary of the Invention
[0004] This invention is applicable to mass production lines of automated camera modules, especially for camera assembly that requires full-field high-definition imaging, such as camera lens focusing calibration for scenarios like barcode recognition in unmanned vending machines, user behavior analysis at smart checkout counters, and defect identification in industrial vision inspection equipment. It can adapt to assembly tolerance differences between different batches of lens modules, ensuring consistent imaging quality under mass production.
[0005] To overcome the aforementioned deficiencies of existing technologies, this invention provides a Monte Carlo tree search algorithm and system for camera lens assembly focus calibration. The algorithm constructs a three-dimensional search space including focus position, horizontal tilt angle, and vertical tilt angle, and combines Monte Carlo tree search with an upper confidence bound strategy to simultaneously optimize the physical configuration of the lens. This effectively avoids the false peak trap caused by image plane tilt, significantly improving the full field-of-view clarity of the camera. By iteratively updating the search tree through backpropagation, the calibration cycle of a single camera can be shortened, while simultaneously reducing the failure rate of various visual recognition tasks in edge areas, such as barcode recognition and local defect detection, ensuring the production capacity and product quality stability of automated production lines.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] Monte Carlo tree search is used in camera lens assembly focus calibration algorithms, including:
[0008] A 3D search space supporting Monte Carlo tree search is constructed. An initial image of a high-contrast crosshair test pattern is acquired at the current position of the lens. The local sharpness index value of the initial image is calculated to generate a local sharpness matrix. The initial tilt angle is calculated based on the local sharpness matrix. Based on the local sharpness matrix and the initial tilt angle, the root node of the Monte Carlo tree is constructed in the 3D search space.
[0009] Starting from the root node of the Monte Carlo tree, the upper confidence bound strategy is applied to select the optimal search path. For nodes that are not fully expanded at the end of the optimal search path, new child nodes are generated in the three-dimensional search space. Lens physics adjustment is performed on the new child nodes and the comprehensive reward value is calculated. The Monte Carlo tree is updated through backpropagation. The process is iterated until the termination condition is met.
[0010] The Monte Carlo tree that has completed iterations is traversed to calculate the final score of each node. The optimal 3D configuration parameters are determined based on the final scores, and the camera is adjusted to the optimal 3D configuration based on the optimal 3D configuration parameters.
[0011] The method for constructing the three-dimensional search space includes:
[0012] The movable range of the lens is discretized into N position nodes, and the horizontal and vertical tilt angle adjustment ranges of the lens are discretized into M angle nodes respectively, thus constructing an N×M×M three-dimensional search space.
[0013] The method for generating the local sharpness matrix is as follows:
[0014] The initial image is divided into nine sub-regions of a 3×3 grid. The variance of the gradient magnitude of all pixels in each sub-region is calculated as the local sharpness index value of the sub-region, and a 3×3 local sharpness matrix is generated.
[0015] The initial tilt angle includes the initial horizontal tilt angle and the initial vertical tilt angle;
[0016] The calculation methods for the initial horizontal tilt angle and the initial vertical tilt angle include:
[0017] Spatial gradient analysis is performed on the local sharpness matrix to calculate the horizontal and vertical sharpness gradients. The horizontal sharpness gradient is converted into the initial horizontal tilt angle, and the vertical sharpness gradient is converted into the initial vertical tilt angle.
[0018] The method for constructing the root node of the Monte Carlo tree includes:
[0019] Locate the initial focus position Z0 of the current shot in the 3D search space; calculate the global sharpness index value and spatial sharpness difference index value of the root node based on the local sharpness matrix; calculate the tilt index value of the root node based on the initial horizontal tilt angle and the initial vertical tilt angle; set the difference penalty coefficient and tilt penalty coefficient of the root node.
[0020] The cumulative reward value of the root node is calculated based on its global sharpness index, spatial sharpness difference index, tilt index, difference penalty coefficient, and tilt penalty coefficient.
[0021] Initialize the number of visits to 1, divide the cumulative reward value by the number of visits to obtain the average reward value, and set the search depth to 0;
[0022] The root node of the Monte Carlo tree is constructed by integrating the initial focus position Z0, initial horizontal tilt angle, initial vertical tilt angle, global sharpness index value of the root node, spatial sharpness difference index value, tilt index value, number of visits, cumulative reward value, average reward value, and search depth.
[0023] The tilt index value is the sum of the absolute values of the initial horizontal tilt angle and the initial vertical tilt angle.
[0024] The method for selecting the optimal search path includes:
[0025] Set the root node of the Monte Carlo tree as the current search node, initialize the node sequence list and add the current search node to the node sequence list, create a search termination flag and set it to the non-terminating state;
[0026] Check the number of child nodes of the current search node, determine whether the current search node is a node that is not fully expanded, and set the search termination flag to the terminated state if the current search node is a node that is not fully expanded.
[0027] When the current search node is a fully expanded node, determine the next search node, add the next search node to the node sequence list, and update the current search node to the next search node;
[0028] Read the status of the search termination flag. If the search termination flag is in an unterminated state, continue to judge the updated current search node. If the search termination flag is in a terminated state, output the complete node sequence list as the optimal search path.
[0029] The method for determining the next search node includes:
[0030] Get all direct child nodes of the current search node, calculate the UCT value of the direct child nodes, compare the UCT values of all direct child nodes, and select the direct child node with the largest UCT value as the next search node.
[0031] The method for generating new child nodes is as follows:
[0032] When the optimal search path reaches a node that is not fully expanded, the spatial sharpness difference index value of the node is calculated. Based on the spatial sharpness difference index value of the node, a three-dimensional spatial expansion strategy is selected to generate a new child node in the three-dimensional search space.
[0033] The method for determining the optimal three-dimensional configuration parameters includes:
[0034] Traverse all nodes in the completed Monte Carlo tree, calculate the node stability and tilt risk factor for each node, calculate the final score based on the node's average return value, node stability, and tilt risk factor, select the node with the highest final score as the global optimal node, and record the optimal three-dimensional configuration parameters of the global optimal node; the optimal three-dimensional configuration parameters include the optimal focus position, the optimal horizontal tilt angle, and the optimal vertical tilt angle.
[0035] A Monte Carlo tree search system for camera lens assembly focus calibration is used to implement the aforementioned Monte Carlo tree search algorithm for camera lens assembly focus calibration. The system includes:
[0036] Root node construction module: Used to construct a 3D search space that supports Monte Carlo tree search. It acquires an initial image of a high-contrast crosshair test pattern at the current position of the lens, calculates the local sharpness index value of the initial image, and generates a local sharpness matrix; calculates the initial tilt angle based on the local sharpness matrix; and constructs the root node of the Monte Carlo tree in the 3D search space based on the local sharpness matrix and the initial tilt angle.
[0037] Iterative update module: It is used to select the optimal search path by applying the upper confidence bound strategy starting from the root node of the Monte Carlo tree. For the nodes that are not fully expanded at the end of the optimal search path, it expands them in the three-dimensional search space to generate new child nodes. It performs lens physics adjustment on the new child nodes and calculates the comprehensive reward value. It updates the Monte Carlo tree through backpropagation and iterates until the termination condition is met.
[0038] Optimal Configuration Module: Used to traverse the Monte Carlo tree after the iteration is completed, calculate the final score of each node, determine the optimal 3D configuration parameters based on the final score, and adjust the camera to the optimal 3D configuration based on the optimal 3D configuration parameters.
[0039] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0040] This invention overcomes the limitations of traditional one-dimensional focus search, which only focuses on the focal position, by constructing a three-dimensional search space that integrates the lens focus position and horizontal and vertical tilt angles. It comprehensively covers geometric anomalies caused by accumulated assembly tolerances and minor deformations of the mount during lens assembly, such as image plane tilt, avoiding the omission of the true optimal configuration due to missing dimensions. By accurately capturing the initial imaging state and calculating the initial tilt angle using a local sharpness matrix, it provides a reliable initial starting point for Monte Carlo tree search that closely matches the actual assembly situation, reducing invalid search paths. Furthermore, it achieves efficient selection of the optimal search path through an upper confidence bound strategy, while also leveraging existing high-quality nodes. By exploring potential high-quality nodes and combining the calculation of the comprehensive reward value after physical adjustment of new child nodes with backpropagation updates, the search process can be dynamically optimized and local pseudo-peaks can be avoided. Finally, the optimal 3D configuration is determined by traversing the tree to calculate the final score of the nodes, so that the lens is adjusted to the globally optimal state that balances focus accuracy and tilt correction. This significantly improves problems such as image blurring and insufficient sharpness in local areas (especially edge areas) caused by image plane tilt, ensures the consistency and sharpness of the camera's full field of view imaging, improves the accuracy and reliability of focus calibration, and adapts to the core requirements of calibration quality and efficiency for mass production of cameras. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 A flowchart illustrating the principle of the Monte Carlo tree search algorithm for camera lens assembly focus calibration provided in this embodiment of the invention;
[0043] Figure 2 A schematic diagram illustrating the principle of generating a local sharpness matrix according to an embodiment of the present invention;
[0044] Figure 3 A flowchart illustrating a method for performing an update operation on each node in a node sequence, provided by an embodiment of the present invention;
[0045] Figure 4 A flowchart illustrating the principle of determining the globally optimal node is provided in this embodiment of the invention.
[0046] Figure 5 This is a functional block diagram of a camera lens assembly focus calibration system provided in an embodiment of the present invention using Monte Carlo tree search. Detailed Implementation
[0047] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0048] Example 1
[0049] Please see Figure 1 As shown, this embodiment provides a Monte Carlo tree search algorithm for camera lens assembly focus calibration, including:
[0050] Step S10: Construct a three-dimensional search space that supports Monte Carlo tree search. Acquire an initial image of a high-contrast crosshair test pattern at the current position of the lens, calculate the local sharpness index value of the initial image, and generate a local sharpness matrix. Calculate the initial tilt angle based on the local sharpness matrix. Construct the root node of the Monte Carlo tree in the three-dimensional search space based on the local sharpness matrix and the initial tilt angle.
[0051] Further, step S10 includes:
[0052] Step S11: Discretize the movable range of the lens into N position nodes, and discretize the horizontal and vertical tilt angle adjustment range of the lens into M angle nodes respectively, to construct an N×M×M three-dimensional search space.
[0053] Step S11 aims to construct a standardized three-dimensional search space, providing a clear exploration boundary and quantitative basis for subsequent Monte Carlo tree search. The specific implementation process includes: based on the physical structural characteristics of the camera module, establishing a three-dimensional coordinate system with the image sensor center as the origin. The Z-axis is perpendicular to the image sensor plane and points towards the lens, and its direction is completely consistent with the axis of motion driven by the lens voice coil motor, ensuring that the Z-axis coordinates directly map the physical movement distance of the lens. The X-axis is parallel to the horizontal edge of the image sensor, and the Y-axis is parallel to the vertical edge. The directions of the X and Y axes are defined to match the mechanical degrees of freedom of the lens rotation around the axis when tilted, ensuring that changes in the horizontal and vertical tilt angles correspond to changes in the coordinate system's dimensions. The establishment of the three-dimensional coordinate system strictly follows the correspondence between the module's mechanical structure and the optical propagation path, ensuring that the calculation of all subsequent spatial parameters (such as focal position and tilt angle) can be directly related to the physical entity, avoiding calculation deviations caused by the disconnect between the three-dimensional coordinate system and actual hardware actions.
[0054] For the lens's movable range in the Z-axis direction, the discretization is based on the stroke specifications of the lens's voice coil motor. The stroke parameters of the voice coil motor are determined by the module design file and represent the maximum physically achievable movement range of the lens. When discretizing this range into N position nodes, the node spacing must meet two conditions: First, the node spacing should not be greater than the minimum step accuracy of the voice coil motor to ensure that the discretized nodes can cover all possible physical positions and cover all focal states without omission; second, the total number of nodes N should be controlled within a reasonable range to avoid redundant search space due to excessively large N, which would increase the computational burden. The adjustment range of the horizontal tilt angle θx and the vertical tilt angle θy is discretized based on the adjustment capability of the fine-tuning thread driven by the piezoelectric actuator or stepper motor. The mechanical precision of the fine-tuning thread determines the minimum adjustable increment of the tilt angle. When the adjustment range of the two tilt angles is discretized into M angle nodes, it is also necessary to ensure that the node spacing is not greater than the minimum adjustment precision of the fine-tuning thread, and the value of M must match the value of N on the Z-axis to make the discretization density in the three-dimensional space uniform and avoid the optimal solution falling in the node gap due to the nodes being too sparse in a certain dimension.
[0055] Through the above process, an N×M×M three-dimensional search space is ultimately constructed, which includes all possible combinations of focal position Z, horizontal tilt angle θx, and vertical tilt angle θy. Traditional focus calibration only limits the search range to the one-dimensional space of the Z-axis, completely ignoring the two key degrees of freedom of lens tilt. This leads to an inability to cover the true optimal configuration area when there is accumulated assembly tolerance or deformation of the mounting base. However, the three-dimensional search space constructed in this step, through physical mapping and discretization of the coordinate system, transforms the originally continuous and difficult-to-quantify three-dimensional state of the lens (position + tilt) into a finite set of discrete nodes. This allows the Monte Carlo tree search algorithm to systematically explore all potential optimal configurations with controllable computational resource consumption, rather than blindly traversing them.
[0056] The physical correlation of the three-dimensional coordinate system ensures that the parameters obtained from subsequent searches can be directly converted into hardware drive signals without additional coordinate transformation steps, reducing errors in the signal transmission process. Discretization transforms the continuous physical adjustment process into a search problem of discrete nodes, which not only adapts to the node expansion-based algorithm characteristics of Monte Carlo tree search, but also ensures the physical feasibility of the search results through matching the node spacing with hardware precision, avoiding situations where the optimal solution found by the algorithm exceeds the hardware adjustment capability. The comprehensive coverage of the three-dimensional search space breaks through the limitations of traditional one-dimensional search, making it possible to capture the optimal sharpness configuration across the entire field of view caused by tilt. Without step S11, the subsequent Monte Carlo tree search would lack a clear exploration boundary, either resulting in extremely low computational efficiency due to an excessively large search range, or missing the global optimal solution due to an excessively small range, and failing to establish a direct correlation between algorithm parameters and hardware actions, causing the entire calibration process to lose its physical basis. The three-dimensional search space provides a positioning framework for the initial focal position Z0, initial tilt angles θx0 and θy0 of the root node in step S14, ensuring that the root node can accurately fall within the search space, laying the starting foundation for the selection of subsequent search paths.
[0057] Step S12: Acquire an initial image of the high-contrast crosshair test pattern at the current position of the lens, calculate the local sharpness index value of the initial image, and generate a local sharpness matrix.
[0058] The method for generating the local sharpness matrix is as follows: the initial image is divided into nine sub-regions of a 3×3 grid, the variance of the gradient magnitude of all pixels in each sub-region is calculated as the local sharpness index value of the sub-region, and a 3×3 local sharpness matrix is generated.
[0059] The specific implementation process of step S12 includes: at the current position of the lens, i.e., the initial assembly position without any adjustment, controlling the camera to acquire an image of a preset high-contrast crosshair test pattern. The high-contrast crosshair pattern is chosen as the test source because it possesses two key characteristics: first, the grayscale changes drastically at the edges of the crosshair lines; in defocused or tilted states, the degree of blurring at the edges exhibits significant spatial differences, which can keenly reflect the imaging state of the optical system; second, the crosshairs cover both the center and edge areas of the image, and its imaging effect can simultaneously characterize the sharpness of the center and edges of the field of view, avoiding the deficiency that single-area testing cannot reflect the entire field of view. The brightness and contrast parameters of the test pattern need to be pre-calibrated to ensure that the pattern imaging maintains a stable grayscale dynamic range under different module batches of cameras, preventing the inability to identify sharpness differences due to insufficient signal from the pattern itself.
[0060] like Figure 2 As shown, after image acquisition is completed, the initial image is divided into nine sub-regions in a 3×3 grid pattern, including the upper left sub-region, upper middle sub-region, upper right sub-region, middle left sub-region, center sub-region, middle right sub-region, lower left sub-region, lower middle sub-region, and lower right sub-region. The grid was divided into 3×3 dimensions, rather than other dimensions (such as 2×2 or 4×4), primarily based on the following considerations: A 2×2 grid results in too few sub-regions, failing to accurately capture sharpness differences in different orientations (e.g., top left, top right, bottom left, bottom right), potentially missing local blur features caused by tilt; a 4×4 grid results in too many sub-regions, increasing subsequent computation, and the sharpness differences between adjacent sub-regions may be too small, exacerbating noise interference and reducing data reliability; a 3×3 grid covers the nine key orientations of the image—center, top, bottom, left, right, top left, top right, bottom left, and bottom right—comprehensively reflecting the sharpness distribution across the entire field of view, while achieving a balance between computational load and recognition accuracy, ensuring data processing efficiency and accuracy. During the division process, the boundaries of the sub-regions must be strictly aligned with the image pixel coordinates, and the number of pixels in each sub-region must remain consistent to avoid weight bias in sharpness calculation due to uneven factor region sizes.
[0061] The local sharpness index is calculated separately for each sub-region. The calculation process is as follows: For each pixel within the sub-region, the gray-level gradient in the horizontal and vertical directions is calculated. Mature edge detection algorithms such as the Sobel operator or Prewitt operator are used for gray-level gradient calculation. These algorithms can effectively extract the rate of change of pixel gray-level, and the magnitude of the rate of change directly corresponds to the sharpness of the line edges. The gradient magnitude of each pixel is calculated based on the gray-level gradient. The gradient magnitude is the square root of the sum of the squares of the horizontal and vertical gradients. The gradient magnitude integrates edge information from both directions, avoiding the problem that a single-direction gradient cannot fully reflect the edge state. The variance of the gradient magnitudes of all pixels is calculated, and the variance is used as the local sharpness index value of the sub-region. Variance is chosen as the sharpness index because it reflects the dispersion of the gradient magnitude: when the sub-region is sharp, the gradient magnitude of edge pixels is large, and the gradient magnitude of non-edge pixels is small, indicating a high degree of dispersion and a large variance value; when the sub-region is blurry, the difference in gradient magnitudes among all pixels is small, indicating a low degree of dispersion and a small variance value. This correspondence allows the variance to accurately quantify the sharpness level of the sub-region.
[0062] Arrange the local sharpness index values of the nine sub-regions according to their spatial location to form a 3×3 local sharpness matrix V= This method generates a local sharpness matrix, which directly presents the sharpness differences between different sub-regions. This difference is a direct optical manifestation of lens tilt. When the lens is horizontally tilted, there will be a significant difference in sharpness indices between the left and right sub-regions of the image; when there is a vertical tilt, there will be a significant difference in sharpness indices between the top and bottom sub-regions. This avoids the situation where traditional global sharpness indices, such as the full image gradient variance, average the sharpness of the entire image, and even if there is lens tilt causing the edges to be blurry while the center is sharp, it still shows a higher value, thus masking the tilt defect.
[0063] In step S12, the selection of a high-contrast crosshair pattern enhances the sensitivity to sharpness differences, allowing even minute tilts to be detected through variations in sharpness within sub-regions, thus improving the accuracy of subsequent tilt angle calculations. The combination of 3×3 grid division and variance index enables the quantification and spatial positioning of sharpness distribution, providing a structured data foundation for gradient analysis in step S13. Without this local sharpness matrix, step S13 would be unable to acquire sharpness difference data from different orientations, making it impossible to deduce the tilt angle. The entire calculation process is based on the optical characteristics of the image itself, eliminating the need for additional hardware such as tilt sensors, reducing module production costs, and avoiding measurement errors that may be introduced by hardware sensors. Furthermore, the generation process of the local sharpness matrix can reuse data with the global sharpness index value of the root node in subsequent step S14, reducing repetitive image acquisition and calculation steps and improving overall calibration efficiency. The X and Y axes established by the three-dimensional coordinate system correspond to the horizontal and vertical orientations of the 3×3 sub-regions. This ensures that the sharpness gradient calculations in the horizontal and vertical directions in subsequent step S13 match the dimensions of the coordinate system, guaranteeing a one-to-one correspondence between the derivation of the tilt angle and the spatial dimensions, thus avoiding directional confusion. Without this step, subsequent step S13 would lack the basis for calculating the initial tilt angle, leading to inaccurate initial state information of the root node. This would cause the Monte Carlo tree search to start from an incorrect point, ultimately failing to find the global optimum.
[0064] Step S13: The initial tilt angle includes the initial horizontal tilt angle and the initial vertical tilt angle. Perform spatial gradient analysis on the local sharpness matrix, calculate the horizontal sharpness gradient and the vertical sharpness gradient, convert the horizontal sharpness gradient into the initial horizontal tilt angle, and convert the vertical sharpness gradient into the initial vertical tilt angle.
[0065] The horizontal sharpness gradient is calculated as follows: First, calculate the average local sharpness index of the three left sub-regions in the local sharpness matrix (top left, middle left, and bottom left sub-regions). Then, calculate the average local sharpness index of the three right sub-regions (top right, middle right, and bottom right sub-regions). The difference between the two is the horizontal sharpness gradient. The logic behind this method is that when the lens is horizontally tilted, the optical axis is not perpendicular to the sensor plane, leading to a difference in object distance between the left and right sides of the image. This difference in object distance between the left and right sides causes a difference in sharpness between the left and right sub-regions, and the magnitude of this difference is quantified by the gradient value. Similarly, the vertical sharpness gradient is calculated as follows: First, calculate the average local sharpness index of the three upper sub-regions (top left, top middle, and top right sub-regions). Then, calculate the average local sharpness index of the three lower sub-regions (bottom left, bottom middle, and bottom right sub-regions). The difference between the two is the vertical sharpness gradient. The logic is the same as for the horizontal direction: vertical tilt leads to a difference in object distance between the upper and lower sub-regions, which manifests as a sharpness gradient.
[0066] After gradient calculation, the sharpness gradient needs to be converted into initial horizontal tilt angle θx0 and initial vertical tilt angle θy0. The conversion process relies on a pre-calibrated mapping relationship between the sharpness gradient and the tilt angle. This mapping relationship is established through offline experiments. The specific calibration process is as follows: Select a camera module of the same model as the mass-produced batch as the calibration sample to ensure that the optical and mechanical characteristics of the sample are consistent with the mass-produced product; fix the calibration sample on a precision angle adjustment platform, which can accurately control the tilt angle of the lens around the X and Y axes. The angle control accuracy is higher than that of the mass-produced fine-tuning mechanism, ensuring the accuracy of the calibration angle; under different known tilt angles, control the calibration sample to acquire images of high-contrast crosshair test patterns, and calculate the corresponding horizontal and vertical sharpness gradient values according to the method in step S12; pair each known tilt angle with the corresponding sharpness gradient value to form a dataset. Based on the dataset, establish a lookup table or fitting function, such as linear fitting or polynomial fitting, which is the mapping relationship between the sharpness gradient and the tilt angle. Lookup tables are suitable for scenarios where the gradient and angle have a non-linear relationship, allowing direct lookup of the corresponding angle through the gradient value; fitting functions are suitable for scenarios with linear or approximately linear relationships, allowing angle values to be quickly obtained through function calculation. The specific choice of which form to use depends on the distribution characteristics of the calibration dataset.
[0067] Substituting the calculated horizontal sharpness gradient value into the mapping relationship between sharpness gradient and tilt angle, the corresponding initial horizontal tilt angle θx0 can be output; similarly, inputting the vertical sharpness gradient value into the mapping relationship, the corresponding initial vertical tilt angle θy0 can be output. Traditional focus calibration cannot determine the initial tilt angle of the lens and can only start the search based on the default assumption of "no tilt." If tilt actually exists, the search starting point deviates significantly from the true initial state, causing subsequent algorithms to either get stuck in spurious peaks or spend a lot of time traversing irrelevant regions, severely impacting calibration efficiency and accuracy. This step, however, derives the initial tilt angle through optical features, obtaining accurate initial state information without relying on additional hardware. This invention derives the tilt angle through gradient analysis of the local sharpness matrix, utilizing the optical characteristics of the imaging system itself. This avoids the increased hardware costs and space occupation caused by installing an additional tilt sensor, while eliminating measurement deviations caused by assembly errors between the sensor and the camera module. The mapping relationship established through offline calibration ensures the accuracy of gradient and angle conversion. The calibration process uses samples and test conditions consistent with mass production, allowing the mapping relationship to adapt to individual differences in different batches of modules, thus improving the reliability of the initial angle calculation. The initial tilt angle provides key angle parameters for constructing the root node in step S14, ensuring that the state of the root node (Z0, θx0, θy0) accurately reflects the actual initial assembly state of the lens. This prevents subsequent searches from starting from an incorrect point, significantly reducing invalid search paths and improving the convergence speed of the Monte Carlo tree search. The initial horizontal tilt angle θx0 and initial vertical tilt angle θy0 calculated in step S13, together with the initial focal position Z0 obtained in step S14, constitute the three-dimensional state parameters of the root node, ensuring the integrity of the root node's state information and providing an accurate initial basis for the search path selection in the subsequent step S20. Without this step, the root node constructed in step S14 will lack the tilt angle parameter and will default to zero. In this case, the root node's state will deviate from the actual initial state. During subsequent searches, the algorithm will need to spend a large number of iterations exploring the unknown regions of the tilt angle dimension, not only prolonging calibration time but also potentially preventing convergence to the global optimum due to excessive initial deviation. Furthermore, the gradient calculation method in this step strictly corresponds to the orientation of the three-dimensional coordinate system constructed in step S11: the horizontal gradient corresponds to the X-axis tilt, and the vertical gradient corresponds to the Y-axis tilt, ensuring that the tilt angle dimension is consistent with the search space dimension and avoiding dimensional confusion during subsequent searches.
[0068] Step S14: Based on the local sharpness matrix, the initial horizontal tilt angle, and the initial vertical tilt angle, construct the root node of the Monte Carlo tree in the three-dimensional search space.
[0069] Further, step S14 includes:
[0070] Step S141: Locate the initial focus position Z0 of the current lens in the three-dimensional search space;
[0071] Step S142: Calculate the global sharpness index value and spatial sharpness difference index value of the root node based on the local sharpness matrix.
[0072] Step S143: Calculate the tilt index value of the root node based on the initial horizontal tilt angle and the initial vertical tilt angle;
[0073] Step S144: Set the difference penalty coefficient and skew penalty coefficient for the root node;
[0074] Step S145: Calculate the cumulative reward value of the root node based on the global sharpness index value, spatial sharpness difference index value, tilt index value, difference penalty coefficient, and tilt penalty coefficient of the root node.
[0075] Step S146: Initialize the number of visits to 1, divide the cumulative reward value by the number of visits to obtain the average reward value, and set the search depth to 0;
[0076] Step S147: Integrate the initial focus position Z0, initial horizontal tilt angle, initial vertical tilt angle, global sharpness index value of the root node, spatial sharpness difference index value, tilt index value, number of visits, cumulative reward value, average reward value and search depth, initialize the number of tilt-sensitive child nodes to 0, and construct the root node of the Monte Carlo tree.
[0077] Specifically, the position of the lens in the Z-axis direction of the three-dimensional coordinate system is obtained by reading the position encoder of the voice coil motor. The position encoder of the voice coil motor is a high-precision feedback element that is standard on the lens module. Its resolution matches the minimum step accuracy of the voice coil motor, and it can output the physical position coordinates of the lens on the Z-axis in real time. The reading process establishes communication between the module's control system and the position feedback interface of the voice coil motor, mapping the raw position data output by the encoder to the Z-axis of the three-dimensional coordinate system to obtain the initial focus position Z0. This method directly associates the physical position of the lens with the three-dimensional coordinate system through the real-time feedback of the position encoder, ensuring the accuracy of Z0 and providing a reliable starting point for the focus position in subsequent searches. This avoids the deviation caused by the default initial focus position of "mechanical midpoint" or "zero position" in traditional focus calibration, which may not match the actual initial optical focus position.
[0078] The global sharpness index is the weighted average of nine index values in the local sharpness matrix. The weight coefficient for the central sub-region is set to 0.3, while the weights for the other eight edge and semi-edge sub-regions are each set to 0.0875. The weighting is based on the following principle: in most imaging scenarios, such as face recognition and barcode recognition, the central image region carries core information and has higher sharpness requirements, hence it is given a higher weight; edge regions are weighted equally to ensure that information across the entire field of view is not ignored. The calculation first multiplies the local sharpness index value of each sub-region by its corresponding weight, and then sums them to obtain the global sharpness index value. The spatial sharpness difference index is the standard deviation of the nine local sharpness index values. The standard deviation quantifies the dispersion of the data and directly reflects the uniformity of sharpness across all sub-regions in the entire field of view. A smaller standard deviation indicates less sharpness difference between regions and a more uniform image; conversely, a larger standard deviation indicates significant sharpness unevenness, possibly caused by tilt. This method combines global sharpness index values with spatial sharpness difference index values to form a comprehensive assessment of image quality. The global sharpness index value ensures that the sharpness of the core area is given priority, while the spatial sharpness difference index value supplements the quantification of uniformity. This avoids the shortcomings of traditional global sharpness indexes, such as simple average values, which cannot distinguish between "sharp center and blurry edge" and "uniform sharpness across the entire field of view".
[0079] The tilt index is the sum of the absolute values of the initial horizontal tilt angle θx0 and the initial vertical tilt angle θy0, i.e., tilt index = |θx0| + |θy0|. The reason for using the sum of absolute values is that the impact of tilt on imaging is only related to the degree of tilt, and not to the tilt direction (e.g., whether θx0 is positive or negative). The absolute value can eliminate directional interference. Summation integrates the tilt of the two dimensions into a single quantitative index, facilitating subsequent calculations in conjunction with the penalty coefficient and simplifying the parameter processing flow. This method, by using the sum of the absolute values of the initial horizontal tilt angle θx0 and the initial vertical tilt angle θy0 as the tilt index, provides a quantitative basis for the tilt dimension in subsequent cumulative reward value calculations, avoiding misjudgments of tilt risk by the algorithm due to unknown tilt degree, and achieving effective quantification of the initial tilt degree.
[0080] The difference penalty coefficient is set according to the clarity and uniformity requirements of the application scenario: for scenarios with high requirements for uniformity across the entire field of view, such as barcode recognition, where edge barcodes need to be clear, a higher coefficient value is used; for scenarios with high focus on the central area and lower requirements for the edges, such as face recognition, where core information is concentrated in the center of the face, a lower coefficient value is used. The tilt penalty coefficient is set according to the tilt tolerance of the mechanical structure: if the tilt adjustment mechanism has poor long-term stability, such as a fine-tuning screw that is prone to backing back due to vibration, a higher coefficient value is used to limit the tilt angle; if the mechanism is stable and reliable, such as a piezoelectric actuator that has no risk of backing back, a lower coefficient value is used to retain more adjustment space. By setting scenario-based coefficients, the calculation of the cumulative reward value can be made to fit actual needs, improving the versatility and practicality of the algorithm. For example, the setting basis and values of the two coefficients are shown in Table 1:
[0081] Table 1. Example of the basis for setting the difference penalty coefficient and the tilt penalty coefficient.
[0082] coefficient type Setting basis Application scenario examples Example values Difference penalty coefficient Full field of view sharpness uniformity requirements Barcode recognition 2.0 Difference penalty coefficient Full field of view sharpness uniformity requirements Facial recognition 0.5 Tilt penalty coefficient Long-term stability of tilt adjustment mechanism Poor institutional stability 10.0 Tilt penalty coefficient Long-term stability of tilt adjustment mechanism Stable and reliable mechanism 2.0
[0083] The cumulative reward value = global sharpness index value − (spatial sharpness difference index value × difference penalty coefficient) − (tilt index value × tilt penalty coefficient). The formula's design logic is as follows: the global sharpness index value is a positive contribution; a higher value indicates a sharper overall image. The spatial sharpness difference index value and tilt index value are negative deductions. By multiplying them by their corresponding penalty coefficients, the negative impact of uneven sharpness and tilt on image quality is quantified. The higher the difference penalty coefficient, the more significant the deduction for uneven sharpness; the higher the tilt penalty coefficient, the more significant the deduction for tilt. This method guides the algorithm to prioritize a configuration of "high global sharpness, uniform sharpness, and low tilt" through multi-index weighted calculation, laying the foundation for avoiding false peaks at the root node level. This avoids the situation where traditional algorithms, which only optimize global sharpness, easily fall into the trap of "sharp center and blurry edges" false peaks.
[0084] The number of visits is initialized to 1, as the root node is in its initial state and one state evaluation has been completed. The average reward value is the ratio of the cumulative reward value to the number of visits, providing initial statistical data for the UCT strategy in subsequent step S21 (which needs to be calculated based on the average reward value). The search depth is set to 0, as the root node is the starting point of the search tree and has no parent nodes. This method ensures that the subsequent UCT strategy can correctly calculate the selection priority of nodes through parameter initialization, providing data support for search path selection and avoiding the situation where the MCTS (Monte Carlo Tree Search) algorithm cannot start the search due to a lack of initial statistical parameters. In step S147, the number of tilt-sensitive child nodes is initialized to 0, as the root node has not yet expanded its child nodes, and there is no need to record tilt-sensitive child nodes. All parameters are integrated to ensure that the root node contains three-dimensional state (position + tilt), performance indicators (clarity, uniformity, tilt), and search statistics (number of visits, reward value, depth), forming a complete initial state package. Through comprehensive parameter integration, the subsequent search process can be carried out based on the complete initial state, avoiding deviations in the search direction due to missing information.
[0085] In the initial stage of Monte Carlo tree search, the root node lacks three-dimensional state parameters, performance evaluation indicators, and search statistics, leading to a large deviation between the search starting point and the actual initial state. This can easily result in falling into false peaks or traversing invalid regions. By obtaining Z0 and calculating the tilt index, the initial state of the lens is expanded from the traditional "one-dimensional position" to "three-dimensional position + tilt." Combined with the sharpness index in step S142, a multi-dimensional and accurate characterization of the initial state is achieved, avoiding search inefficiency caused by a blurred initial state. Through the spatial sharpness difference in step S142 and the cumulative reward value calculation in step S145, the optimization objective is upgraded from "single global sharpness" to "global sharpness + uniformity + low tilt," avoiding false peaks from the algorithm logic level. The multi-dimensional optimization objective enables the calibrated module to adapt to more complex imaging scenarios. For example, the same module can be used for barcode recognition (requiring uniform sharpness) or face recognition (requiring center sharpness), requiring only adjustment of the penalty coefficient, thus improving the module's scene adaptability and reusability. By integrating all parameters in step S147, the root node becomes an integrated unit that includes physical state, performance indicators, and search statistics, ensuring that the subsequent child node expansion and backpropagation in step S20 can be carried out based on a unified parameter system.
[0086] Step S10 comprehensively addresses the core problem of traditional focus calibration algorithms lacking a reliable starting point, having low search efficiency, and being prone to spurious peaks due to the inability to accurately obtain the three-dimensional initial state (position + tilt) of the lens relative to the image sensor caused by the accumulation of assembly tolerances and minor deformation of the lens mount during camera module assembly. This is achieved through the synergy of steps S11-S14, forming a complete technical chain: Step S11 establishes a three-dimensional coordinate system matching the physical structure, discretizing the lens's movable range and tilt adjustment range into N×M×M nodes, with the node spacing matching the hardware precision, thus solving the problem that the traditional one-dimensional search space cannot cover the tilt dimension and misses the optimal solution; Step S12 acquires high-resolution... The crosshair image is compared, divided into 3×3 sub-regions, and the local sharpness is quantified by variance to form a local sharpness matrix. The crosshair edge sensitivity is used to capture differences, balancing accuracy and computational load, and solving the problem of traditional global sharpness indicators masking tilt defects. Step S13 analyzes the horizontal / vertical gradient of the local sharpness matrix and combines it with the offline calibration mapping relationship to convert the optical gradient into the initial tilt angle, eliminating the need for additional sensors and reducing hardware costs and assembly errors. Step S14 integrates the 3D initial state, multi-dimensional performance indicators, and search statistical parameters, and constructs an integrated root node based on the cumulative reward value formula, providing a complete initial starting point for the MCTS algorithm. S10 makes the 3D initial state change from blurry to quantifiable and controllable, eliminating invalid search iterations; it eliminates the need for additional sensors, reducing hardware costs, and the parameters can be configured to adapt to multiple module models. Without S10, the tilt dimension cannot be optimized, tilt defects cannot be detected, the MCTS algorithm cannot start, and the final module image is blurry with low edge sharpness, resulting in a significant decrease in production line yield and efficiency.
[0087] Step S20: Starting from the root node of the Monte Carlo tree, apply the upper confidence bound strategy to select the optimal search path. For the nodes that are not fully expanded at the end of the optimal search path, expand them in the three-dimensional search space to generate new child nodes. Perform lens physics adjustment on the new child nodes and calculate the comprehensive reward value. Update the Monte Carlo tree through backpropagation. Iterate until the termination condition is met.
[0088] Further, step S20 includes:
[0089] Step S21: Starting from the root node of the Monte Carlo tree, use the upper confidence bound strategy to form the optimal search path and record the node sequence on the optimal search path;
[0090] Further, step S21 includes:
[0091] Step S211: Set the root node of the Monte Carlo tree as the current search node, initialize the node sequence list and add the current search node to the node sequence list, create a search termination flag and set it to the non-termination state;
[0092] Step S212: Check the number of child nodes of the current search node, determine whether the current search node is a node that is not fully expanded, and set the search termination flag to the termination state if the current search node is a node that is not fully expanded.
[0093] Step S213: When the current search node is a fully expanded node, obtain all direct child nodes of the current search node and read the access count of the current search node as the access count of the parent node.
[0094] Step S214: For each direct child node, extract the average reward value of the direct child node and the number of visits to the direct child node, and substitute the number of visits to the parent node, the average reward value of the direct child node, and the number of visits to the direct child node into the upper confidence bound formula to calculate the UCT value of the direct child node.
[0095] Step S215: Compare the UCT values of all direct child nodes, select the direct child node with the largest UCT value as the next search node, add the next search node to the node sequence list and update the current search node as the next search node;
[0096] Step S216: Read the status of the search termination flag. If the search termination flag is in an unterminated state, return to step S212 to continue judging the updated current search node. If the search termination flag is in a terminated state, output the complete node sequence list as the optimal search path.
[0097] Step S211 calls the 3D configuration parameters (Z0, θx0, θy0) and statistical parameters stored in the root node to ensure that the current search node is consistent with the initial modeling state. The statistical parameters include the number of visits and the average reward value. The node sequence list adopts a linear storage structure. Each storage unit records the unique identifier of the node, the 3D configuration parameters (focal position, horizontal tilt angle, vertical tilt angle), and the statistical parameters (number of visits, cumulative reward value, average reward value, number of tilt-sensitive child nodes). Its design aims to completely retain the information of all nodes on the search path, providing the parent node basis for the child node expansion in the subsequent step S22, and providing a clear update path for the backpropagation in step S25. The search termination flag is a Boolean variable, initially set to "not terminated" to start the loop. Its state switching will be determined by whether the subsequent node is an incompletely expanded node. This design controls the search process through simple logic to avoid loop redundancy or interruption. This method enables direct path retrieval through real-time storage of the node sequence list, reducing redundant calculations and ensuring path integrity. It avoids the drawbacks of traditional search paths, which lack a clear recording mechanism and can only select child nodes in real time without being able to backtrack the complete path, leading to increased computational load when expanding or updating the tree structure again.
[0098] A node that is not fully expanded is defined as one whose actual number of child nodes is less than the preset maximum number of child nodes. The maximum number of child nodes is determined by considering the discrete density of the 3D search space constructed in step S11 and the hardware's adjustment capabilities. If the Z-axis is discrete into N nodes and θx / θy into M nodes each, the maximum number of child nodes must cover the critical adjacent configurations of the current node within the range of ±1 step along the Z-axis, ±1 step along θx, and ±1 step along θy. For example, it can be set to 5-9, ensuring no critical configurations are missed while avoiding excessive child nodes that could overload computational resources. The judgment process requires reading the actual number of child nodes of the current node. If the actual number of child nodes is less than the preset maximum number of child nodes, it is determined to be an incompletely expanded node, and the termination flag is switched; otherwise, it is a fully expanded node. Traditional algorithms only judge based on the presence of child nodes, ignoring whether the child nodes cover critical areas. This results in some nodes having child nodes but not covering potentially efficient configurations, requiring further expansion. This step, through the quantitative constraint of the maximum number of child nodes, ensures the necessity of expanding incompletely expanded nodes and avoids ineffective expansion.
[0099] The acquisition of direct child nodes is achieved through the child node pointer list stored in the current node. This list records the unique identifiers of all direct child nodes, ensuring no omissions or duplicates. The parent node access count is retrieved by calling the statistical value of the current node after initialization in step S14 (access count = 1) and updating in step S25 (incrementing by 1 with each backpropagation). The average reward value of a direct child node is extracted from the statistical results of that node after steps S14 (average reward value = cumulative reward value / access count) and S25 (recalculated after updating the cumulative reward value and access count). This value quantifies the past imaging performance of the child node. The access count of a direct child node is also a real-time value updated in S25, reflecting the extent of exploration of the child node. The UCT value calculation formula is: ,in: For the utilization term, a higher value indicates that the 3D configuration corresponding to the child node has better past imaging performance, guiding the algorithm to prioritize verified high-return nodes; C is the exploration coefficient, which is set according to the complexity of the search space and computational resources. The higher the dimension of the search space, such as the larger the values of N and M, the larger the value of C to enhance the exploration capability. For example, when the total number of nodes in the 3D search space is 1000-5000, C can be set to 1.0-2.0 to ensure a balance between sufficient exploration and computational efficiency. For the exploration term, the parent node visit count is the total number of times the parent nodes of the direct child node i are visited, reflecting the overall exploration frequency of this branch; the direct child node i visit count is the number of times the direct child node i itself is visited, and the fewer the visits, the less fully explored the node is. The larger the exploration term value, the higher the weight the algorithm assigns to the insufficiently explored nodes, avoiding premature convergence to local pseudo-peaks. Traditional hill-climbing algorithms rely only on gradient ascent (without exploration), and the original MCTS relies on random selection (without quantized utilization). However, the UCT formula, through the quantized calculation of "utilization term + exploration term", makes the path selection based on both historical performance and potential value, which meets the global optimization requirements of the three-dimensional search space.
[0100] The comparison of UCT values employs a successive traversal of direct child nodes, recording the maximum value and corresponding child node identifier in each comparison to ensure the selection of a unique child node with the largest UCT value. If multiple child nodes have equal UCT values, a tie is broken by randomly selecting one. This random selection is based on the principle that equal UCT values indicate these nodes are at an equal level in terms of "exploitation-exploration" balance, and random selection avoids the algorithm getting stuck in fixed branches, improving the comprehensiveness of the exploration. Adding the next search node to the node sequence list continuously improves the search path record, ensuring that the final output sequence covers all nodes from the root node to the incompletely expanded node. Updating the current search node as the next search node initiates the next round of the "judging node expansion status - calculating UCT value - selecting child node" loop until the incompletely expanded node is found. Traditional algorithms either only select the best-performing node, ignoring exploration, or only select the unknown node, ignoring exploitation. This step selects the node with the largest UCT value, ensuring that each selection considers both "known advantages" and "potential advantages," increasing the probability of discovering the globally optimal path. The reading of the search termination flag must be synchronized in real time with the state switching result of step S212 to ensure that the loop terminates precisely when an incompletely expanded node is found, avoiding excessive iteration. The output node sequence list must include the three-dimensional configuration parameters, statistical parameters (number of visits, average reward value), and parent-child relationships of each node. This information provides a clear parent node for the child node expansion in step S22, i.e., the last node of the sequence, and also provides a complete update path for the backpropagation in step S25 (tracing back from the last node of the sequence to the root node). Traditional algorithms often use a fixed number of iterations as the termination condition, which may lead to the failure to find expandable nodes or premature termination. However, this step uses "finding an incompletely expanded node" as the termination condition, ensuring that the path selection is directly connected to subsequent expansion, thus improving search efficiency.
[0101] Step S22: When the optimal search path reaches a node that is not fully expanded, calculate the spatial sharpness difference index value of the node that is not fully expanded, select a three-dimensional spatial expansion strategy based on the spatial sharpness difference index value of the node that is not fully expanded, and generate a new child node in the three-dimensional search space; initialize the number of tilt-sensitive child nodes of the new child node to 0.
[0102] The core of step S22 is to dynamically adjust the expansion direction based on the imaging state (sharpness uniformity) of the incompletely unfolded node, thereby improving the search targeting. The spatial sharpness difference index value of the incompletely unfolded node is obtained when the node is generated: first, a high-contrast crosshair image under the lens configuration corresponding to the node is acquired, the image is divided into 3×3 sub-regions, the variance of the pixel gradient magnitude of each sub-region is calculated to form a local sharpness matrix, and then the standard deviation of the nine local sharpness index values in the matrix is calculated. This standard deviation is the spatial sharpness difference index value of the node. An expansion strategy is selected based on the spatial sharpness difference index value of the incompletely unfolded node: the first is the tilt correction mode, which is preferentially activated when the spatial sharpness difference is greater than the preset difference threshold. The setting of this difference threshold is based on the requirements of the application scenario for sharpness uniformity and is determined through offline experiments. Images are acquired at different tilt angles, the spatial sharpness difference is calculated, and the critical value that causes the edge area sharpness to drop to the point that it cannot meet the application requirements, such as barcode recognition failure, is recorded. This critical value is used as the difference threshold. When this mode is enabled, the focal position Z of the node remains unchanged, and only the horizontal tilt angle θx or the vertical tilt angle θy is adjusted. The adjustment direction must be based on the tilt index value of the node: if the absolute value of the horizontal sharpness gradient is greater than that of the vertical direction, θx is adjusted first; otherwise, θy is adjusted first, ensuring that the adjustment directly addresses the root cause of uneven sharpness. The second mode is the focus-priority mode, which is enabled first when the spatial sharpness difference is less than the preset difference threshold. At this time, the sharpness uniformity has met the basic requirements, and the focus should be on optimizing the global sharpness. When this mode is enabled, the θx and θy of the node remain unchanged, and the lens is moved only in the Z-axis direction. The movement step size is the Z-axis node spacing set in step S11, ensuring that each movement corresponds to a discrete node and avoiding skipping nodes, which would cause the optimal solution to be missed. The third mode is a hybrid adjustment mode, enabled under specific conditions. For example, when the spatial sharpness difference is near the difference threshold (e.g., 90%-110% of the threshold), and the node's global sharpness is lower than 80% of the highest global sharpness found in the search tree, it indicates that simply correcting the tilt or adjusting the focus cannot significantly improve performance, and synergistic optimization is required. The highest global sharpness found in the search tree needs to be stored in real-time in the global parameter area of the Monte Carlo tree. Each time a new node is generated and its global sharpness index value is calculated, if this value is higher than the currently stored highest global sharpness, the highest value in the global parameter area is updated to ensure real-time parameter accuracy. When this mode is enabled, the focus position Z and a tilt angle are adjusted simultaneously to achieve synergistic improvement.Tilt correction mode can quickly improve sharpness unevenness and avoid the algorithm from continuously exploring the pseudo-peak area of "sharp center and blurry edge", laying a uniform foundation for subsequent focus optimization; focus priority mode focuses on adjusting the Z-axis when sharpness is uniform, avoiding unnecessary tilt adjustment that causes mechanical wear and extending the life of the adjustment mechanism; hybrid adjustment mode can cope with complex imaging conditions (such as the coexistence of tilt and defocus) and overcome the performance bottleneck of single adjustment through collaborative optimization, discovering the optimal configuration that traditional strategies cannot capture.
[0103] After a new child node is generated, its access count and cumulative reward value need to be initialized to 0: 0 access count because the new child node has not yet been explored and there is no statistical data; 0 cumulative reward value because its performance indicators have not yet been calculated, and will be supplemented later through steps S23 and S24. Simultaneously, the number of tilt-sensitive child nodes of the new child node is initialized to 0, as the new child node has not yet expanded its child nodes, and there is no need to record relevant statistical information. Traditional strategies use the same expansion method for all nodes, such as randomly expanding adjacent nodes, which cannot adjust the direction according to the node's imaging status. This leads to blindly adjusting the focus when there is uneven sharpness, or focusing on correcting tilt when the focus deviation is large, resulting in low efficiency. The multi-mode expansion strategy in this step accurately determines the core problem of the current node through spatial sharpness difference—whether it is uneven sharpness (requiring tilt correction) or low global sharpness (requiring focus adjustment)—and then expands accordingly, ensuring that each child node generation is aimed at solving the current core problem, significantly improving expansion efficiency.
[0104] Step S23: Perform lens physical adjustment on the new child node and calculate the physical index of the new child node; the physical index includes global sharpness index value, spatial sharpness difference index value and tilt index value;
[0105] The adjustment object for performing lens physical adjustments is the three-dimensional configuration parameter (Z) corresponding to the new child node. new θx new ,θy new ), where Z new Let θx be the target coordinate of the new child node in the Z-axis direction of the 3D search space. new It is the target value of the lens horizontal tilt angle corresponding to the new child node, θy newThis is the target value for the vertical tilt angle of the lens corresponding to the new sub-node. Adjustment in the Z-axis direction is achieved by controlling the lens voice coil motor. Adjustment of the horizontal and vertical tilt angles is achieved by controlling the fine-tuning thread driven by a piezoelectric actuator or stepper motor. After adjustment, a high-contrast crosshair test pattern image under this 3D configuration is acquired. The acquisition conditions must be completely consistent with step S12, including the brightness, contrast, and shooting distance of the test pattern, to ensure the comparability of image data and avoid misjudging sharpness differences due to changes in acquisition conditions. After image acquisition, the local sharpness matrix is calculated according to the method in step S12: the image is divided into 3×3 sub-regions, and the variance of the pixel gradient magnitude is calculated for each sub-region to generate a 3×3 matrix. Based on this local sharpness matrix, three key physical indices are calculated: First, the global sharpness index value, using the weighted average method defined in step S14, with a weight of 0.3 for the central sub-region and 0.0875 for each of the other sub-regions, ensuring consistency with the calculation logic of the root node; second, the spatial sharpness difference index value, calculating the standard deviation of the sharpness index values of the nine sub-regions to quantify the sharpness uniformity; and third, the tilt index value, using a similar but independent calculation process to step S13, generating a local sharpness matrix for the images acquired under the new sub-node configuration, calculating the sharpness gradients in the horizontal and vertical directions, and obtaining the actual tilt angle θx under the current configuration through the pre-calibrated gradient-angle mapping relationship. actual With θy actual Take the sum of the absolute values of the two values, that is, the tilt index value = |θx| actual |+|θy actual This indicator reflects the actual tilt after adjustment, rather than the preset angle of the new sub-node, thus avoiding indicator deviation caused by hardware adjustment errors.
[0106] Traditional algorithms often predict node performance based on a pre-defined sharpness model, ignoring practical factors such as hardware adjustment errors and optical aberrations. This leads to significant discrepancies between predicted and actual performance, and may even misclassify spurious peaks as optimal solutions. This step, through actual physical adjustment and image acquisition, obtains real performance data of the new child node configuration, ensuring the accuracy of subsequent comprehensive reward calculations and providing reliable feedback for the algorithm. The combination of physical adjustment and real-time feedback ensures consistency between hardware status and node configuration, avoiding "misjudgments" by the algorithm due to adjustment errors. Secondly, the index calculation method, consistent with steps S12 and S14, places the performance data of all nodes in the same quantification system, ensuring fairness and comparability in subsequent UCT strategy selection and comprehensive reward calculation. The image acquisition process also verifies the imaging feasibility of the 3D configuration. If the acquired image has severe distortion or noise, the node configuration can be directly determined to be invalid, avoiding invalid iterations in the future.
[0107] Step S24: Calculate the comprehensive reward value of the new child node based on the physical indicators, and mark the tilt-sensitive node according to the ratio of spatial sharpness difference to global sharpness.
[0108] The core of step S24 is to establish a multi-objective optimization evaluation system of "high definition + high uniformity + low tilt" to guide the algorithm to avoid false peaks. The specific implementation process is as follows: Following the method in step S14, calculate the comprehensive reward value of the new child node, and set a ratio threshold K. When the spatial sharpness difference index value of the new child node > the global sharpness index value × K, the node is marked as a tilt-sensitive node. The ratio threshold K is determined based on offline experiments. At different tilt angles, a large number of images are collected to calculate the ratio of spatial sharpness difference to global sharpness. When this ratio exceeds a certain value, the imaging quality of the edge region significantly decreases, such as when the barcode recognition success rate is below 80%. This value is used as K. For example, K can be set to 20%-40%. For new child nodes marked as tilt-sensitive nodes, an additional penalty needs to be applied: based on the above comprehensive reward value, subtract (spatial sharpness difference index value × additional penalty coefficient). Set the additional penalty coefficient to 1.5-2 times the difference penalty coefficient to further reduce the reward value of tilt-sensitive nodes, ensuring that the algorithm prioritizes avoiding such nodes in subsequent selections. For example, in a barcode recognition scenario (difference penalty coefficient 2.0), if the spatial clarity difference of a certain tilt-sensitive node is 5 and the global clarity is 12, and K=30% (5>12×30%=3.6), then the additional penalty coefficient is 3.0, and the overall reward value needs to be reduced by 5×3.0=15, which greatly reduces the attractiveness of the node.
[0109] Traditional algorithms, focusing solely on global sharpness, fail to distinguish between "uniform sharpness across the entire field of view" and "sharp center with blurred edges," easily misjudging the latter (pseudo-peaks) as the optimal solution. This step introduces deductions for spatial sharpness difference and tilt, along with additional penalties for tilt-sensitive nodes, making the evaluation system more aligned with practical application needs. It demands not only high global sharpness but also uniform sharpness across the entire field of view and low tilt, fundamentally avoiding pseudo-peaks. The multi-objective design of the comprehensive reward value ensures that the algorithm's optimization direction is highly consistent with the needs of end-user applications. Secondly, the labeling of tilt-sensitive nodes provides crucial information for the backpropagation in subsequent step S25. Step S25, by counting the number of tilt-sensitive child nodes, labels nodes in tilt-risk areas, further reducing the probability of pseudo-peak regions being selected. Without this step, the algorithm cannot quantify the comprehensive performance of nodes, cannot distinguish between pseudo-peaks and the true optimal solution, and subsequent searches will continue to linger in pseudo-peak regions, failing to converge to the global optimum.
[0110] Step S25: Propagate the comprehensive reward value of the new child node back along the node sequence to the root node of the Monte Carlo tree. Perform an update operation on each node in the node sequence. After the update is completed, check whether the preset iteration termination condition has been met. If the iteration termination condition has not been met, return to step S21 to continue to select the optimal search path based on the upper confidence bound UCT strategy and start the next round of iteration; otherwise, proceed to step S30 to determine the global optimal configuration.
[0111] See Figure 3 Performing an update operation on each node in the node sequence specifically includes:
[0112] Step S251: Starting from the new child node, backtrack along the node sequence to the root node of the Monte Carlo tree to form a backpropagation path, and increment the visit count of each node on the backpropagation path by 1.
[0113] Step S252: Add the comprehensive reward value of the new child node to the cumulative reward value of each node in the node sequence, and update the cumulative reward value of each node.
[0114] Step S253: Divide the updated cumulative reward value of each node by the updated number of visits, and recalculate the average reward value of each node.
[0115] The core of step S25 is to establish a closed-loop mechanism of "performance feedback - tree structure update - risk avoidance - termination judgment" to ensure that the search can quickly converge to the global optimum while avoiding getting trapped in pseudo-peak regions. In step S251, starting from the new child node, the path backpropagation is formed by tracing the node sequence recorded in step S21, such as root node → node A → node B → new child node back to the root node. Path construction relies on the parent-child relationship between nodes in the node sequence. The parent node is located sequentially through the "parent node pointer" stored in each node to ensure that no node is missed. The access count of each node on the path is incremented by 1. The access count is used to quantify the frequency of node exploration. The higher the count, the more reliable the performance data of the three-dimensional configuration corresponding to the node, providing data support for the "exploitation" item of the UCT strategy. Traditional methods fail to reflect the exploration status of the entire branch due to ancestor nodes, resulting in large deviations in UCT value calculations. However, full path updates synchronize the visit counts of all ancestor nodes with the branch exploration frequency, ensuring the integrity of statistical data. For example, if the visit count of node B increases, the visit counts of its parent node A and the root node also increase synchronously, accurately reflecting the overall exploration progress of that branch.
[0116] Step S252 adds the calculated comprehensive reward value of the new child node to the existing cumulative reward value of each node on the backpropagation path, rather than replacing the original value. The logic for accumulating the cumulative reward value is based on the principle that "node performance is reflected by the combined performance of all its descendant child nodes." The higher the cumulative reward value of a node, the more high-performance child nodes exist under its branch, making that branch more valuable for exploration. For example, if the comprehensive reward value of the new child node is 8, the original cumulative reward value of node B is 20, and after accumulation it becomes 28; the original cumulative reward value of node A is 50, and after accumulation it becomes 58; and the original cumulative reward value of the root node is 100, and after accumulation it becomes 108. This method, by adding the comprehensive reward value of the new child node to the existing cumulative reward value of each node on the backpropagation path, ensures that the cumulative reward value comprehensively reflects the overall performance of the branch, providing accurate total data for calculating the average reward value. This avoids the situation in traditional algorithms where only the reward value of direct child nodes is used to update the parent node, causing ancestor nodes to fail to reflect the performance of deeper child nodes. According to the calculation method defined in step S14, for each node on the backpropagation path, the updated cumulative reward value is divided by the updated number of visits to obtain a new average reward value. This ensures that after each backpropagation, the average reward value of the node can reflect the latest branch performance in real time, providing accurate "utilization" data for the UCT strategy in step S21 and avoiding path selection errors caused by data lag.
[0117] If a new child node is marked as a skew-sensitive node, the "number of skew-sensitive child nodes" for each node on the backpropagation path is incremented by 1. Here, the "number of skew-sensitive child nodes" is defined as the total number of skew-sensitive child nodes among all descendant child nodes of a node, not just direct child nodes. The logic behind this is that the skewness problem of descendant child nodes essentially originates from the branch direction of the ancestor node, and the overall skew risk of the branch needs to be reflected through the risk statistics of the ancestor node. For example, if the node sequence is root node → A → B → new child node (skew-sensitive), then the number of skew-sensitive child nodes for the root node, A, and B is incremented by 1. If another child node of B is also skew-sensitive, then the number for B, the root node, and A is incremented by 1 again. Through full-path statistics, the skew risk of each branch can be quantified, providing a data foundation for subsequent skew-risk area node marking and avoiding the situation where traditional algorithms repeatedly enter the same skew-risk branch because they do not trace the source of skew risk. The iteration termination condition is when the total number of iterations reaches a preset iteration threshold. This threshold is determined through offline experiments based on the total number of nodes in the 3D search space and the time consumed per iteration. In a typical search space, such as N=50, M=20, with a total of 50×20×20=20000 nodes, the global optimal solution discovery rate corresponding to different iteration counts was tested. When the iteration count reaches a certain value, the discovery rate stabilizes above 95%, and this value is the iteration threshold. When the number of tilt-sensitive child nodes of a node exceeds 50% of its total child nodes, it is marked as a tilt-risk area node. Its UCT value is multiplied by a risk reduction factor of 0.5. This UCT value reduction guides the algorithm to prioritize exploring lower-risk branches.
[0118] Step S30: Traverse the Monte Carlo tree that has completed the iteration to calculate the final score of each node, determine the optimal three-dimensional configuration parameters based on the final score, adjust the lens to the optimal three-dimensional configuration based on the optimal three-dimensional configuration parameters, verify the optimal three-dimensional configuration, and complete the lens assembly and fixation.
[0119] Step S30 transforms the massive node data generated by Monte Carlo tree search into a physically feasible optimal lens configuration, and ensures the long-term effectiveness of the configuration through precise adjustment and reliable solidification, filling the gap between algorithm optimization and hardware implementation, while avoiding risks such as the disconnect between search results and actual application needs, adjustment errors, and solidification failure.
[0120] Further, step S30 includes:
[0121] Step S31, as follows Figure 4As shown, all nodes in the Monte Carlo tree that has completed the iteration are traversed, the node stability and tilt risk factor of each node are calculated, the final score is calculated based on the average reward value of the node, the node stability and tilt risk factor, the node with the highest final score is selected as the global optimal node, and the optimal three-dimensional configuration parameters of the global optimal node are recorded, including the optimal focus position, the optimal horizontal tilt angle and the optimal vertical tilt angle.
[0122] During the traversal, for each node whose access count exceeds the node access count threshold, its final node score is calculated. The node access count threshold needs to be determined through offline experiments: multiple batches of modules are selected for search iteration, and the actual imaging performance corresponding to nodes with different access counts is monitored over a long period of time. The monitoring duration is recommended to be 12-24 hours, with imaging performance data collected once per hour, and the cumulative sampling count is no less than 50 times. The lowest access count when the node performance data (global sharpness, spatial sharpness difference) tends to stabilize is recorded, and this count is the node access count threshold. The purpose of setting the node access count threshold is to filter out nodes with random statistical information due to insufficient exploration, ensure that the node data participating in the scoring has statistical reliability, and avoid performance misjudgment caused by accidental factors. The calculation of the node stability index value requires first extracting all direct child nodes of the node, obtaining the comprehensive reward value of each direct child node calculated in step S24, using the standard deviation formula to calculate the dispersion of these comprehensive reward values, and then taking the reciprocal of the standard deviation as the node stability index value. The standard deviation reflects the fluctuation range of the sub-node's performance. The smaller the standard deviation, the closer the performance of the adjacent configurations around the node is, the more stable the imaging state of the area where the node is located, and the less affected by minor adjustment disturbances. Taking the reciprocal makes the index value positively correlated with stability, which meets the requirement of "the higher the stability, the better" in the scoring logic. Traditional methods may select nodes with excellent single-point performance but a sharp drop in the performance of surrounding nodes. In actual use, performance degradation occurs due to minor disturbances such as mechanical vibration. The introduction of the node stability index ensures that the selected nodes not only have excellent performance themselves, but also have strong performance consistency in their surrounding areas, adapting to individual differences in modules and fluctuations in the usage environment during mass production.
[0123] The tilt risk factor is calculated based on the ratio of the number of tilt-sensitive child nodes to the total number of child nodes. This ratio is directly calculated by reading the number of tilt-sensitive child nodes stored in the node's database and the total number of child nodes. Tilt-sensitive child nodes are marked in step S24, and their proportion reflects the tilt-related pseudo-peak distribution density of the branch to which the node belongs. A higher proportion indicates that the exploration path extending from that node is more prone to invalid configurations with "clear center and blurred edges," and the branch's tilt risk is higher. The tilt risk factor is designed to be 1 minus this ratio, making the factor range between 0 and 1. When the proportion is 0, the factor is 1, indicating no tilt risk; when the proportion is close to 1, the factor is close to 0, indicating high risk. This design achieves risk quantification and positive scoring adaptation. By adjusting the tilt risk factor, the final score of high-risk nodes is naturally reduced, logically cutting off the selection bias towards pseudo-peak regions and avoiding the situation where traditional algorithms repeatedly enter the same pseudo-peak region due to the inability to trace the source of risk. The final scoring formula is: Node final score = Average return value × Node stability index value × Tilt risk factor. The formula's design logic is a progressive hierarchy of "core performance × stability × risk control." The average return value determines the scoring benchmark, the stability index value filters out nodes with "stable performance," and the skewed risk factor eliminates "high-risk" nodes. These three factors work together to achieve a multi-dimensional comprehensive evaluation. The higher the average return value, the larger the node stability index value, and the closer the skewed risk factor is to 1, the higher the final score, precisely targeting the globally optimal goal of "high performance, high stability, and low risk." The node with the highest final score is the globally optimal node. If step S31 is missing, it is impossible to filter out the configuration that truly meets the globally optimal requirements from the vast search tree nodes. This may result in the wrong selection of pseudo-peak nodes or unstable nodes, rendering subsequent adjustment and solidification work meaningless. The search results of step S20 cannot be translated into actual imaging performance improvement, and the entire calibration process becomes disconnected between the algorithm and the hardware.
[0124] Step S32: Based on the optimal focus position, optimal horizontal tilt angle, and optimal vertical tilt angle of the global optimal node, execute a hardware adjustment sequence of two stages, coarse adjustment and fine adjustment, to precisely adjust the lens to the optimal three-dimensional configuration.
[0125] The coarse adjustment stage is implemented as follows: The current three-dimensional state parameters of the lens are read, namely the current Z-axis position, current θx, and current θy; the differences between the current state and the optimal three-dimensional configuration parameters are calculated, namely the Z-axis position difference ΔZ, the horizontal tilt difference Δθx, and the vertical tilt difference Δθy; finally, the coarse adjustment step size and number of adjustments are set based on the differences. The Z-axis coarse adjustment step size is determined based on the maximum stepping accuracy of the voice coil motor and ΔZ, and is usually several times the fine adjustment step size, ensuring that ΔZ is reduced to a range that can be quickly processed by fine adjustment within a few adjustments; the coarse adjustment angle increments of θx and θy are determined based on the adjustment accuracy of the fine adjustment thread and Δθx and Δθy, and the principle is the same as for the Z-axis. The purpose of coarse adjustment is to quickly reduce the difference between the target parameters and the current state, avoiding the excessively long adjustment cycle caused by excessively small step sizes in direct fine adjustment, thereby improving adjustment efficiency to adapt to mass production pace and improve the low efficiency of traditional single-stage fine adjustment.
[0126] The fine-tuning stage employs closed-loop control, with its core being a cyclical mechanism of "adjustment-feedback-comparison-readjustment." The adjustment target is the residual minute difference after coarse adjustment. The Z-axis fine-tuning step size is set to the minimum step accuracy of the voice coil motor, and the fine-tuning angle increments of θx and θy are set to the minimum adjustment accuracy of the fine-tuning thread, ensuring that the smallest unit of adjustment matches the hardware precision. The selection of feedback signals needs to be dimensionally differentiated: for the Z-axis, real-time readings from the position encoder are prioritized because they directly reflect the lens's physical position, have low feedback latency, and their accuracy matches the motor stepping; for θx and θy, since there are no direct position sensors, the spatial sharpness difference of real-time acquired images is used as the feedback signal. This indicator is directly related to the tilt angle and is calculated using the method in step S12. Precision thresholds are set, determined through offline experiments based on the terminal application requirements: for example, for barcode recognition scenarios, the barcode recognition success rate under different adjustment deviations is collected, and the maximum adjustment deviation when the success rate stabilizes above the preset threshold is used as the precision threshold; for face recognition scenarios, the accuracy of facial feature point recognition is used as the basis for setting corresponding precision thresholds. The closed-loop control process is as follows: after each minor adjustment, a feedback signal is collected, and the deviation between the feedback value and the target value is calculated. If the deviation is greater than the accuracy threshold, the adjustment continues according to the direction of the deviation until the deviation is less than or equal to the accuracy threshold. This method effectively compensates for the nonlinearity, hysteresis, and backlash errors of the mechanical system. Traditional open-loop control only drives the hardware based on preset parameters and cannot perceive the actual deviation during the adjustment process, resulting in a gap between the final state and the target parameters. Closed-loop control, on the other hand, forms an error correction mechanism through real-time feedback, ensuring that the hardware state is highly consistent with the optimal configuration parameters determined by the algorithm.
[0127] Step S33: Verify the optimal three-dimensional configuration, lock the optimal three-dimensional configuration, and complete the lens assembly and fixation.
[0128] The process of verifying the optimal 3D configuration is as follows: Based on the determined optimal 3D configuration parameters, after physically adjusting the lens to this configuration, a high-contrast crosshair test pattern image is acquired. The global sharpness index, spatial sharpness difference index, and tilt index are calculated according to the unified method in steps S12 and S23. The calculation results are compared with preset imaging quality standards, which include global sharpness threshold, spatial sharpness difference threshold, and tilt threshold. The thresholds are determined based on offline experiments. Through correlation analysis of the imaging performance of a large number of modules under different configurations and the needs of terminal applications, a mapping relationship between configuration parameters and imaging quality is established to ensure that the verification standards conform to actual applications. When the calculation results meet all threshold requirements, the verification is deemed successful; otherwise, the process returns to step S30 to recalculate the optimal configuration. The process of locking the optimal 3D configuration is as follows: The lens position in the 3D coordinate system is fixed using a mechanical locking mechanism. This mechanism includes a locking screw for the piezoelectric actuator and an anti-backflow structure for the fine-tuning threads. First, the lens is adjusted to the optimal configuration, and then a preset locking torque is applied. The locking torque value is determined based on the lens material, mounting structure, and long-term stability requirements, ensuring stable configuration under conditions of vibration and temperature changes. After lens locking is completed, a permanent fixing process between the lens and the mounting base is performed. The verification step S33, through actual image acquisition and index calculation, transforms the calibration results from algorithmic derivation into a physically achievable stable state.
[0129] Example 2
[0130] This embodiment, based on Embodiment 1, provides a Monte Carlo tree search application in a camera lens assembly focus calibration system, such as... Figure 5 As shown, it includes:
[0131] Root node construction module: Used to construct a 3D search space that supports Monte Carlo tree search. It acquires an initial image of a high-contrast crosshair test pattern at the current position of the lens, calculates the local sharpness index value of the initial image, and generates a local sharpness matrix; calculates the initial tilt angle based on the local sharpness matrix; and constructs the root node of the Monte Carlo tree in the 3D search space based on the local sharpness matrix and the initial tilt angle.
[0132] Iterative update module: It is used to select the optimal search path by applying the upper confidence bound strategy starting from the root node of the Monte Carlo tree. For the nodes that are not fully expanded at the end of the optimal search path, it expands them in the three-dimensional search space to generate new child nodes. It performs lens physics adjustment on the new child nodes and calculates the comprehensive reward value. It updates the Monte Carlo tree through backpropagation and iterates until the termination condition is met.
[0133] Optimal Configuration Module: Used to traverse the Monte Carlo tree after the iteration is completed, calculate the final score of each node, determine the optimal 3D configuration parameters based on the final score, and adjust the camera to the optimal 3D configuration based on the optimal 3D configuration parameters.
[0134] Furthermore, in the root node construction module, the method for constructing the root node of the Monte Carlo tree in the three-dimensional search space includes:
[0135] Step S141: Locate the initial focus position Z0 of the current lens in the three-dimensional search space;
[0136] Step S142: Calculate the global sharpness index value and spatial sharpness difference index value of the root node based on the local sharpness matrix.
[0137] Step S143: Calculate the tilt index value of the root node based on the initial horizontal tilt angle and the initial vertical tilt angle;
[0138] Step S144: Set the difference penalty coefficient and skew penalty coefficient for the root node;
[0139] Step S145: Calculate the cumulative reward value of the root node based on the global sharpness index value, spatial sharpness difference index value, tilt index value, difference penalty coefficient, and tilt penalty coefficient of the root node.
[0140] Step S146: Initialize the number of visits to 1, divide the cumulative reward value by the number of visits to obtain the average reward value, and set the search depth to 0;
[0141] Step S147: Integrate the initial focus position Z0, initial horizontal tilt angle, initial vertical tilt angle, global sharpness index value of the root node, spatial sharpness difference index value, tilt index value, number of visits, cumulative reward value, average reward value and search depth, initialize the number of tilt-sensitive child nodes to 0, and construct the root node of the Monte Carlo tree.
[0142] Furthermore, in the iterative update module, the method for selecting the optimal search path includes:
[0143] Step S21: Starting from the root node of the Monte Carlo tree, use the upper confidence bound strategy to form the optimal search path and record the node sequence on the optimal search path;
[0144] Further, step S21 includes:
[0145] Step S211: Set the root node of the Monte Carlo tree as the current search node, initialize the node sequence list and add the current search node to the node sequence list, create a search termination flag and set it to the non-termination state;
[0146] Step S212: Check the number of child nodes of the current search node, determine whether the current search node is a node that is not fully expanded, and set the search termination flag to the termination state if the current search node is a node that is not fully expanded.
[0147] Step S213: When the current search node is a fully expanded node, obtain all direct child nodes of the current search node and read the access count of the current search node as the access count of the parent node.
[0148] Step S214: For each direct child node, extract the average reward value of the direct child node and the number of visits to the direct child node, and substitute the number of visits to the parent node, the average reward value of the direct child node, and the number of visits to the direct child node into the upper confidence bound formula to calculate the UCT value of the direct child node.
[0149] Step S215: Compare the UCT values of all direct child nodes, select the direct child node with the largest UCT value as the next search node, add the next search node to the node sequence list and update the current search node as the next search node;
[0150] Step S216: Read the status of the search termination flag. If the search termination flag is in an unterminated state, return to step S212 to continue judging the updated current search node. If the search termination flag is in a terminated state, output the complete node sequence list as the optimal search path.
[0151] The algorithm and system of this application may be implemented in many ways. For example, the algorithm and system of this application may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above-described order of steps for the algorithm is for illustrative purposes only, and the steps of the method of this application are not limited to the order specifically described above, unless otherwise specifically stated.
[0152] In addition, the parts of the technical solutions provided in the embodiments of this application that are consistent with the implementation principles of the corresponding technical solutions in the prior art have not been described in detail, so as to avoid excessive elaboration.
[0153] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the invention. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A Monte Carlo tree search algorithm for camera lens assembly focus calibration, characterized in that, The algorithm includes: A 3D search space supporting Monte Carlo tree search is constructed. An initial image of a high-contrast crosshair test pattern is acquired at the current position of the lens. The local sharpness index value of the initial image is calculated to generate a local sharpness matrix. The initial tilt angle is calculated based on the local sharpness matrix. Based on the local sharpness matrix and the initial tilt angle, the root node of the Monte Carlo tree is constructed in the 3D search space. Starting from the root node of the Monte Carlo tree, the upper confidence bound strategy is applied to select the optimal search path. For nodes that are not fully expanded at the end of the optimal search path, new child nodes are generated in the three-dimensional search space. Lens physics adjustment is performed on the new child nodes and the comprehensive reward value is calculated. The Monte Carlo tree is updated through backpropagation. The process is iterated until the termination condition is met. The Monte Carlo tree that has completed iterations is traversed to calculate the final score of each node. The optimal 3D configuration parameters are determined based on the final scores, and the camera is adjusted to the optimal 3D configuration based on the optimal 3D configuration parameters.
2. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 1, characterized in that, The method for constructing the three-dimensional search space includes: The movable range of the lens is discretized into N position nodes, and the horizontal and vertical tilt angle adjustment ranges of the lens are discretized into M angle nodes respectively, thus constructing an N×M×M three-dimensional search space.
3. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 2, characterized in that, The method for generating the local sharpness matrix is as follows: The initial image is divided into nine sub-regions of a 3×3 grid. The variance of the gradient magnitude of all pixels in each sub-region is calculated as the local sharpness index value of the sub-region, and a 3×3 local sharpness matrix is generated.
4. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 3, characterized in that, The initial tilt angle includes the initial horizontal tilt angle and the initial vertical tilt angle; The calculation methods for the initial horizontal tilt angle and the initial vertical tilt angle include: Spatial gradient analysis is performed on the local sharpness matrix to calculate the horizontal and vertical sharpness gradients. The horizontal sharpness gradient is converted into the initial horizontal tilt angle, and the vertical sharpness gradient is converted into the initial vertical tilt angle.
5. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 4, characterized in that, The method for constructing the root node of the Monte Carlo tree includes: Locate the initial focus position Z0 of the current shot in the 3D search space; calculate the global sharpness index value and spatial sharpness difference index value of the root node based on the local sharpness matrix; calculate the tilt index value of the root node based on the initial horizontal tilt angle and the initial vertical tilt angle; set the difference penalty coefficient and tilt penalty coefficient of the root node. The cumulative reward value of the root node is calculated based on its global sharpness index, spatial sharpness difference index, tilt index, difference penalty coefficient, and tilt penalty coefficient. Initialize the number of visits to 1, divide the cumulative reward value by the number of visits to obtain the average reward value, and set the search depth to 0; The root node of the Monte Carlo tree is constructed by integrating the initial focus position Z0, initial horizontal tilt angle, initial vertical tilt angle, global sharpness index value of the root node, spatial sharpness difference index value, tilt index value, number of visits, cumulative reward value, average reward value, and search depth.
6. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 5, characterized in that, The tilt index value is the sum of the absolute values of the initial horizontal tilt angle and the initial vertical tilt angle.
7. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 6, characterized in that, The method for selecting the optimal search path includes: Set the root node of the Monte Carlo tree as the current search node, initialize the node sequence list and add the current search node to the node sequence list, create a search termination flag and set it to the non-terminating state; Check the number of child nodes of the current search node, determine whether the current search node is a node that is not fully expanded, and set the search termination flag to the terminated state if the current search node is a node that is not fully expanded. When the current search node is a fully expanded node, determine the next search node, add the next search node to the node sequence list, and update the current search node to the next search node; Read the status of the search termination flag. If the search termination flag is in an unterminated state, continue to judge the updated current search node. If the search termination flag is in a terminated state, output the complete node sequence list as the optimal search path.
8. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 7, characterized in that, The method for determining the next search node includes: Get all direct child nodes of the current search node, calculate the UCT value of the direct child nodes, compare the UCT values of all direct child nodes, and select the direct child node with the largest UCT value as the next search node.
9. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 8, characterized in that, The method for generating new child nodes is as follows: When the optimal search path reaches a node that is not fully expanded, the spatial sharpness difference index value of the node is calculated. Based on the spatial sharpness difference index value of the node, a three-dimensional spatial expansion strategy is selected to generate a new child node in the three-dimensional search space.
10. The Monte Carlo tree search algorithm for camera lens assembly focus calibration according to claim 9, characterized in that, The method for determining the optimal three-dimensional configuration parameters includes: Traverse all nodes in the completed Monte Carlo tree, calculate the node stability and tilt risk factor for each node, calculate the final score based on the node's average return value, node stability, and tilt risk factor, select the node with the highest final score as the global optimal node, and record the optimal three-dimensional configuration parameters of the global optimal node; the optimal three-dimensional configuration parameters include the optimal focus position, the optimal horizontal tilt angle, and the optimal vertical tilt angle.
11. A Monte Carlo tree search system for camera lens assembly focus calibration, used to implement the Monte Carlo tree search algorithm for camera lens assembly focus calibration as described in any one of claims 1-10, characterized in that, The system includes: Root node construction module: Used to construct a 3D search space that supports Monte Carlo tree search. It acquires an initial image of a high-contrast crosshair test pattern at the current position of the lens, calculates the local sharpness index value of the initial image, and generates a local sharpness matrix; calculates the initial tilt angle based on the local sharpness matrix; and constructs the root node of the Monte Carlo tree in the 3D search space based on the local sharpness matrix and the initial tilt angle. Iterative update module: It is used to select the optimal search path by applying the upper confidence bound strategy starting from the root node of the Monte Carlo tree. For the nodes that are not fully expanded at the end of the optimal search path, it expands them in the three-dimensional search space to generate new child nodes. It performs lens physics adjustment on the new child nodes and calculates the comprehensive reward value. It updates the Monte Carlo tree through backpropagation and iterates until the termination condition is met. Optimal Configuration Module: Used to traverse the Monte Carlo tree after the iteration is completed, calculate the final score of each node, determine the optimal 3D configuration parameters based on the final score, and adjust the camera to the optimal 3D configuration based on the optimal 3D configuration parameters.
Citation Information
Patent Citations
Monte Carlo noise removal method based on machine learning
CN105787892A
Three-dimensional picture display method and system based on indoor space positioning
CN120147584A
Unmanned aerial vehicle three-dimensional coverage path planning method based on Monte Carlo tree search
CN116560410A
Spacecraft orbit determination method and device, electronic equipment and storage medium
CN118408544A
Rapid automatic focus fixing method based on topological structure and Monte Carlo algorithm
CN118778220A
Cited By
Dynamic refraction visual correction method for ultra-shallow water blue-green laser sounding
CN121739980A
Machine vision automatic precision focusing method and system based on dual-mode evaluation
CN121832041A
