Industrial camera auto-focusing method based on neural network and three-stage progressive hill climbing algorithm

By combining neural networks with a three-level progressive hill-climbing algorithm, efficient and accurate autofocus of industrial cameras is achieved, solving the problems of slow focusing speed, low accuracy and weak anti-interference ability in existing technologies. It is suitable for posture measurement of industrial robots.

CN122496716APending Publication Date: 2026-07-31SICHUAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SICHUAN UNIV
Filing Date
2026-04-30
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing industrial camera autofocus technology cannot simultaneously solve the problems of low focusing efficiency over a wide range, slow convergence of high-precision focusing, easy getting stuck in local extrema, weak anti-interference ability in industrial scenes, and insufficient focusing accuracy in zoom scenes.

Method used

A two-stage focusing architecture based on neural networks and a three-level progressive hill-climbing algorithm is adopted. It combines coarse focusing regression neural networks and three-level progressive fine focusing. The neural network enables fast coarse focusing without searching over a wide range, while the Tenengrad sharpness evaluation and target detection algorithms enable high-precision fine focusing that is resistant to local extrema.

Benefits of technology

It achieves efficient autofocus that balances speed and accuracy, is suitable for industrial robot posture measurement scenarios, improves focusing speed and accuracy, enhances robustness, and is applicable to various industrial inspection scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122496716A_ABST
    Figure CN122496716A_ABST
Patent Text Reader

Abstract

This invention belongs to the field of industrial machine vision autofocus technology, and discloses an industrial camera autofocus method based on neural networks and a three-level progressive hill-climbing algorithm. It employs a two-stage architecture: coarse focusing via neural networks and fine focusing via three levels. In the coarse focusing stage, a coarse focusing regression neural network model fuses the current focal length parameters and the target image, directly outputting the predicted difference between the current image distance and the optimal sharp image distance, quickly locking the near-focus area. In the fine focusing stage, a target recognition algorithm identifies the target area as the focusing window. Combined with a three-level progressive hill-climbing search algorithm and Tenengrad gradient sharpness evaluation, the search range is gradually narrowed through three levels of coarse adjustment, fine adjustment, and micro-adjustment, and a sharpness threshold difference is set to avoid local extrema, ultimately locating the optimal focusing position. This invention solves the problem of inappropriate focusing window selection in traditional methods, meeting the speed, accuracy, and robustness requirements of focusing in industrial scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of industrial machine vision autofocus technology, specifically relating to an industrial camera autofocus method based on neural networks and a three-level progressive hill-climbing algorithm. Background Technology

[0002] In fields such as industrial inspection, precision manufacturing, and robotic processing, the autofocus capability of industrial cameras directly determines the image acquisition quality, which in turn affects the accuracy of subsequent feature extraction, target recognition, and pose calculation. Especially in the pose measurement scenario of zoom monocular vision robots, the camera needs to dynamically adjust the focal length according to the measurement distance. The focusing accuracy directly determines the measurement accuracy of the pose angle. Industrial scenarios require a pose measurement accuracy better than 0.05°, which places extremely high demands on the speed, accuracy, and anti-interference capability of autofocus.

[0003] Currently, the mainstream autofocus technologies for industrial cameras are mainly divided into two categories: One approach is search-based focusing methods based on traditional image sharpness evaluation, such as hill-climbing search algorithms, golden section search algorithms, and Laplacian variance sharpness evaluation. Among these, the hill-climbing search algorithm is the most widely used in industrial scenarios due to its simple logic and ease of implementation. However, this method has significant drawbacks: fixed-step search strategies cannot balance focusing speed and accuracy; large-step searches converge quickly but lack accuracy, while small-step searches have high accuracy but take a very long time to focus over a large area, making them unsuitable for the large-area, rapid focusing requirements of industrial scenarios; traditional hill-climbing algorithms are highly susceptible to noise and lighting fluctuations in industrial scenarios, easily getting stuck in local extrema and leading to focusing failure; traditional Laplacian variance sharpness evaluation algorithms have poor noise resistance and insufficient accuracy in evaluating low-contrast, weak-texture target areas in industrial scenarios, resulting in a flat sharpness curve that makes it difficult to accurately lock the focus peak; traditional focusing windows often use fixed central or golden section areas, which cannot adapt to the target position and are prone to misfocusing problems such as "sharp background, blurry target," directly affecting the accuracy of subsequent attitude calculations.

[0004] Second, there are deep learning-based autofocus methods that directly predict the focus position or sharpness level through neural networks to achieve rapid focusing. However, existing deep learning focusing methods have significant shortcomings: poor generalization of end-to-end focus prediction, and in industrial scenarios with different focal lengths and targets, the prediction accuracy cannot meet industrial-grade requirements; relying solely on neural networks cannot achieve micron-level high-precision focusing, and can only complete coarse focusing over a wide range, making it difficult to adapt to the needs of precision industrial inspection and attitude measurement; existing networks mostly use images as input without incorporating camera focal length parameters, resulting in a significant drop in prediction accuracy in zoom scenarios.

[0005] Therefore, existing industrial camera autofocus technology cannot simultaneously solve problems such as "low focusing efficiency over a wide range", "slow convergence of high-precision focusing", "easy to get stuck in local extrema", "weak anti-interference ability in industrial scenarios" and "insufficient focusing accuracy in zoom scenarios". There is an urgent need for an autofocus solution that takes into account speed, accuracy and robustness and is suitable for industrial robot posture measurement scenarios. Summary of the Invention

[0006] The purpose of this invention is to provide an industrial camera autofocus method based on neural networks and a three-level progressive hill-climbing algorithm. It adopts a two-stage architecture of "neural network coarse focusing and three-level progressive fine focusing". It achieves fast coarse focusing without searching over a wide range through neural networks, and achieves high-precision fine focusing with resistance to local extrema through deep integration of the three-level progressive hill-climbing algorithm and Tenengrad sharpness evaluation. At the same time, it combines a target detection algorithm to achieve adaptive target area recognition, which solves the problem of improper selection of the traditional focus window and meets the speed, accuracy and robustness requirements of focusing in industrial scenarios.

[0007] To achieve the above objectives, the present invention adopts the following technical solution: An autofocus method for industrial cameras based on neural networks and a three-level progressive hill-climbing algorithm includes the following steps: Step 1: Trigger autofocus, acquire the current focal length parameters and real-time image of the industrial camera, obtain the predicted difference between the current image distance and the optimal sharp image distance based on the coarse focus regression neural network model, and control the drive motor to adjust the image distance according to the predicted difference to complete coarse focus and lock a near-focus range containing the optimal focus position. The coarse focus regression neural network model comprises an improved dilated convolutional ResNet50 backbone network, a dilated spatial pyramid pooling module, an SE channel attention module, a feature fusion module, and a prediction head, connected in sequence. The improved dilated convolutional ResNet50 backbone network extracts multi-scale features from the input image; the dilated spatial pyramid pooling module fuses the multi-scale features; the SE channel attention module performs channel weighting on the fused features to enhance focus-related features; and the feature fusion module concatenates and fuses the image features output by the SE channel attention module with the input focal length parameters, and outputs the prediction difference through the prediction head. Step 2: Use a target detection algorithm to identify the target region in the image, and use the identified target region as the focus window; combine a three-level progressive hill-climbing search algorithm and a Tenengrad sharpness evaluation algorithm to perform focus search within the near-focus range; The three-level progressive hill-climbing search algorithm employs three search stages with progressively decreasing step sizes: coarse adjustment search stage, fine adjustment search stage, and fine adjustment search stage, to gradually narrow the focus range; and sets a sharpness threshold difference during the search process to avoid local extrema. Step 3: After completing the focus search, locate the image distance position with the highest Tenengrad sharpness evaluation value, control the industrial camera to adjust the image distance to that position, and complete the autofocus.

[0008] Furthermore, the improved dilated convolutional ResNet50 backbone network modifies the stride of the third and fourth residual layers of the standard ResNet50 to 1, introduces dilated convolutions with an inflation factor of 2 in the third residual layer, and introduces dilated convolutions with an inflation factor of 4 in the fourth residual layer, thereby reducing the downsampling factor of the network from 32 times to 8 times.

[0009] Furthermore, the hollow space pyramid pooling module includes parallel 1×1 convolution branches, 3×3 hollow convolution branches with dilation rates of 6, 12, and 18, and a global average pooling branch.

[0010] Furthermore, the target detection algorithm adopts the YOLOv9 model.

[0011] Furthermore, the step size of the three-level progressive hill-climbing search algorithm is set as follows: the step size of the coarse-tuning search stage is the first step size, the step size of the fine-tuning search stage is the second step size, and the step size of the fine-tuning search stage is the third step size, and the first step size > the second step size > the third step size. The three-level progressive hill-climbing search algorithm includes: Coarse adjustment search stage: Starting from the image distance after coarse focusing, the Tenengrad sharpness evaluation value of the target area of ​​the corresponding image is calculated frame by frame according to the first step of bidirectional traversal within the near-focus range. The sub-interval where the peak of the evaluation value is located is located to complete the coarse adjustment search and narrow the focus range. Fine-tuning search phase: Using the sub-interval locked by the coarse-tuning search as the search range, perform bidirectional traversal according to the second step size, calculate the Tenengrad sharpness evaluation value frame by frame, locate the smaller sub-interval where the peak of the evaluation value is located, and complete the fine-tuning search; Fine-tuning search phase: Using the sub-interval locked by the fine-tuning search as the search range, the entire interval is traversed according to the third step length. The Tenengrad sharpness evaluation value is calculated frame by frame. The image distance position corresponding to the global maximum value of the evaluation value is found, and the fine-tuning search is completed.

[0012] Furthermore, the Tenengrad gradient sharpness evaluation algorithm is as follows: the horizontal and vertical gradients of the image grayscale values ​​within the focus window are calculated based on the Sobel operator, the gradient magnitude of each pixel is calculated, and the average of the gradient magnitudes of all pixels within the focus window is used as the final Tenengrad sharpness evaluation value. , in, This is the Tenengrad clarity rating. and Each pixel The horizontal and vertical gradients at the location, and These are the width and height of the focus window, respectively.

[0013] Furthermore, a sharpness threshold difference is set to avoid local extremes, including: in each search process, the difference between the Tenengrad sharpness evaluation values ​​corresponding to two adjacent image distance positions is calculated. If the difference is less than the preset absolute sharpness threshold difference, the current area is determined to be a flat area and not identified as a peak interval, and the search range is further expanded.

[0014] Compared with the prior art, the present invention has the following beneficial effects: (1) A two-stage focusing architecture of "neural network coarse focusing + three-level progressive fine focusing" is adopted, which takes into account both the focusing efficiency of a wide range and the high-precision focusing requirements of industrial grade. In the coarse focusing stage, the image distance difference is predicted in one step by the neural network, without the need to traverse and search frame by frame, which compresses the large-range coarse focusing of traditional methods in the form of several seconds to the form of hundreds of milliseconds; in the fine focusing stage, high-precision focusing is achieved in the near-focus range through three-level progressive search, which meets the requirements of speed and accuracy.

[0015] (2) By using a three-level progressive hill climbing search algorithm, the step size is gradually reduced, which can quickly narrow the focus range with a large step size and ensure the final focus accuracy with a small step size. This solves the problem that traditional fixed step size hill climbing algorithms cannot balance speed and accuracy. At the same time, an absolute sharpness threshold difference constraint is set to effectively avoid the problem that the algorithm is prone to getting trapped in local extreme values ​​in industrial scenarios.

[0016] (3) The Tenengrad gradient sharpness evaluation algorithm based on the Sobel operator is adopted, which effectively suppresses the interference of noise and light fluctuation in industrial scenes on sharpness evaluation. It can still achieve accurate sharpness evaluation for industrial target areas with weak texture and low contrast. At the same time, the sharpness curve of the algorithm has the characteristics of single peak and sharpness, which can more accurately lock the focus peak and has a robustness far superior to the traditional Laplace variance algorithm.

[0017] (4) The target area is adaptively identified by the target detection algorithm. The target area is used as the focusing window for fine focusing. This solves the problem of misfocusing where the background is clear but the target is blurry when the traditional fixed focusing window is used. It also eliminates the interference of the background area on the sharpness evaluation and greatly improves the focusing accuracy.

[0018] (5) By improving the ResNet50 network with dilated convolution as a coarse focus regression neural network, the downsampling factor is reduced to 8 times, which preserves the fine-grained focus features to the greatest extent; multi-scale blur features are captured by ASPP module; effective focus features are enhanced by SE channel attention; and a focal length parameter post-fusion strategy is adopted to achieve accurate image distance difference prediction at different focal lengths. It has strong generalization and is suitable for industrial application scenarios of zoom cameras.

[0019] (6) No complex hardware modification is required. High-precision and fast autofocus of industrial cameras can be achieved through software algorithms alone. It is compatible with different models of industrial cameras and different industrial inspection scenarios, and has extremely high engineering application value and commercial promotion prospects. Attached Figure Description

[0020] Figure 1 This is a schematic diagram of the process of the present invention.

[0021] Figure 2 This is a schematic diagram of the coarse-focusing regression neural network model structure of the present invention.

[0022] Figure 3 This is a schematic diagram of the improved dilated convolutional ResNet50 backbone network structure of this invention.

[0023] Figure 4 This is a schematic diagram of the hollow space pyramid pooling module structure of the present invention.

[0024] Figure 5 This is a graph showing the true error of the model on the test set during the training process of this invention.

[0025] Figure 6 This is an example illustration of the coarse focusing method of the present invention.

[0026] Figure 7 This is an example of the autofocus result of the present invention. Detailed Implementation

[0027] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.

[0028] like Figure 1 As shown in the figure, this embodiment discloses an industrial camera autofocus method based on neural networks and a three-level progressive hill-climbing algorithm, which includes the following steps: Step 1: Trigger autofocus, acquire the current focal length parameters and real-time image of the industrial camera, obtain the predicted difference between the current image distance and the optimal sharp image distance based on the coarse focus regression neural network model, and control the drive motor to adjust the image distance according to the predicted difference to complete coarse focus and lock a near-focus range containing the optimal focus position.

[0029] like Figure 2 As shown, the coarse focus regression neural network model includes an improved dilated convolutional ResNet50 backbone network, a dilated spatial pyramid pooling module, a channel attention module, a feature fusion module, and a prediction head, as follows: Figure 3 As shown, the improved dilated convolutional ResNet50 backbone network includes an input layer, a first residual layer, a second residual layer, a third residual layer, and a fourth residual layer. The input layer includes a convolutional layer (7×7 convolutional kernels, 64 filters, stride of 2) and a max pooling layer (3×3 pooling kernels, stride of 2). The first residual layer includes 3 residual blocks, each with 64 filters; the second residual layer includes 4 residual blocks, each with 128 filters; the third residual layer includes 6 residual blocks, each with 256 filters; and the fourth residual layer includes 3 residual blocks, each with 512 filters. Each residual block consists of three convolutional layers with kernels of 1×1, 3×3, and 1×1, respectively. In this embodiment, the stride of the convolutional layers in the third and fourth residual layers is set to 1 (the stride of traditional networks is 2). A dilated convolution with an inflation factor of 2 is introduced into the 3×3 convolutional layer of the third residual layer, with padding of 2. A dilated convolution with an inflation factor of 4 is introduced into the 3×3 convolutional layer of the fourth residual layer, with padding of 4. The final network outputs a feature map with a stride of 8 and 2048 channels. This reduces the downsampling factor of the network from 32x to 8x. The receptive field is expanded without increasing the number of parameters, while retaining high-resolution focusing features.

[0030] The hollow spatial pyramid pooling module has 2048 input channels and 256 output channels. It includes 5 parallel branches: a 1×1 convolution branch, a 3×3 hollow convolution branch with dilation rates of 6, 12, and 18, and a global average pooling branch. The output features of each branch are spliced ​​after being bilinearly upsampled to a uniform size, and then reduced to 256 channels by 1×1 convolution. Finally, they are output after batch normalization, ReLU activation, and Dropout regularization.

[0031] The channel attention module has 256 input channels and 16 output channels. It compresses the feature map into a channel-dimensional vector through global average pooling, generates channel weights through two fully connected layers, and performs channel weighting on the feature map output by the multi-scale feature fusion module to enhance focus-related features.

[0032] The feature fusion module is used to flatten the feature map weighted by the SE module into a 256-dimensional vector through adaptive global average pooling, reduce the dimension to 32-dimensional through the first fully connected layer, and concatenate it with the input focal length parameter (1-dimensional). Finally, the prediction head (the second fully connected layer) outputs a 1-dimensional scalar, which is the difference between the current image distance and the optimal sharp image distance.

[0033] We collected target images with different image distances at common focal lengths of 20.7~48.3mm using industrial cameras, acquiring a total of 1400 valid samples. The optimal sharp image distance was defined as the image distance corresponding to the global maximum Tenengrad sharpness evaluation value at the same focal length. The true difference between the current image distance and the optimal sharp image distance for each sample was labeled. The dataset was randomly divided into training and validation sets in an 8:2 ratio. Data augmentation was performed using methods such as rotation, mirroring, adding Gaussian noise, and simulating defocus blur to improve model robustness.

[0034] The Adam optimizer was used, with an initial learning rate of 0.001, a mean squared error loss function (MSE), a batch size of 8, and 100 training epochs. Figure 5 As shown, the model's loss decreased rapidly in the early stages of training, while the validation accuracy improved simultaneously, indicating that the network can quickly learn the mapping relationship between focus features and offset. In the middle stages of training, the loss stabilized, and the validation accuracy showed no significant fluctuations, with no obvious overfitting or underfitting. In the later stages of training, the model fully converged, the loss remained stable, the average true error was controlled within 50 pixel units, and the regression accuracy reached over 92%, meeting the requirements of the coarse focus design. After each training epoch, the model was validated using a validation set. Training was terminated early when the validation set loss no longer decreased after 10 consecutive epochs. During training, the learning rate was dynamically adjusted using the CosineAnnealingLR scheduler, and the converged, well-trained coarse focus regression neural network model was ultimately saved.

[0035] Step 2: Use the YOLO target detection algorithm to identify the target region in the coarsely focused image, and use the identified target region as the focus window; combine the three-level progressive hill climbing search algorithm and the Tenengrad gradient sharpness evaluation algorithm to perform focus search in the near-focus range; After coarse focusing, the real-time image is used to perform target detection using a trained YOLOv9 model. The bounding box coordinates of the target region are output, and this region is cropped as the focus window to eliminate background interference. The YOLO model can accurately identify the target region, even in semi-clear images, and can accurately lock the target position.

[0036] Training the YOLOv9 model: 1000 target images of varying resolution, pose, and distance were used, divided into training and validation sets in an 8:2 ratio. The YOLOv9 model input size was 640×640 pixels, with a batch size of 8, 300 training epochs, and an SGD optimizer with an initial learning rate of 0.01. After training, the YOLOv9 model achieved a target region recognition accuracy of over 98% on the test set, accurately identifying target bounding boxes in partially sharp, coarsely focused images.

[0037] The three-level progressive hill-climbing search algorithm includes three search stages with progressively decreasing step sizes: coarse adjustment search stage, fine adjustment search stage, and fine adjustment search stage, in order to gradually narrow the focus range; and a sharpness threshold difference is set during the search process to avoid local extrema.

[0038] Coarse adjustment search phase: Taking the image distance after coarse focusing as the center starting point, the search range is set to ±500 micrometers. The search is performed bidirectionally in steps of 100 micrometers. Each time the image distance is adjusted, an image frame is acquired and its Tenengrad evaluation value is calculated. After the traversal is completed, the 100-micrometer sub-interval where the peak of the evaluation value is located is located, and the coarse adjustment search is completed, reducing the focusing range from ±500 micrometers to 100 micrometers.

[0039] Fine-tuning search phase: Using the 100-micron sub-range locked by the coarse-tuning search as the search range, bidirectional traversal is performed with a step size of 15 microns. The Tenengrad evaluation value is calculated frame by frame, and the 15-micron sub-range where the peak of the evaluation value is located is located to complete the fine-tuning search and further narrow the focus range.

[0040] Fine-tuning search phase: Using the 15-micron sub-interval locked by the fine-tuning search as the search range, the entire interval is traversed in steps of 5 microns. The Tenengrad evaluation value is calculated frame by frame. The image distance position corresponding to the global maximum value of the evaluation value is found, and the fine-tuning search is completed.

[0041] In each level of the search process, an absolute sharpness threshold difference of 50 is set. If the difference in Tenengrad evaluation values ​​between two adjacent image distance positions is less than 50, the current region is determined to be a flat area and not a peak interval, and the search range is further expanded. This mechanism effectively avoids the algorithm from getting stuck in local extrema due to noise and lighting fluctuations, ensuring that the globally optimal focus position is found.

[0042] Tenengrad evaluation values ​​are calculated for each frame of the acquired image. The target region of interest (ROI) is cropped and converted into a grayscale image. A 3×3 Sobel horizontal and vertical template is used to calculate the horizontal gradient of each pixel in the grayscale image. with vertical gradient The gradient magnitude of each pixel is calculated using a formula. Finally, the summation and averaging are used to obtain the Tenengrad sharpness rating of the entire image. , and Each pixel The horizontal and vertical gradients at the location, and These represent the width and height of the focus window, respectively. The Sobel operator's 3×3 neighborhood template has a built-in weighted smoothing effect, which can effectively suppress image noise in industrial scenes and ensure the accuracy of sharpness evaluation.

[0043] Step 3: After completing the three-level search, locate the image distance position with the highest Tenengrad sharpness evaluation value, control the industrial camera to adjust the image distance to that position, and complete the autofocus.

[0044] The industrial camera used is a Basler acA2040-180km global shutter camera with a resolution of 4096×3000 and a pixel size of 3.45×3.45μm; the zoom lens has a focal length range of 16~96mm; the image distance drive uses a high-precision stepper motor, with a minimum image distance adjustment unit of 1 micrometer; the cooperative target is a 3D target with 14 reflective feature points, and the target size is 200×150mm; the host computer uses an Intel i7-12650H CPU, an NVIDIA GeForce RTX 4050 GPU, and runs the Windows 11 operating system. The software environment includes Python 3.9, PyTorch 2.0.1, OpenCV 4.8.0, and CUDA 11.8.

[0045] Using the method described in this embodiment, the entire autofocus process takes less than 800ms, with a focusing accuracy of 5 micrometers and a focusing success rate of 99.8%. Figure 6 Three sets of coarse focusing results at different focal lengths are shown. The left side is the initial image, and the right side is the image after coarse focusing. After coarse localization by this network, the image can quickly reach a state where the target is recognizable, the fine focusing search range is reduced by more than 80%, and the focusing time is significantly reduced, verifying the effectiveness and practicality of this coarse focusing module. Figure 7 The results demonstrate the sharpness and focus of some examples, achieving an average recognition accuracy of 90% while maintaining a high success rate, further validating the reliability and robustness of the focus detection algorithm. Compared to traditional fixed-step hill-climbing algorithms, the focusing speed is improved by over 70%, and the focusing accuracy is improved by an order of magnitude. Compared to the golden section search algorithm, it effectively avoids local extrema problems, improving the focusing success rate by over 25%.

[0046] In industrial robot attitude measurement applications, within a measurement range of 3-7m and an attitude angle measurement range of ±30°, the yaw and roll angle measurement accuracy is better than 0.05°, fully meeting the application requirements of high-precision machining for aerospace assembly robots.

[0047] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. An industrial camera automatic focusing method based on a neural network and a three-stage progressive hill climbing algorithm, characterized in that, Includes the following steps: Step 1: Trigger autofocus, acquire the current focal length parameters and real-time image of the industrial camera, obtain the predicted difference between the current image distance and the optimal sharp image distance based on the coarse focus regression neural network model, and control the drive motor to adjust the image distance according to the predicted difference to complete coarse focus and lock a near-focus range containing the optimal focus position. The coarse focus regression neural network model includes an improved dilated convolutional ResNet50 backbone network, a dilated spatial pyramid pooling module, an SE channel attention module, a feature fusion module, and a prediction head connected in sequence. The improved dilated convolutional ResNet50 backbone network extracts multi-scale features from the input image. The hollow space pyramid pooling module fuses multi-scale features; the SE channel attention module performs channel weighting on the fused features to enhance focus-related features. feature The fusion module concatenates and fuses the image features output by the SE channel attention module with the input focal length parameters, and outputs the prediction difference through the prediction head; Step 2: Use a target detection algorithm to identify the target region in the image, and use the identified target region as the focus window; combine a three-level progressive hill-climbing search algorithm and a Tenengrad sharpness evaluation algorithm to perform focus search within the near-focus range; The three-level progressive hill-climbing search algorithm employs three search stages with progressively decreasing step sizes: coarse adjustment search stage, fine adjustment search stage, and fine adjustment search stage, to gradually narrow the focus range; and sets a sharpness threshold difference during the search process to avoid local extrema. Step 3: After completing the focus search, locate the image distance position with the highest Tenengrad sharpness evaluation value, control the industrial camera to adjust the image distance to that position, and complete the autofocus.

2. The industrial camera auto-focusing method based on neural network and three-level progressive hill climbing algorithm according to claim 1, characterized in that, The improved dilated convolutional ResNet50 backbone network modifies the stride of the third and fourth residual layers of the standard ResNet50 to 1, introduces dilated convolutions with an inflation factor of 2 in the third residual layer, and introduces dilated convolutions with an inflation factor of 4 in the fourth residual layer, thereby reducing the downsampling factor of the network from 32 times to 8 times. 3.The industrial camera auto-focusing method based on neural network and three-stage progressive hill climbing algorithm according to claim 1, wherein, The hollow space pyramid pooling module includes parallel 1×1 convolution branches, 3×3 hollow convolution branches with dilation rates of 6, 12, and 18, and a global average pooling branch.

4. The industrial camera auto-focusing method based on neural network and three-level progressive hill climbing algorithm according to claim 1, characterized in that, The target detection algorithm uses the YOLOv9 model.

5. The method of claim 1, wherein the method further comprises: The step size of the three-level progressive hill-climbing search algorithm is set as follows: the step size of the coarse-tuning search stage is the first step size, the step size of the fine-tuning search stage is the second step size, and the step size of the fine-tuning search stage is the third step size, and the first step size > the second step size > the third step size. The three-level progressive hill-climbing search algorithm includes: Coarse adjustment search stage: Starting from the image distance after coarse focusing, the Tenengrad sharpness evaluation value of the target area of ​​the corresponding image is calculated frame by frame according to the first step of bidirectional traversal within the near-focus range. The sub-interval where the peak of the evaluation value is located is located to complete the coarse adjustment search and narrow the focus range. Fine-tuning search phase: Using the sub-interval locked by the coarse-tuning search as the search range, perform bidirectional traversal according to the second step size, calculate the Tenengrad sharpness evaluation value frame by frame, locate the smaller sub-interval where the peak of the evaluation value is located, and complete the fine-tuning search; Fine-tuning search phase: Using the sub-interval locked by the fine-tuning search as the search range, the entire interval is traversed according to the third step length. The Tenengrad sharpness evaluation value is calculated frame by frame. The image distance position corresponding to the global maximum value of the evaluation value is found, and the fine-tuning search is completed.

6. The industrial camera autofocus method based on neural networks and a three-level progressive hill-climbing algorithm according to claim 1 or 5, characterized in that, The Tenengrad gradient sharpness evaluation algorithm is as follows: the horizontal and vertical gradients of the image grayscale values ​​within the focus window are calculated based on the Sobel operator, the gradient magnitude of each pixel is calculated, and the average of the gradient magnitudes of all pixels within the focus window is used as the final Tenengrad sharpness evaluation value. , in, This is the Tenengrad clarity rating. and Each pixel The horizontal and vertical gradients at the location, and These are the width and height of the focus window, respectively.

7. The industrial camera autofocus method based on neural network and three-level progressive hill-climbing algorithm according to claim 6, characterized in that, To avoid local extremes, a sharpness threshold difference is set. This includes: calculating the difference in Tenengrad sharpness evaluation values ​​between two adjacent image distance positions during each search. If the difference is less than the preset absolute sharpness threshold difference, the current area is determined to be a flat area and not a peak area, and the search range is further expanded.