Real-time adjusting camera focusing method and system

By constructing an offline spot centroid-positive focus lookup table and an online real-time focusing algorithm, the problem of focusing and anti-interference in complex environments for industrial cameras was solved, achieving efficient and stable image clarity and real-time focusing.

CN121567958APending Publication Date: 2026-02-24SUZHOU UNIV OF SCI & TECH
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202511738389.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-25
Publication Date
2026-02-24

AI Technical Summary

Technical Problem

Existing industrial camera focusing methods are not strong enough to resist interference from factors such as conveyor belt vibration, light fluctuations, and light spot obstruction, resulting in decreased image quality and focusing errors.

Method used

An optimized spot centroid-focus lookup table is constructed offline and combined with an online real-time focusing algorithm, including spot anti-interference preprocessing, centroid calculation and efficient retrieval data structure (such as KD tree), and occlusion interference is compensated by Kalman filtering to achieve real-time focusing.

Benefits of technology

It significantly improves the camera's anti-interference capability and real-time performance in focusing, ensuring image clarity, adapting to the complex environment of industrial scenarios, and meeting the needs of high-speed production.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121567958A_ABST
    Figure CN121567958A_ABST
Patent Text Reader

Abstract

The invention discloses a real-time adjustment camera focusing method and system, and aims to solve the problem of poor anti-interference capability of an existing focusing mode. The method comprises the following steps: off-line construction of an optimization lookup table and on-line real-time focusing: in an off-line stage, constructing a fixed-focus platform, generating an original lookup table through light spot anti-interference preprocessing and centroid calculation, and then constructing an efficient retrieval data structure to obtain the optimization lookup table; in the online stage, images are collected in real time, the center of mass is obtained through anti-interference processing, compensation is conducted through a preset prediction algorithm during shielding, target reference points are matched through an efficient retrieval data structure, and focusing is triggered according to deviation of the center of mass. The system comprises a hardware module and a software module which cooperatively realize the method. The method improves the anti-interference capability of light spot processing and the matching efficiency of the lookup table, adapts to the interference of illumination fluctuation, shielding and the like of an industrial environment, meets the real-time focusing requirements of high-speed production, is compatible with existing hardware, and is convenient to deploy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial camera focusing technology, specifically to a real-time camera focusing method and system. Background Technology

[0002] In industrial vision applications, clear images are the core prerequisite for measuring the size of objects under test, detecting defects, and recognizing postures. However, industrial scenarios face two major challenges: First, the distance between the object under test and the imaging system can change frequently due to conveyor belt vibration, dynamic changes in the conveying distance, etc., causing the image to shift from focus to out of focus. Second, the industrial environment is complex, and fluctuations in lighting, light spots caused by dust and oil, and noise from the image sensor can damage the image quality and increase the difficulty of focusing.

[0003] While existing solutions based on "offline construction of spot centroid - positive focus lookup table + online matching and focusing" have improved real-time performance to some extent, the spot processing has weak anti-interference capabilities. The spot extraction method used is not optimized for industrial environment interference, and light fluctuations can easily lead to blurred spot edges and centroid calculation deviations. Occlusion or noise interference may cause focusing errors.

[0004] In summary, there is an urgent need for a real-time camera focusing method and system. Summary of the Invention

[0005] The purpose of this invention is to provide a real-time camera focusing method and system to solve the problem of poor anti-interference capability of existing focusing methods.

[0006] The technical solution of the present invention to solve the above-mentioned technical problems is as follows:

[0007] A real-time camera focusing method includes the following steps:

[0008] Step S1: Offline construction of an optimized spot centroid-positive focus lookup table, specifically including: S11: Setting up an offline fixed-focus platform, placing the vision system in front of the motion platform, placing the object to be tested on the motion platform, the motion direction of the motion platform being parallel to the optical axis of the imaging unit in the vision system, adjusting the light source parameters and the position of the motion platform to achieve normal imaging of the object to be tested; S12: Driving the motion platform to move along the optical axis, recording the first position A1 with the highest imaging clarity when the focusing motor stroke is zero, and the second position A2 with the highest imaging clarity when the focusing motor is at its maximum stroke, calculating the stroke range L = A2 - A1 of the motion platform, and setting the step distance of the motion platform. Step 1 is the preset ratio of the depth of field of the imaging unit; S13: Drive the motion platform from the first position A1 to the second position A2 according to the step distance step1, and acquire the image of the object to be tested at each step position. Perform spot anti-interference preprocessing, spot extraction and spot centroid calculation on the acquired image in sequence to obtain the spot centroid coordinates (xc, yc) corresponding to each step position; S14: Record the "spot centroid coordinates (xc, yc) - focusing motor stroke A" data pair corresponding to each step position to form an original lookup table, and construct an efficient retrieval data structure based on the spot centroid coordinates (xc, yc) to obtain an optimized spot centroid-positive focus lookup table;

[0009] Step S2: Online real-time focusing, specifically including: S21: Placing the object to be tested within the field of view of the vision system, loading the optimized spot centroid-positive focus lookup table, driving the focusing motor to move from the initial stroke to the maximum stroke according to the step distance step1, acquiring the first frame image of the object to be tested and performing the spot anti-interference preprocessing and spot centroid calculation to obtain the first frame spot centroid coordinates (xc0, yc0), and obtaining the corresponding reference point R0 (x0, y0, A0) through the efficient retrieval data structure matching; S22: Real-time acquisition of images of the object to be tested, repeatedly performing the spot anti-interference preprocessing and spot centroid calculation for each frame image to obtain the current frame spot centroid coordinates (xc, yc); S23: Determining the integrity of the current frame spot, if the spot is occluded, compensating the current frame spot centroid coordinates (xc, yc) through a preset prediction algorithm to obtain... S24: Match the effective centroid coordinates or the compensated centroid coordinates (xc, yc) with the efficient retrieval data structure to obtain the corresponding target reference point R(x, y, A); S25: Calculate the centroid deviation value d between the effective centroid coordinates or the compensated centroid coordinates (xc, yc) and the target reference point R(x, y, A). If the centroid deviation value d is greater than the preset deviation threshold, drive the focusing motor to move to the focusing motor stroke A corresponding to the target reference point R(x, y, A) to complete real-time focusing; S26: Determine whether a stop signal is received. If a stop signal is received, exit online real-time focusing; if no stop signal is received, return to step S22 and repeat the real-time focusing loop.

[0010] In a further embodiment, in step S11, the light source parameters include light source brightness and light source angle. Normal imaging means that in the image acquired by the imaging unit, the gray value of the light spot area of ​​the object under test is within a preset gray value range, and there are no obvious overexposed or underexposed areas.

[0011] In a further embodiment, the light spot anti-interference preprocessing in step S13 includes the following sub-steps: S131: Illumination compensation processing, using at least one illumination compensation algorithm to process the acquired image, wherein the illumination compensation algorithm includes an adaptive histogram equalization (CLAHE) algorithm, and the cliplimit value of the adaptive histogram equalization algorithm is in the range of 1.0-3.0; S132: Noise suppression processing, using at least one noise suppression algorithm to process the illumination-compensated image, wherein the noise suppression algorithm includes a combination of a Gaussian filtering algorithm and a median filtering algorithm, wherein the Gaussian filtering algorithm has a convolution value of 1.0-3.0. The kernel size is 3×3-7×7, the standard deviation σ ranges from 0.5 to 2.0, and the window size of the median filtering algorithm is 3×3-5×5; S133: Multi-threshold binarization fusion processing, using at least two binarization algorithms to binarize the spot region in the noise-suppressed image to obtain at least two binarized images, performing a logical AND operation on the at least two binarized images to obtain a fused spot binarized image; the binarization algorithm includes a single-threshold binarization algorithm and an OTU binarization algorithm, and the threshold of the single-threshold binarization algorithm is 1.0-1.5 times the average gray level of the image.

[0012] In a further embodiment, the calculation of the spot centroid in step S13 is achieved using the image moment formula, the specific formula of which is as follows: Where, m pq Let x be the p-th order moment of the image, N be the total number of pixels contained in the spot region, and x be the x-th order moment. i y i Let f(x) and f(x) be the x and y coordinates of the i-th pixel within the light spot region, respectively. i ,y i Let be the grayscale value of the i-th pixel, where p, q, and i are all non-negative integers, and x... c y c These are the horizontal and vertical coordinates of the centroid of the light spot, respectively, m. 10 Let m be the first to zeroth moments of the image. 00 Let m be the 0-0th order moment of the image. 01 is the 0th-1st moment of the image.

[0013] In a further embodiment, the efficient retrieval data structure in step S14 is a KD-tree. The construction process of the KD-tree includes: S141: using all spot centroid coordinates (xc, yc) in the original lookup table as the dataset, determining the dimension of the KD-tree to be 2, with the first split dimension being the horizontal coordinate xc of the spot centroid and the second split dimension being the vertical coordinate yc of the spot centroid; S142: sorting the dataset according to the first split dimension xc, and selecting the spot centroid coordinate at the middle position after sorting as the root node of the KD-tree; S143: dividing the dataset into a subset to the left of the root node (xc is less than the root node xc) and a subset to the right of the root node (xc is greater than the root node xc), repeating the sorting and middle node selection in step S142 for each subset according to the second split dimension yc, and generating child nodes and leaf nodes of the KD-tree in sequence until all dataset elements are added to the KD-tree as nodes, thus completing the construction of the efficient retrieval data structure.

[0014] In a further embodiment, in step S21, the initial stroke is the minimum stroke of the focusing motor, and the matching process of the first frame spot centroid coordinates (xc0, yc0) is as follows: by traversing the optimized spot centroid-focus lookup table through the nearest neighbor search algorithm of the KD tree, the "spot centroid coordinates-focus motor stroke" data pair with the smallest Euclidean distance to (xc0, yc0) is found and used as the reference point R0(x0, y0, A0).

[0015] In a further embodiment, in step S23, the criterion for determining whether the light spot is occluded is: the pixel area of ​​the light spot region in the current frame is less than a preset proportion of the pixel area of ​​the historical normal light spot (the preset proportion ranges from 50% to 80%); the preset prediction algorithm is a Kalman filter algorithm, and the mathematical expression of the Kalman filter algorithm is as follows: State equation: X k =AX k-1 +BU k-1 +W k Observation equation: Z k =HX k +V k Among them, X k =[x c,k ,y c,k ] T The state vector at time k (including the horizontal coordinate x of the centroid of the light spot at time k) c,k With vertical coordinate y c,k A is the state transition matrix. B is the control input matrix. U k-1 W is the control input at time k-1. kThe process noise (following a Gaussian distribution with a mean of 0 and a covariance matrix of Q, where Q = diag([q1,q2]), and the values ​​of q1 and q2 range from 0.01 to 0.1) The observation vector at time k (including the centroid coordinates of the light spot detected at time k) H is the observation matrix. V k The observed noise (following a Gaussian distribution with a mean of 0 and a covariance matrix of R, R = diag([r1,r2]), where r1 and r2 range from 0.05 to 0.5); the compensated centroid coordinates (xc,yc) are the optimal estimates obtained by Kalman filtering. It is obtained through prediction-update iteration using Kalman filtering.

[0016] In a further embodiment, in step S24, the matching process of the efficient retrieval data structure is as follows: input the effective centroid coordinates or the compensated centroid coordinates (xc, yc) into the KD tree, traverse the optimized spot centroid-focus lookup table through the KD tree's NN (nearest neighbor) search algorithm, and output the "spot centroid coordinates-focusing motor travel" data pair with the smallest Euclidean distance to the input coordinates as the target reference point R(x, y, A).

[0017] In a further embodiment, in step S25, the centroid deviation value d is calculated using the Euclidean distance formula, the specific formula of which is as follows: Where, x c,eff y c,eff These are the horizontal and vertical components of the effective centroid coordinates or compensated centroid coordinates (xc, yc), respectively, where x and y are the horizontal and vertical components of the target reference point R(x, y, A), respectively; the preset deviation threshold is the pixel distance corresponding to the step distance step1 (calculated by converting the pixel size of the imaging unit to the object-image distance).

[0018] A real-time adjustable camera focusing system for use in the aforementioned real-time adjustable camera focusing method;

[0019] The system includes: a hardware module: an image acquisition module for acquiring images of the object under test, including a CMOS image sensor and an industrial lens;

[0020] The motion control module is used to drive the focusing motor and the motion platform, including a stepper motor driver and a motion control card;

[0021] The light source module is used to provide illumination, including industrial light sources with adjustable brightness;

[0022] Software module: Spot anti-interference processing submodule, used to perform spot anti-interference preprocessing;

[0023] The centroid calculation submodule is used to perform spot centroid calculation;

[0024] The lookup table management submodule is used to build efficient retrieval data structures and optimize lookup tables;

[0025] The spot prediction submodule is used to perform Kalman filter compensation;

[0026] The focus control submodule is used to perform matching and focus triggering;

[0027] The hardware module and software module are connected via a data bus. The output of the image acquisition module is connected to the input of the spot anti-interference processing submodule. The output of the spot anti-interference processing submodule is connected to the input of the centroid calculation submodule. The output of the centroid calculation submodule is connected to the inputs of the lookup table management submodule and the spot prediction submodule. The output of the lookup table management submodule is connected to the input of the focus control submodule. The output of the spot prediction submodule is connected to the input of the focus control submodule. The output of the focus control submodule is connected to the input of the motion control module.

[0028] The present invention has the following beneficial effects:

[0029] This invention significantly improves the anti-interference capability and real-time performance of camera focusing by synergistically optimizing spot anti-interference preprocessing, efficient retrieval data structure construction, and occlusion compensation mechanism. It can effectively cope with illumination fluctuations, noise interference, and spot occlusion problems in industrial scenarios, ensuring the stability and accuracy of spot centroid calculation. At the same time, it greatly optimizes the lookup table matching efficiency, meets the real-time focusing requirements of high-speed industrial production, and is compatible with existing industrial vision hardware systems. Upgrades can be achieved without additional equipment replacement, improving the automation and continuity of the focusing process and adapting to diverse industrial inspection scenarios. Attached Figure Description

[0030] Figure 1 This is an overall block diagram of the adjustment method of the present invention.

[0031] Figure 2 This is a detailed block diagram of step one in the adjustment method of the present invention.

[0032] Figure 3 This is a detailed block diagram of step two in the adjustment method of the present invention. Detailed Implementation

[0033] The principles and features of the present invention are described below with reference to the accompanying drawings. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.

[0034] (I) Experimental Environment Setup

[0035] To verify the effectiveness of this invention, the following industrial scenario experimental platform was built:

[0036] Hardware configuration: Image acquisition module: Baslerac A2040-90um (2-megapixel CMOS, 90fps, 3.45μm pixel size), Computar M1614-MP2 (16mm lens, F1.4);

[0037] Motion control module: Leadshine DM542 driver, Leadshine 42 stepper motor (step angle 1.8°, reduction ratio 1:5), HIWIN linear motion platform (accuracy ±0.005mm);

[0038] Light source module: KeyenceCA-DRW2 (ring light source, 650nm, brightness adjustable from 0-255 levels);

[0039] Computing module: NVIDIA Jetson AGX Orin (CPU 12-core ARM Cortex-A78, GPU 2048 CUDA Core, 64GB memory);

[0040] Industrial scenario simulation:

[0041] Test object: aluminum alloy gear (50mm diameter, 20 teeth, surface roughness Ra1.6); dynamic interference: conveyor belt speed 1m / s, image acquisition is synchronously triggered by encoder (1 frame is acquired for every 1mm movement);

[0042] Environmental interference: light fluctuations (brightness adjusted by ±30% via light source controller), light spot occlusion (10%-50% of the light spot area covered by transparent acrylic sheet), noise (simulated as 20dB noise via image sensor gain adjustment).

[0043] (II) Offline Table Creation Process

[0044] S11: Platform Setup and Imaging Calibration

[0045] Fix the vision system to the optical platform, place the motion platform 1m in front, and fix the gear to the motion platform; adjust the light source brightness to 2000lm and the angle to 45°, acquire the image and observe that the gray value of the light spot is 150 (8-bit gray level), with no overexposure / underexposure, and complete the calibration.

[0046] S12: The travel range is determined in step 1. The focus motor travel is set to zero, and the motion platform is driven to move from 1.2m (far distance) to 0.8m (near distance) at a speed of 5mm / s. One frame of image is acquired every 0.1mm, and the sharpness D is calculated. When the motion platform is at 1.05m, D reaches its maximum value D1_max = 12500, and A1 = 1.05m is recorded. The focus motor is set to its maximum travel (100mm), and the movement is repeated. When the platform is at 0.95m, D reaches D2_max = 12300, and A2 = 0.95m is recorded. L = A2 - A1 = 0.1m = 100mm is calculated. The depth of field of the imaging unit is 50mm (at a 1m object distance), and step 1 = 50mm / 3 ≈ 16.7mm.

[0047] S13: Spot preprocessing and centroid calculation: The motion platform moves from 1.05m to 0.95m in 16.7mm steps, with a total of 6 step positions (M=6). Three frames are acquired at each position, and the average is taken. The following steps are executed: CLAHE: cliplimit=2.0, tile=8×8, resulting in a 60% improvement in spot grayscale uniformity; Gaussian filtering: 3×3 kernel, σ=1.0, reducing noise intensity from 20dB to 10dB; Median filtering: 3×3 window, removing residual noise. Salt and pepper noise; Binarization fusion: grayscale mean μ=120, T1=144, OTU threshold T2=138, the purity of the fused spot (the proportion of spot pixels in the foreground) reaches 98%; Centroid calculation: the centroids of the 6 step positions are (640,360), (720,360), (800,360), (880,360), (960,360), (1040,360) (pixel coordinates, image resolution 1280×720).

[0048] S14: Optimize the lookup table. Construct the original lookup table: 6 elements are [(640,360,0mm), (720,360,16.7mm), (800,360,33.4mm), (880,360,50.1mm), (960,360,66.8mm), (1040,360,83.5mm)]; Construct the KD tree: Root node: the middle element after sorting by xc (800,360,33.4mm); Left subtree: (640,360,0mm), (720,360,16.7mm), with child node (720,360,16.7mm); Right subtree: (880,360,50.1mm), (960,360,66.8mm), (1040,360,83.5mm), with child node (960,360,66.8mm); Optimized lookup table: Binds the original element to the KD-tree index and stores it in the memory of the calculation module.

[0049] (III) Online Real-Time Focusing Process

[0050] S21: Initialize and load the optimized lookup table, drive the focusing motor to move from 0mm to 83.5mm, acquire the first frame image, and after preprocessing, the centroid (xc0, yc0) = (800, 360); KD tree search: input (800, 360), find the nearest node (800, 360, 33.4mm), and the reference point R0 = (800, 360, 33.4mm).

[0051] S22: Dynamic image acquisition starts the conveyor belt (speed 1m / s). Every time the encoder is triggered (the gear moves 1mm), the image acquisition module acquires one frame of image. After preprocessing, it outputs a binarized image of the light spot. The preprocessing time for a single frame is 0.3ms.

[0052] S23: Occlusion Compensation Test Occlusion rate 10%: Spot area S = 180 pixels (S0 = 200 pixels), complete judgment, centroid (xc, yc) = (840, 360); Occlusion rate 30%: S = 140 pixels, Kalman filter activated, observed value Zk = (860, 358), compensated centroid (xc, yc) = (858, 359), error 0.5 pixels; Occlusion rate 50%: S = 100 pixels, observed value Zk = (890, 355), compensated centroid (xc, yc) = (885, 357), error 1.2 pixels.

[0053] S24: KD tree matching input (840,360): Search to find the nearest node (880,360,50.1mm), target reference point R = (880,360,50.1mm); input (858,359): Search to find the nearest node (880,360,50.1mm), R = (880,360,50.1mm); single frame matching time is 0.7ms.

[0054] S25: Focusing trigger deviation calculation: Input (840,360), d=√[(840-880)] 2 +(360-360) 2 = 40 pixels, T = 21 pixels (step1 = 16.7mm corresponding pixels), d > T, drive the motor to 50.1mm, motor response time is 1.5ms; after focusing, the sharpness is: D = 12400 (close to D1_max = 12500), the image is clear.

[0055] S26: Continuous operation test lasted for 2 hours (conveyor belt moved 7200m), a total of 7200 frames of images were collected, the average focus delay was 4.2ms, and the focus success rate was 96% (only 3 failures due to extreme occlusion rate >50%), which is far superior to the existing solution.

[0056] (iv) Performance Comparison Test

[0057]

[0058]

[0059] Replacing the Kalman filter with a particle filter (100 particles) reduces the compensation error from 1.2 pixels to 0.8 pixels in extreme scenarios with an occlusion rate >50%, but increases the frame time to 1.5ms. This is suitable for scenarios where high precision is prioritized (such as semiconductor detection).

[0060] Replacing the KD tree with a Ball tree (the sphere radius is set based on step 1) improves matching efficiency by 10% in scenarios with uneven distribution of the light spot centroid (such as large yc deviation), and is suitable for workpieces with multi-directional movement.

[0061] By replacing the ring light source with a coaxial light source and using CLAHE preprocessing, the spot purity is increased from 98% to 99.5% in highly reflective metal scenes, making it suitable for automotive parts inspection.

[0062] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A real-time camera focusing method, characterized in that, Includes the following steps: Step S1: Construct an optimized spot centroid-positive focus lookup table offline; Specifically, it includes: S11: setting up an offline fixed-focus platform, setting the vision system in front of the motion platform, placing the object to be tested on the motion platform, the motion direction of the motion platform being parallel to the optical axis of the imaging unit in the vision system, and adjusting the light source parameters and the position of the motion platform to achieve normal imaging of the object to be tested. S12: Drive the motion platform to move along the optical axis, record the first position A1 with the highest image clarity when the focusing motor stroke is zero, and the second position A2 with the highest image clarity when the focusing motor is at its maximum stroke, calculate the stroke range L = A2 - A1 of the motion platform, and set the step distance step1 of the motion platform to the preset ratio of the depth of field of the imaging unit. S13: Drive the motion platform to move from the first position A1 to the second position A2 by the step distance step1. At each step position, acquire the image of the object to be tested. Perform anti-interference preprocessing, spot extraction and spot centroid calculation on the acquired image in sequence to obtain the spot centroid coordinates (xc, yc) corresponding to each step position. S14: Record the data pairs of "spot centroid coordinates (xc, yc) - focusing motor stroke A" corresponding to each step position to form an original lookup table, and construct an efficient retrieval data structure based on the spot centroid coordinates (xc, yc) to obtain an optimized spot centroid-positive focus lookup table; Step S2: Online real-time focus adjustment.

2. The real-time camera focusing method according to claim 1, characterized in that, Step S2 includes: S21: Place the object to be tested within the field of view of the vision system, load the optimized spot centroid-positive focus lookup table, drive the focusing motor to move from the initial stroke to the maximum stroke according to the step distance step1, acquire the first frame image of the object to be tested and perform the spot anti-interference preprocessing and spot centroid calculation to obtain the first frame spot centroid coordinates (xc0, yc0), and obtain the corresponding reference point R0 (x0, y0, A0) through the efficient retrieval data structure matching; S22: Real-time acquisition of images of the object under test, repeated execution of the spot anti-interference preprocessing and spot centroid calculation for each frame of image to obtain the current frame spot centroid coordinates (xc, yc); S23: Determine the integrity of the current frame spot. If the spot is occluded, compensate the centroid coordinates (xc, yc) of the current frame spot using a preset prediction algorithm to obtain the compensated centroid coordinates (xc, yc). If the spot is intact, directly use the centroid coordinates (xc, yc) of the current frame spot as the valid centroid coordinates. S24: Match the effective centroid coordinates or compensated centroid coordinates (xc, yc) using the efficient retrieval data structure to obtain the corresponding target reference point R(x, y, A); S25: Calculate the centroid deviation value d between the effective centroid coordinates or compensated centroid coordinates (xc,yc) and the target reference point R(x,y,A). If the centroid deviation value d is greater than a preset deviation threshold, drive the focusing motor to move to the focusing motor stroke A corresponding to the target reference point R(x,y,A) to complete real-time focusing. S26: Determine whether a stop signal has been received. If a stop signal is received, exit online real-time focusing; if no stop signal is received, return to step S22 and repeat the real-time focusing cycle.

3. The real-time camera focusing method according to claim 1, characterized in that, The beam anti-interference preprocessing in step S13 includes the following sub-steps: S131: Illumination compensation processing, employing at least one illumination compensation algorithm to process the acquired image. The illumination compensation algorithm includes an adaptive histogram equalization algorithm, where the cliplimit value of the adaptive histogram equalization algorithm ranges from 1.0 to 3.

0. S132: Noise suppression processing, employing at least one noise suppression algorithm to process the illumination-compensated image. The noise suppression algorithm includes a combination of a Gaussian filtering algorithm and a median filtering algorithm. The convolution kernel size of the Gaussian filtering algorithm is 3×3-7×7, and the standard deviation σ ranges from 1.0 to 3.

0. The range is 0.5-2.0, and the window size of the median filtering algorithm is 3×3-5×5; S133: Multi-threshold binarization fusion processing, using at least two binarization algorithms to binarize the spot region in the noise-suppressed image to obtain at least two binarized images, performing a logical AND operation on the at least two binarized images to obtain a fused spot binarized image; the binarization algorithm includes a single-threshold binarization algorithm and an OTU binarization algorithm, and the threshold of the single-threshold binarization algorithm is 1.0-1.5 times the average gray level of the image.

4. The real-time camera focusing method according to claim 1, characterized in that, The calculation of the spot centroid in step S13 is achieved using the image moment formula, as follows: Where, m pq Let x be the p-th order moment of the image, N be the total number of pixels contained in the spot region, and x be the x-th order moment. i y i Let f(x) and f(x) be the x and y coordinates of the i-th pixel within the light spot region, respectively. i ,y i Let be the grayscale value of the i-th pixel, where p, q, and i are all non-negative integers, and x... c y c These are the horizontal and vertical coordinates of the centroid of the light spot, respectively, m. 10 Let m be the first to zeroth moments of the image. 00 Let m be the 0-0th order moment of the image. 01 is the 0th-1st moment of the image.

5. The real-time camera focusing method according to claim 1, characterized in that, The efficient retrieval data structure in step S14 is a KD tree. The construction process of the KD tree includes: S141: using all spot centroid coordinates (xc, yc) in the original lookup table as the dataset, determining the dimension of the KD tree to be 2, with the first split dimension being the horizontal coordinate xc of the spot centroid and the second split dimension being the vertical coordinate yc of the spot centroid; S142: sorting the dataset according to the first split dimension xc, and selecting the spot centroid coordinate at the middle position after sorting as the root node of the KD tree; S143: dividing the dataset into a subset to the left of the root node (xc is less than the root node xc) and a subset to the right of the root node (xc is greater than the root node xc), repeating the sorting and middle node selection in step S142 for each subset according to the second split dimension yc, and generating child nodes and leaf nodes of the KD tree in sequence until all dataset elements are added to the KD tree as nodes, thus completing the construction of the efficient retrieval data structure.

6. The real-time camera focusing method according to claim 1, characterized in that, In step S21, the initial stroke is the minimum stroke of the focusing motor. The matching process of the first frame spot centroid coordinates (xc0, yc0) is as follows: the optimized spot centroid-focus lookup table is traversed by the KD tree nearest neighbor search algorithm to find the "spot centroid coordinates-focus motor stroke" data pair with the smallest Euclidean distance to (xc0, yc0), which is used as the reference point R0(x0, y0, A0).

7. The real-time camera focusing method according to claim 1, characterized in that, In step S23, the criterion for determining whether the light spot is occluded is: the pixel area of ​​the light spot region in the current frame is less than a preset ratio of the pixel area of ​​the historical normal light spot. The preset prediction algorithm is a Kalman filter algorithm, and the mathematical expression of the Kalman filter algorithm is as follows: State equation: X k =AX k-1 +BU k-1 +W k ; Observation equation: Z k =HX k +V k Among them, X k =[x c,k ,y c,k ] T Let A be the state vector at time k, and let A be the state transition matrix. B is the control input matrix. U k-1 This is the control input at time k-1; W k The process noise follows a Gaussian distribution with a mean of 0 and a covariance matrix of Q, where Q = diag([q1,q2]), and the values ​​of q1 and q2 range from 0.01 to 0.

1. Let H be the observation vector at time k, and H be the observation matrix. V k To observe the noise, we assume it follows a Gaussian distribution with a mean of 0 and a covariance matrix of R, where R = diag([r1,r2]), and the values ​​of r1 and r2 range from 0.05 to 0.

5. The compensated centroid coordinates (xc, yc) are the optimal estimates obtained through Kalman filtering. It is obtained through prediction-update iteration using Kalman filtering.

8. The real-time camera focusing method according to claim 1, characterized in that, In step S24, the matching process of the efficient retrieval data structure is as follows: input the effective centroid coordinates or compensated centroid coordinates (xc, yc) into the KD tree, traverse the optimized spot centroid-focus lookup table through the NN search algorithm of the KD tree, and output the "spot centroid coordinates-focusing motor travel" data pair with the smallest Euclidean distance from the input coordinates as the target reference point R(x, y, A).

9. The real-time camera focusing method according to claim 1, characterized in that, In step S25, the centroid deviation value d is calculated using the Euclidean distance formula, as follows: Where, x c,eff y c,eff The horizontal and vertical components of the effective centroid coordinates or compensated centroid coordinates (xc, yc) are respectively, and x and y are respectively the horizontal and vertical components of the target reference point R(x, y, A); the preset deviation threshold is the pixel distance corresponding to the step distance step1.

10. A real-time adjustable camera focusing system for implementing the real-time adjustable camera focusing method according to any one of claims 1-9: characterized in that, The system includes: Hardware modules: The image acquisition module is used to acquire images of the object under test, including a CMOS image sensor and an industrial lens; the motion control module is used to drive the focusing motor and motion platform, including a stepper motor driver and a motion control card; the light source module is used to provide illumination, including an industrial light source with adjustable brightness. Software module: Spot anti-interference processing submodule, used to perform spot anti-interference preprocessing; The centroid calculation submodule is used to perform spot centroid calculation; The lookup table management submodule is used to build efficient retrieval data structures and optimize lookup tables; The spot prediction submodule is used to perform Kalman filter compensation; The focus control submodule is used to perform matching and focus triggering; The hardware module and software module are connected via a data bus. The output of the image acquisition module is connected to the input of the spot anti-interference processing submodule. The output of the spot anti-interference processing submodule is connected to the input of the centroid calculation submodule. The output of the centroid calculation submodule is connected to the inputs of the lookup table management submodule and the spot prediction submodule. The output of the lookup table management submodule is connected to the input of the focus control submodule. The output of the spot prediction submodule is connected to the input of the focus control submodule. The output of the focus control submodule is connected to the input of the motion control module.

Citation Information

Cited By

  • Automatic focusing method and system for atomic imaging

    CN121784950A

  • An autofocus method and system for atomic imaging

    CN121784950B