A programmatic auto exposure method and system for machine vision long range displacement monitoring

By acquiring target template images, calculating the proportion of dark areas and grayscale histograms, and optimizing exposure and gain parameters, the problem of unstable illumination in machine vision long-distance displacement monitoring was solved, achieving high-precision target imaging and displacement monitoring.

CN121194072BActive Publication Date: 2026-07-31GUANGZHOU HANNAN ENG TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GUANGZHOU HANNAN ENG TECH CO LTD
Filing Date
2025-10-11
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

In machine vision long-distance displacement monitoring systems, unstable lighting conditions lead to poor target imaging quality, reduced contrast, and blurred boundaries, affecting feature extraction and center positioning accuracy. Existing technologies are unable to effectively eliminate background interference and adapt to lighting changes in multiple regions of interest.

Method used

By acquiring target template images, calculating the proportion of dark areas and grayscale histograms, optimizing exposure and gain parameters, employing multi-ROI collaborative metering and one-to-one target-template matching, establishing a bi-peak difference scoring system, and dynamically optimizing exposure-gain parameters, the image quality of the target is ensured.

Benefits of technology

It improves the contrast and boundary clarity of target imaging, enhances feature contrast, achieves sub-pixel level displacement monitoring accuracy, reduces the need for manual parameter adjustment, and improves the stability and accuracy of the monitoring system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121194072B_ABST
    Figure CN121194072B_ABST
Patent Text Reader

Abstract

This application relates to the field of machine vision inspection technology, and discloses a programmed automatic exposure method and system for machine vision long-distance displacement monitoring. The method includes: acquiring template images corresponding to each target and calculating the proportion of dark areas; capturing camera video streams, performing standardized scaling on the regions of interest in the images, and generating grayscale histograms through horizontal stitching or weighted accumulation; analyzing the grayscale histograms, determining the dark area endpoints and peak values ​​of bright and dark areas based on the dark area proportions, calculating boundary scores and bimodal difference scores, and weighting them to obtain the final score; and determining the optimal exposure value and optimal gain value step by step to constitute programmed automatic exposure parameters. This system corresponds to this method. Using this application, dynamic automatic optimization of exposure parameters is achieved, ensuring stable target imaging quality and effectively improving the accuracy and reliability of machine vision long-distance displacement monitoring.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of machine vision inspection technology, specifically a programmed automatic exposure method and system for long-distance displacement monitoring using machine vision. Background Technology

[0002] In previous machine vision-based long-range high-precision micro-displacement monitoring systems, the image quality of the target in the vision camera directly affected the monitoring accuracy. Long-range machine vision displacement monitoring systems require significant contrast between the dark and bright areas of the target image, with clear boundaries. However, in practical applications, the instability of lighting conditions (such as changes in ambient light intensity and uneven light sources) often leads to the following problems in the acquired images: 1) reduced contrast, blurring target features; 2) diffusion in boundary transition areas, causing inaccurate edge localization; 3) local overexposure or underexposure, affecting the integrity of feature extraction. These problems significantly interfere with the center localization accuracy of the target's bright areas. Therefore, developing dynamically adjustable exposure parameters (exposure time and gain) to optimize image quality has become a key technical challenge for improving the accuracy of micro-displacement detection.

[0003] The closest existing technology to this invention is the traditional global or local brightness equalization metering method. These technologies have significant limitations in practical applications. These limitations are mainly twofold: First, they have inherent deficiencies in anti-interference capabilities. Global and local area metering struggle to effectively eliminate interference from non-target areas (such as overexposed centers or peripheral stray light), and neither can achieve coordinated metering of multiple regions of interest (ROIs), making it difficult to obtain effective metering results in complex detection scenarios (such as multi-target displacement monitoring). Second, they have limitations in dynamic adaptability, often relying on fixed algorithms or manual presets, and cannot autonomously optimize exposure parameters based on the structural characteristics of specific targets. Summary of the Invention

[0004] The purpose of this application is to provide a programmed automatic exposure method and system for long-distance displacement monitoring using machine vision, so as to solve the technical problems mentioned in the background art.

[0005] To achieve the above objectives, this application discloses the following technical solutions: In a first aspect, this application discloses a programmed automatic exposure method for long-distance displacement monitoring using machine vision, the method comprising the following steps: S1 - Preprocessing: Obtain template images corresponding to each target in the monitoring scene, and calculate the dark area ratio based on the template images; S2 - Real-time frame processing: Continuously captures camera video streams and performs normalization processing on each frame image. The normalization processing includes: extracting the corresponding region of interest according to the bounding box coordinates of the region of interest of each target, normalizing and scaling each region of interest by a scaling ratio matching the target number, and generating a grayscale histogram by integrating grayscale information from multiple regions. S3 - Evaluation and Scoring: Analyze the grayscale histogram output in step S2, determine the dark area end point based on the dark area proportion and the cumulative number of pixels, and determine the grayscale value with the highest frequency in the dark area and the bright area based on the dark area end point as the dark area peak and the bright area peak, respectively; calculate the boundary score based on the dark area end point, and calculate the bimodal difference score by the difference between the dark area peak and the bright area peak; then, use a preset weighting coefficient to perform a weighted average of the boundary score and the bimodal difference score to obtain the final score; S4 - Parameter Optimization: Determines the optimal exposure and gain values ​​through a step-by-step optimization strategy, including: S41: Fix the gain value as the preset intermediate value, traverse all preset exposure values, perform steps S2-S3 on the image corresponding to each exposure value to obtain the corresponding final score, select the exposure value corresponding to the highest final score as the optimal exposure value and fix it; S42: Based on the optimal exposure value, the gain value is optimized according to the coarse adjustment stage and the fine adjustment stage to finally obtain the optimal gain value; wherein, the optimal exposure value and the optimal gain value constitute the programmed automatic exposure parameters of the camera.

[0006] Preferably, in step S1, obtaining the template image corresponding to each target in the monitoring scene includes the following steps: S111: Manually adjust the camera's exposure value and exposure gain value until the contrast between light and dark of the target in the camera's image meets the preset standard; S112: In the imaging image where the contrast between light and dark meets the standard, extract the corresponding area image of each target as the template image; S113: Name the template image with the corresponding target number and store it in a preset template folder so that each target corresponds to a unique template image; S114: Repeat steps S111-S113 until template images of all targets in the monitoring scene are obtained; wherein, the template images are adapted to targets with various geometric shapes, and for the differences in target imaging area caused by different shooting distances and angles, a corresponding template image is collected for each target separately.

[0007] Preferably, in step S1, calculating the dark area ratio based on the template image includes the following steps: S121: For each target template image, capture a frame containing all targets in the monitoring scene, draw the region of interest bounding box of each target on the image, and record the height and width of each region of interest bounding box, as well as the original width and original height of the corresponding target template image; S122: Calculate the maximum height reference value of the bounding boxes of all regions of interest; S123: Calculate the ratio of the maximum height reference value to the height of the bounding box of each region of interest as the scaling ratio corresponding to the bounding box of that region of interest; S124: Adjust the size of the target template image with the corresponding number according to the scaling ratio, so that the height of the adjusted template image is equal to the maximum height reference value, and the width is equal to the product of the scaling ratio and the width of the original target template image; S125: Perform grayscale conversion, filtering and noise reduction and image enhancement processing on the scaled target template image in sequence. The processed target template image is segmented into a binary image by an adaptive threshold. The bright area contour is extracted by an appropriate contour detection algorithm according to the geometric shape of the target. The number of pixels in the contour is counted as the bright area area. S126: The total bright area is obtained by summing the bright areas of all target template images; S127: Calculate the ratio of the total bright area to the total calculated area of ​​all regions of interest bounding boxes, and subtract this ratio from 1 to calculate the dark area ratio. The total calculated area of ​​all regions of interest bounding boxes is the sum of the calculated areas of each region of interest bounding box. The calculated area of ​​a single region of interest bounding box is equal to the product of the maximum height reference value, the corresponding scaling ratio, and the width of the original template image.

[0008] Preferably, in step S2, generating a grayscale histogram by integrating grayscale information from multiple regions includes the following steps: S211: When performing normalized scaling on each captured region of interest, the width of the scaled region of interest is the scaling ratio of the bounding box of the region of interest multiplied by the original width of the bounding box of the region of interest, and the height of the scaled region of interest is equal to the maximum height reference value of all bounding boxes of the regions of interest. S212: The region of interest is scaled using a bilinear interpolation algorithm to maintain the pixel quality of the region of interest image; S213: Horizontally stitch together all standardized and scaled region of interest images to form a single composite image; convert the composite image into a 256-level grayscale image, and finally output the grayscale histogram corresponding to the grayscale image.

[0009] Preferably, in step S2, generating a grayscale histogram by integrating grayscale information from multiple regions includes the following steps: S221: When performing normalized scaling on each captured region of interest, the width of the scaled region of interest is the scaling ratio of the bounding box of the region of interest multiplied by the original width of the bounding box of the region of interest, and the height of the scaled region of interest is equal to the maximum height reference value of all bounding boxes of the regions of interest. S222: The region of interest is scaled using a bilinear interpolation algorithm to maintain the pixel quality of the region of interest image. S223. Convert each scaled region of interest image into a 256-level grayscale image and calculate the 256-level grayscale histogram corresponding to each region of interest. S224. Assign a preset weight coefficient to the grayscale histogram of each region of interest, perform weighted calculations on the grayscale histograms of all regions of interest according to the preset weight coefficients, and then iteratively accumulate them to generate a merged grayscale histogram as the final output grayscale histogram.

[0010] Preferably, in step S3, the step of calculating the boundary score based on the end point of the dark area, calculating the bimodal difference score by the difference between the peak value of the dark area and the peak value of the bright area, and then weighting the boundary score and the bimodal difference score using a preset weighting coefficient to obtain the final score includes the following steps: S31 - The maximum score for the preset rating; S32 - Boundary Score Calculation: A preset ideal range for the end point of the dark area is defined. If the end point of the dark area is within the ideal range, the boundary score is the preset full score. If the end point of the dark area exceeds the ideal range, the deviation between the end point of the dark area and the ideal range is calculated first, then the maximum allowable deviation is calculated, followed by the ratio of the deviation to the maximum allowable deviation. This ratio is then multiplied by the full score to obtain the deduction value. Finally, the result of subtracting the deduction value from the full score is used as the boundary score, and the minimum boundary score is 0. S33 - Bimodal Difference Score Calculation: A preset expected baseline bimodal difference is calculated; based on the peak value of the dark area and the peak value of the bright area, the absolute difference between the peak value of the dark area and the peak value of the bright area is calculated, and then the ratio of the absolute difference to the expected baseline bimodal difference is calculated. This ratio is then multiplied by the full score to obtain the basic score. If the basic score exceeds the preset full score, the bimodal difference score is the full score; if the basic score does not exceed the full score, the bimodal difference score is the basic score. S34 - Final Score Calculation: The final score is obtained by weighting the calculated boundary scores and bimodal difference scores using preset weighting coefficients. Preferably, the process of obtaining the deviation value includes: Based on the dark area's end point, if the dark area's end point is lower than the lower limit of the ideal range of the dark area's end point, the deviation value is the difference between the lower limit of the ideal range of the dark area's end point and the dark area's end point; if the dark area's end point is higher than the upper limit of the ideal range of the dark area's end point, the deviation value is the difference between the dark area's end point and the upper limit of the ideal range of the dark area's end point. The process for obtaining the maximum permissible deviation value includes: Calculate the difference between the maximum grayscale value and the upper limit of the ideal range of the dark area's end point, and select the larger of this difference and the lower limit of the ideal range of the dark area's end point as the maximum allowable deviation value.

[0011] Preferably, in step S42, optimizing the gain value according to the coarse adjustment stage and the fine adjustment stage includes the following steps: S421 - Coarse Gain Adjustment Stage: Preset a set of gain test points arranged in ascending order, and obtain the full score corresponding to the final score in step S3; set the camera gain to each test point in ascending order of gain value, and execute steps S2 and S3 on the image corresponding to each test point to obtain the final score; record the gain value corresponding to the highest final score among all test points as the temporary optimal gain value; determine the initial search range for fine gain adjustment by taking the test point before the temporary optimal gain value as the lower bound of the search range and the test point after the temporary optimal gain value as the upper bound of the search range; S422 - Gain Fine-tuning Stage: Calculate the midpoint gain value of the current range, where the midpoint gain value is the average of the lower and upper bounds of the search range; obtain the final scores corresponding to the lower, upper, and midpoint gain values ​​of the search range respectively; if the final score corresponding to the lower bound of the search range is greater than the final score corresponding to the upper bound of the search range, update the search range to the lower bound of the search range ~ the midpoint gain value; otherwise, update the search range to the midpoint gain value ~ the upper bound of the search range; repeat the update of the search range until the difference between the upper and lower bounds of the search range is less than a preset threshold; at this point, select the gain value corresponding to the highest final score in the current range as the optimal gain value.

[0012] Preferably, the preset threshold is set according to the accuracy requirements of machine vision long-distance displacement monitoring.

[0013] Secondly, this application discloses a programmed automatic exposure system for machine vision long-distance displacement monitoring, which applies the programmed automatic exposure method for machine vision long-distance displacement monitoring as described above. The system includes: The preprocessing module is configured to: acquire template images corresponding to each target in the monitoring scene, and calculate the dark area ratio based on the template images; The frame processing module is configured to continuously capture camera video streams and perform normalization processing on each frame image. The normalization processing includes: extracting the corresponding region of interest according to the bounding box coordinates of the region of interest of each target, normalizing and scaling each region of interest by a scaling ratio matching the target number, and generating a grayscale histogram by integrating grayscale information from multiple regions. The evaluation and scoring module is configured to: analyze the grayscale histogram output by the frame processing module; determine the dark area end point based on the dark area proportion and the cumulative number of pixels; and determine the grayscale value with the highest frequency in the dark area and the bright area respectively based on the dark area end point as the dark area peak value and the bright area peak value; calculate the boundary score based on the dark area end point; calculate the bimodal difference score by the difference between the dark area peak value and the bright area peak value; and then use a preset weighting coefficient to perform a weighted average of the boundary score and the bimodal difference score to obtain the final score. The parameter optimization module is configured to determine the optimal exposure value and the optimal gain value based on the final score output by the evaluation and scoring module through a step-by-step optimization strategy. Beneficial Effects: The programmed automatic exposure method and system for machine vision-based long-distance displacement monitoring in this application focuses on the geometric features of the target. Through multi-ROI collaborative metering and one-to-one target-template matching, it eliminates background stray light and interference from overexposed / underexposed areas, ensuring that metering is only applied to the core area of ​​the target. A dynamic parameter optimization logic, first optimizing exposure and then coarse-fine adjusting gain, is used, guided by target imaging quality scores, to adapt to changes in outdoor lighting in real time, ensuring stable target imaging. A dual-index evaluation system of boundary scoring and bi-peak difference scoring is established. Dark area boundary position scoring prevents underexposure or overexposure, while bi-peak difference scoring enhances feature contrast, directly guiding parameters towards clear target boundaries and high contrast, adapting to sub-pixel accuracy for displacement monitoring. It can adapt to targets with various geometric shapes such as circles and rings, supports multi-target collaborative monitoring, and solves problems of target shooting distance / angle differences and partial image degradation in multi-target scenarios. The entire process is programmed, eliminating the need for repeated manual parameter adjustments, reducing labor costs and operational errors, and improving the stability of the monitoring system. Attached Figure Description

[0014] To more clearly illustrate the technical solutions in the embodiments of this application 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 this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0015] Figure 1 A flowchart illustrating a programmed automatic exposure method for long-distance displacement monitoring using machine vision, as provided in an embodiment of this application. Figure 2This is a structural block diagram of a programmed automatic exposure system for long-distance displacement monitoring using machine vision, provided in an embodiment of this application. Detailed Implementation

[0016] The technical solutions in the embodiments of this application will be clearly and completely described below. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0017] In this document, the term "comprising" is intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0018] This embodiment aims to address the problem of large displacement monitoring errors caused by excessively bright or dark target images or insignificant contrast in complex outdoor lighting conditions during machine vision-based long-distance displacement monitoring. Through collaborative analysis of multiple regions of interest (ROIs), a comprehensive grayscale histogram is calculated after processing each ROI. A quality evaluation system based on bimodal features is established. Dark area boundary position scoring prevents underexposure or overexposure, while bimodal difference scoring enhances feature contrast. Based on boundary and bimodal difference scores, a dynamic optimization model for exposure-gain parameters is constructed. Iterative calculations drive the imaging system to converge towards the optimal imaging state with clear light and dark boundaries and maximum bimodal separation in the target area. This achieves optimal exposure of the visually monitored target in the machine vision imaging system, ultimately improving the accuracy of long-distance displacement monitoring using machine vision.

[0019] Based on this, this embodiment provides a first aspect such as Figure 1 The illustrated programmed automatic exposure method for long-range displacement monitoring using machine vision includes the following steps: S1 - Preprocessing: Obtain template images corresponding to each target in the monitoring scene, and calculate the dark area ratio based on the template images; S2 - Real-time Frame Processing: Continuously captures camera video streams and performs normalization processing on each frame image. The normalization processing includes: extracting the corresponding region of interest based on the bounding box coordinates of each target's region of interest, normalizing and scaling each region of interest by a scaling ratio matching the target number, and then generating a grayscale histogram by integrating grayscale information from multiple regions. S3 - Evaluation and Scoring: Analyze the grayscale histogram output in step S2, determine the end point of the dark area based on the proportion of dark areas and the cumulative number of pixels, and determine the grayscale value with the highest frequency in the dark area and the bright area based on the end point of the dark area as the peak value of the dark area and the peak value of the bright area respectively; calculate the boundary score based on the end point of the dark area, and calculate the bimodal difference score by the difference between the peak value of the dark area and the peak value of the bright area. Then, use a preset weight coefficient to perform a weighted average of the boundary score and the bimodal difference score to obtain the final score. S4 - Parameter Optimization: Determines the optimal exposure and gain values ​​through a step-by-step optimization strategy, including: S41: Fix the gain value as the preset intermediate value, traverse all preset exposure values, perform steps S2-S3 on the image corresponding to each exposure value to obtain the corresponding final score, select the exposure value corresponding to the highest final score as the optimal exposure value and fix it; S42: Based on the optimal exposure value, the gain value is optimized according to the coarse adjustment stage and the fine adjustment stage to finally obtain the optimal gain value; among them, the optimal exposure value and the optimal gain value constitute the camera's programmable automatic exposure parameters.

[0020] Based on the above, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment achieves programmed automatic dynamic optimization of camera exposure parameters through a full-process design of preprocessing, real-time frame processing, evaluation scoring, and step-by-step parameter optimization. This solves the problem of unstable target imaging quality (too bright, too dark, or insufficient contrast) under complex outdoor lighting conditions, provides high-quality target images for long-distance displacement monitoring, and improves monitoring accuracy.

[0021] In this embodiment, step S1 involves acquiring template images corresponding to each target in the monitoring scene, including the following steps: S111: Manually adjust the camera's exposure value and exposure gain value until the contrast between light and dark of the target in the camera's image meets the preset standard; S112: In the imaging image where the contrast between light and dark meets the standard, extract the corresponding area image of each target as the template image; S113: Name the template image with the corresponding target number and store it in the preset template folder so that each target corresponds to a unique template image; S114: Repeat steps S111-S113 until template images of all targets in the monitoring scene are obtained; the template images are adapted to targets with various geometric shapes, including circles, rings, etc., and for the differences in target imaging area caused by different shooting distances and angles, a corresponding template image is collected for each target separately.

[0022] Based on the above, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment collects template images after manually adjusting to meet the brightness and darkness contrast standard, and establishes a one-to-one correspondence between the target and the template. This ensures that the template images can accurately reflect the target characteristics and adapt to the differences in target imaging caused by different geometric shapes, shooting distances and angles, providing a reliable benchmark for subsequent standardization processing and dark area ratio calculation.

[0023] Further, in step S1, the proportion of dark areas is calculated based on the template image, including the following steps: S121: For each target template image, capture a frame containing all targets in the monitoring scene, draw the region of interest bounding box of each target on the image, and record the height and width of each region of interest bounding box, as well as the original width and original height of the corresponding target template image; S122: Calculate the maximum height reference value of all region of interest bounding boxes, that is, the maximum height reference value is the maximum value among the heights of all region of interest bounding boxes; S123: Calculate the ratio of the maximum height reference value to the height of the bounding box of each region of interest as the scaling ratio corresponding to the bounding box of that region of interest; S124: Adjust the size of the target template image with the corresponding number according to the scaling ratio, so that the height of the adjusted template image is equal to the maximum height reference value, and the width is equal to the product of the scaling ratio and the width of the original target template image. S125: Perform grayscale conversion (converting the color image to a grayscale image), filtering and denoising (eliminating ambient light interference), and image enhancement (optimizing contrast) on the scaled target template image in sequence. The processed target template image is segmented into a binary image (distinguishing between bright and dark areas) using an adaptive threshold. The contour of the bright area is extracted according to the geometric shape of the target using an appropriate contour detection algorithm, and the number of pixels within the contour is counted as the area of ​​the bright area. S126: The total bright area is obtained by summing the bright areas of all target template images; S127: Calculate the ratio of the total bright area to the total calculated area of ​​all regions of interest bounding boxes, and subtract this ratio from 1 to calculate the dark area ratio. The total calculated area of ​​all regions of interest bounding boxes is the sum of the calculated areas of each region of interest bounding box. The calculated area of ​​a single region of interest bounding box is equal to the product of the maximum height reference value, the corresponding scaling ratio, and the width of the original template image.

[0024] The specific formulas and parameter definitions for this step are as follows: (1) Formula for calculating the maximum height reference value: (2) Scaling ratio calculation formula: (3) Formula for calculating the size of the template image after scaling: (4) Formula for calculating the proportion of dark areas: in, To monitor the total number of targets in the scene (which is a positive integer); The maximum height reference value (in pixels) for the bounding boxes of all regions of interest for all targets. The height of the bounding box of the region of interest of the i-th target (in pixels); The width of the bounding box of the region of interest of the i-th target (in pixels); The original width (in pixels) of the template image corresponding to the i-th target. The original height (in pixels) of the template image corresponding to the i-th target. The scaling factor (unitless, representing the height scaling factor) is the bounding box of the region of interest for the i-th target. The width of the i-th target template image after scaling (in pixels); The height of the i-th target template image after scaling (in pixels); The bright area pixel area of ​​the template image after scaling up the i-th target (unit: pixel squared); The sum of the areas of all bright pixels in the target area (unit: squared pixels); This represents the percentage of the dark area (unitless, value range 0~1).

[0025] Based on the above, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment calculates the scaling ratio by ROI bounding box parameters, standardizes and adjusts the template size, extracts the bright area area and calculates the dark area ratio, thereby achieving accurate quantification of the dark area ratio and adapting to the differences in target imaging area, providing an accurate basis for determining the dark area end point based on the dark area ratio.

[0026] In this embodiment, step S2 involves generating a grayscale histogram by integrating grayscale information from multiple regions, including the following steps: S211: When performing normalized scaling on each captured region of interest, the width of the scaled region of interest is the scaling ratio of the bounding box of the region of interest multiplied by the original width of the bounding box of the region of interest, and the height of the scaled region of interest is equal to the maximum height reference value of all bounding boxes of the regions of interest. S212: The region of interest is scaled using a bilinear interpolation algorithm to maintain the pixel quality of the region of interest and avoid image distortion after scaling. S213: Horizontally stitch together all standardized and scaled region of interest images to form a single composite image; convert the composite image into a 256-level grayscale image (grayscale value range of 0~255), and finally output the grayscale histogram corresponding to the grayscale image (counting the number of pixels corresponding to each grayscale value).

[0027] The specific formulas and parameter definitions for this step are as follows: Formula for calculating the normalized and scaled size of the ROI region: in, The scaling factor is the bounding box ratio of the i-th target ROI. The original width (in pixels) of the bounding box of the i-th target ROI; The normalized and scaled width of the i-th target ROI region (in pixels); The maximum height reference value (in pixels) for the bounding boxes of all target ROIs. The height (in pixels) of the i-th target ROI region after normalization and scaling.

[0028] Based on the above, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment generates a composite image and grayscale histogram by standardizing and scaling multiple target ROIs and horizontally stitching them together. This integrates the grayscale distribution information of multiple targets to form complete grayscale features of the target area, which facilitates subsequent unified analysis of the dark area end point and peak value, and improves the completeness of grayscale analysis in multi-target scenarios.

[0029] In this embodiment, step S2 involves generating a grayscale histogram by integrating grayscale information from multiple regions, including the following steps: S221: When performing normalized scaling on each captured region of interest, the width of the scaled region of interest is the scaling ratio of the bounding box of the region of interest multiplied by the original width of the bounding box of the region of interest, and the height of the scaled region of interest is equal to the maximum height reference value of all bounding boxes of the regions of interest. S222: The region of interest is scaled using a bilinear interpolation algorithm to maintain the pixel quality of the region of interest image. S223. Convert each scaled region of interest image into a 256-level grayscale image and calculate the 256-level grayscale histogram corresponding to each region of interest. S224. Assign a preset weight coefficient to the grayscale histogram of each region of interest (set according to the importance of the target in monitoring), and then iteratively accumulate the grayscale histograms of all regions of interest by weighting them according to the preset weight coefficient to generate a merged grayscale histogram as the final output grayscale histogram.

[0030] Based on the above, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment can highlight the grayscale features of key targets according to the differences in target importance by assigning preset weights to the grayscale histograms of multiple target ROIs and weighted accumulation, thereby improving the targeting of the grayscale histograms for the imaging quality of core targets and adapting to the priority requirements in multi-target scenarios.

[0031] In this embodiment, in step S3, a boundary score is calculated based on the end point of the dark area, and a bimodal difference score is calculated based on the difference between the peak value of the dark area and the peak value of the bright area. Then, a weighted average of the boundary score and the bimodal difference score is obtained by using a preset weighting coefficient, including the following steps: S31 - The preset full score value, where the preset full score value can be set according to actual needs (such as 10 points, 100 points, etc., and it must be ensured that the boundary score and the bimodal difference score are calculated based on the same full score value). S32 - Boundary Score Calculation: The ideal range of the dark area's end point is preset (set according to the target imaging quality requirements, grayscale range); if the dark area's end point is within the ideal range, the boundary score is the preset full score; if the dark area's end point exceeds the ideal range, first calculate the deviation of the dark area's end point from the ideal range, then calculate the maximum allowable deviation, then calculate the ratio of the deviation to the maximum allowable deviation, and multiply this ratio by the full score to obtain the deduction value. Finally, the result of subtracting the deduction value from the full score is used as the boundary score, and the minimum boundary score is 0. S33 - Bimodal Difference Score Calculation: A preset expected baseline bimodal difference is calculated (based on the target's brightness and contrast requirements). Based on the peak values ​​of the dark and bright areas, the absolute difference between the peak values ​​of the dark and bright areas is calculated (i.e., the absolute difference is the absolute value of the difference between the grayscale values ​​of the peak values ​​of the dark and bright areas). Then, the ratio of the absolute difference to the expected baseline bimodal difference is calculated, and this ratio is multiplied by the full score to obtain the basic score. If the basic score exceeds the preset full score, the bimodal difference score is the full score; if the basic score does not exceed the full score, the bimodal difference score is the basic score. S34 - Final Score Calculation: The final score is obtained by weighting the calculated boundary score and the bimodal difference score using a preset weighting coefficient (the preset weighting coefficient is the weight of the bimodal difference score, with a value range of 0 < preset weighting coefficient < 1, set according to the priority of light and dark contrast and boundary accuracy).

[0032] The specific formulas and parameter definitions for this step are as follows: (1) Formula for calculating boundary score (taking a full score of 100 points as an example): like ,but ; like ,but ; (2) Formula for calculating the bimodal difference score (taking a full score of 100 as an example): (3) Final score calculation formula: in, The end point of the dark area (unit: gray value, range 0~255); The lower limit of the ideal range for the end point of the dark area (unit: gray value, range 0~255); The upper limit of the ideal range for the end point of the dark area (unit: gray value, range 0~255); The deviation of the dark area's endpoint from the ideal range (unit: grayscale value); Maximum permissible deviation (unit: grayscale value); The peak value of the dark area (i.e., the highest gray value of the dark area determined based on the end point of the dark area, in units of gray value, ranging from 0 to 255); The peak value of the bright area (i.e., the highest gray value of the bright area determined based on the end point of the dark area, in gray value, ranging from 0 to 255); The absolute difference between the peak value in the dark area and the peak value in the bright area (unit: gray value). The preset expected baseline bimodal difference (unit: gray value, set according to target characteristics); Preset weighting coefficients (range 0~1) for scoring the bimodal difference. Scoring of the boundary (unit: points, range 0 to preset full score); Scoring of the bimodal difference (unit: points, range 0 to preset full score); The final score (unit: points, range 0 to preset full score).

[0033] Based on the above, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment establishes a quantitative evaluation system for target imaging quality through boundary scoring (quantifying the rationality of the dark area end point), bimodal difference scoring (quantifying the degree of brightness contrast), and weighted final scoring. This system accurately guides exposure parameters towards clear boundaries and significant contrast, directly serving the core needs of displacement monitoring for target imaging.

[0034] Furthermore, the process of obtaining the deviation value includes: Based on the end point of the dark area, if the end point of the dark area is lower than the lower limit of the ideal range of the end point of the dark area, the deviation value is the difference between the lower limit of the ideal range of the end point of the dark area and the end point of the dark area; if the end point of the dark area is higher than the upper limit of the ideal range of the end point of the dark area, the deviation value is the difference between the end point of the dark area and the upper limit of the ideal range of the end point of the dark area.

[0035] Secondly, the process of obtaining the maximum permissible deviation value includes: Calculate the difference between the maximum grayscale value and the upper limit of the ideal range of the dark area's end point, and select the larger of this difference and the lower limit of the ideal range of the dark area's end point as the maximum allowable deviation value.

[0036] The specific formulas and parameter definitions for this step are as follows: (1) Formula for calculating deviation: Formula for calculating maximum permissible deviation: Where 255 is the maximum gray value of a 256-level grayscale image (which is a fixed value).

[0037] Based on the above, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment, by clarifying the calculation methods of deviation value and maximum allowable deviation value and standardizing the quantitative logic of boundary scoring, ensures that the scoring can objectively reflect the degree of deviation of the dark area end point, thereby improving the accuracy and consistency of boundary scoring.

[0038] In this embodiment, step S42 optimizes the gain value according to the coarse adjustment stage and the fine adjustment stage, including the following steps: S421 - Coarse Gain Adjustment Stage: Preset a set of gain test points arranged in ascending order (set according to the adjustable range of camera gain), obtain the full score corresponding to the final score in step S3 (the full score of the boundary score or the full score of the bimodal difference score, and the two are equal); set the camera gain to each test point in ascending order of gain value, and execute steps S2 and S3 on the image corresponding to each test point to obtain the final score; record the gain value corresponding to the highest final score among all test points as the temporary optimal gain value; determine the initial search range for fine gain adjustment by taking the test point before the temporary optimal gain value as the lower bound of the search range and the test point after the temporary optimal gain value as the upper bound of the search range; S422 - Gain Fine-tuning Stage: A binary search iterative search is performed within the initial search range: First, the midpoint gain value of the current range is calculated, where the midpoint gain value is the average of the lower and upper bounds of the search range; the final scores corresponding to the lower, upper, and midpoint gain values ​​of the search range are obtained respectively; if the final score corresponding to the lower bound of the search range is greater than the final score corresponding to the upper bound of the search range, the search range is updated to the lower bound of the search range ~ the midpoint gain value; otherwise, the search range is updated to the midpoint gain value ~ the upper bound of the search range; the search range is updated repeatedly (i.e., the above binary iterative process is repeated) until the difference between the upper and lower bounds of the search range is less than a preset threshold; at this point, the gain value corresponding to the highest final score within the current range is selected as the optimal gain value.

[0039] The specific formulas and parameter definitions for this step are as follows: (1) Formula for calculating the gain value at the midpoint of the search range: in, This is the lower bound of the gain fine-tuning search range (unit: dB, camera gain unit). This is the upper bound of the gain fine-tuning search range (unit: dB). This is the midpoint gain value (in dB) for the current search range.

[0040] Furthermore, the preset threshold is set according to the accuracy requirements of machine vision long-distance displacement monitoring. When the difference between the upper and lower bounds of the search range is less than the preset threshold, the binary search iteration stops to ensure that the accuracy of the optimal gain value meets the displacement monitoring requirements, and the final score corresponding to the optimal gain value is the highest score in the current search range.

[0041] Based on the above, the programmed automatic exposure method for long-distance displacement monitoring using machine vision in this embodiment quickly locates the optimal range through coarse gain adjustment and accurately searches using a binary search method for fine adjustment. This improves efficiency while ensuring the accuracy of gain optimization, achieving efficient and accurate optimization of the gain value. It adapts to the dynamic requirements of target imaging quality under different lighting conditions and allows the accuracy of gain optimization to flexibly adapt to the displacement monitoring requirements of different scenarios (such as sub-pixel or pixel-level accuracy), thus improving the method's scenario adaptability and flexibility.

[0042] In summary, the programmed automatic exposure method for machine vision long-distance displacement monitoring in this embodiment addresses the core issues of poor target imaging quality and limited displacement monitoring accuracy under complex outdoor lighting conditions in machine vision long-distance displacement monitoring scenarios. Through customized metering schemes, dynamic parameter optimization, and a dedicated quality evaluation system, it achieves precise optimization of target imaging, resulting in the following technical effects: 1. Focus on the geometric features of the target to improve the photometric anti-interference capability and eliminate background interference. By using a bright area extraction algorithm that is adaptive based on the geometric features of the target, a bright area contour detection algorithm is adaptively selected for targets with different structures such as circles and rings. Combined with a one-to-one target-template matching mechanism, the bright area area and dark area ratio of the target are accurately calculated, avoiding area calculation errors caused by differences in target shooting distance and angle. By employing multi-ROI collaborative metering, collaborative analysis is performed only on the region of interest of the target, directly eliminating interference from irrelevant areas such as overexposed background, stray light, and obstructions around the target. This solves the problem that traditional metering is greatly affected by background lighting and the metering results deviate from the actual needs of the target, ensuring that the metering process focuses on the core area of ​​the target and laying the foundation for high-quality imaging.

[0043] 2. Dynamically optimize exposure-gain parameters to adapt to complex outdoor lighting conditions and ensure image stability. A step-by-step optimization mechanism is adopted: first, the gain is fixed to the median value, all exposure values ​​are traversed and the optimal exposure value is selected through the scoring module, and then the gain is optimized by coarse adjustment and fine adjustment based on the optimal exposure value. The coarse adjustment quickly locates the optimal gain range through preset test points, and the fine adjustment accurately searches for the optimal value through the binary search method, which avoids mutual interference between parameters and takes into account both optimization efficiency and accuracy. This dynamic optimization process is guided by the target imaging quality score (rather than a general brightness index), and can respond in real time to changes in outdoor lighting (such as light intensity fluctuations and uneven light sources). It dynamically adjusts the exposure-gain parameters, solving the problem that traditional methods require repeated manual adjustments when lighting changes and cannot adapt in real time, ensuring that the target can stably present clear images under different lighting conditions.

[0044] 3. A customized imaging quality evaluation system for targets directly serves the accuracy requirements of displacement monitoring. By using boundary scoring, a score is calculated based on the degree of deviation between the end point of the dark area and the ideal range, which effectively prevents underexposure or overexposure of the target and ensures a reasonable distribution of the bright and dark areas of the target. By using bimodal difference scoring, the degree of difference between the peak values ​​of dark and bright areas is quantified, thereby enhancing the contrast of target features. The two are weighted according to preset weights to obtain the final score, which directly guides parameter optimization to converge towards the direction of clear target boundary and maximum contrast between light and dark. This avoids the contradiction that traditional general indicators have good visual appeal but insufficient target feature extraction accuracy, and ensures that the target imaging quality is fully adapted to the sub-pixel accuracy requirements of long-distance displacement monitoring.

[0045] 4. Strong scene adaptability, covering monitoring needs of multiple targets and multiple structure targets. Adaptable to multi-structure targets: Through one-to-one matching of target and template, even if the target has different geometric shapes such as circles and rings, or the imaging area is different due to shooting distance and angle, the bright area can still be accurately calculated by separately acquiring template images, solving the problem that traditional methods cannot adapt to differences in target structure. Supports multi-target collaborative monitoring: Through multi-ROI collaborative photometry and weighted histogram analysis, the imaging optimization of multiple targets in the monitoring scene can be processed simultaneously. The ROI of each target is matched with the scaling ratio and weight according to the number, which not only ensures the consistency of multi-target imaging, but also preserves the differences in importance of each target. This solves the problem of image degradation of some targets in multi-target scenes in traditional methods and broadens the scope of application of the invention.

[0046] 5. Improve the automation level of the displacement monitoring system and reduce the cost of manual intervention. The entire process is automated through programmed automatic exposure: from template image acquisition in the preprocessing stage (which can be completed in batches according to program logic), ROI standardization and histogram generation in the frame processing stage, to iterative calculation of evaluation scores and parameter optimization, there is no need for manual adjustment of exposure, gain parameters or preset thresholds. This solves the problem of traditional metering technology relying on human experience and having a low degree of automation, reduces labor costs, avoids errors caused by manual operation, and further ensures the stability and reliability of long-distance displacement monitoring.

[0047] This embodiment provides a second aspect as follows: Figure 2 The machine vision-based long-range displacement monitoring programmed automatic exposure system shown applies the machine vision-based long-range displacement monitoring programmed automatic exposure method described above. The system includes: The preprocessing module is configured to: acquire template images corresponding to each target in the monitoring scene, and calculate the dark area ratio based on the template images; The frame processing module is configured to continuously capture camera video streams and perform normalization processing on each frame image. The normalization processing includes: extracting the corresponding region of interest according to the bounding box coordinates of the region of interest of each target, normalizing and scaling each region of interest by a scaling ratio matching the target number, and generating a grayscale histogram by integrating grayscale information from multiple regions. The evaluation and scoring module is configured to: analyze the grayscale histogram output by the frame processing module, determine the dark area end point based on the dark area ratio and the cumulative number of pixels, and determine the grayscale value with the highest frequency in the dark area and the bright area based on the dark area end point as the dark area peak and the bright area peak, respectively; calculate the boundary score based on the dark area end point, and calculate the bimodal difference score by the difference between the dark area peak and the bright area peak; and then use a preset weighting coefficient to perform a weighted average of the boundary score and the bimodal difference score to obtain the final score. The parameter optimization module is configured to determine the optimal exposure value and the optimal gain value based on the final score output by the evaluation and scoring module through a step-by-step optimization strategy.

[0048] It should be noted that the programmed automatic exposure system for machine vision long-distance displacement monitoring in this embodiment corresponds to the programmed automatic exposure method for machine vision long-distance displacement monitoring described above. Therefore, the parts of the programmed automatic exposure system for machine vision long-distance displacement monitoring in this embodiment that are not described in detail (including but not limited to specific technical means and technical effects) can be referred to the relevant descriptions in the programmed automatic exposure method for machine vision long-distance displacement monitoring described above, and will not be repeated here.

[0049] In the embodiments provided in this application, it should be understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, code, or any suitable combination thereof. For hardware implementation, the processor may be implemented in one or more of the following: application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, other electronic units designed to implement the functions described herein, or combinations thereof. For software implementation, some or all of the processes of the embodiments may be performed by a computer program instructing the associated hardware. During implementation, the program may be stored in a computer-readable storage medium or transmitted as one or more instructions or code on a computer-readable storage medium. Computer-readable storage media include computer storage media and communication media, wherein communication media include any medium that facilitates the transmission of a computer program from one place to another. Storage media may be any available medium accessible to a computer. Computer-readable storage media may include, but are not limited to, RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code having the form of instructions or data structures and accessible to a computer.

[0050] Finally, it should be noted that the above description is only a preferred embodiment of this application and is not intended to limit this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method of programmed auto exposure for machine vision long range displacement monitoring, characterized in that, The method includes the following steps: S1 - Preprocessing: Obtain template images corresponding to each target in the monitoring scene, and calculate the dark area ratio based on the template images; S2 - Real-time frame processing: Continuously captures camera video streams and performs normalization processing on each frame image. The normalization processing includes: extracting the corresponding region of interest according to the bounding box coordinates of the region of interest of each target, normalizing and scaling each region of interest by a scaling ratio matching the target number, and generating a grayscale histogram by integrating grayscale information from multiple regions. S3 - Evaluation and Scoring: Analyze the grayscale histogram output in step S2, determine the dark area end point based on the dark area proportion and the cumulative number of pixels, and determine the grayscale value with the highest frequency in the dark area and the bright area based on the dark area end point as the dark area peak and the bright area peak, respectively; calculate the boundary score based on the dark area end point, and calculate the bimodal difference score by the difference between the dark area peak and the bright area peak; then, use a preset weighting coefficient to perform a weighted average of the boundary score and the bimodal difference score to obtain the final score; S4 - Parameter Optimization: Determines the optimal exposure and gain values ​​through a step-by-step optimization strategy, including: S41: Fix the gain value as the preset intermediate value, traverse all preset exposure values, perform steps S2-S3 on the image corresponding to each exposure value to obtain the corresponding final score, select the exposure value corresponding to the highest final score as the optimal exposure value and fix it; S42: Based on the optimal exposure value, the gain value is optimized according to the coarse adjustment stage and the fine adjustment stage to finally obtain the optimal gain value; wherein, the optimal exposure value and the optimal gain value constitute the camera's programmed automatic exposure parameters; In step S1, calculating the dark area ratio based on the template image includes the following steps: S121: For each target template image, capture a frame containing all targets in the monitoring scene, draw the region of interest bounding box of each target on the image, and record the height and width of each region of interest bounding box, as well as the original width and original height of the corresponding target template image; S122: Calculate the maximum height reference value of the bounding boxes of all regions of interest; S123: Calculate the ratio of the maximum height reference value to the height of the bounding box of each region of interest as the scaling ratio corresponding to the bounding box of that region of interest; S124: Adjust the size of the target template image with the corresponding number according to the scaling ratio, so that the height of the adjusted template image is equal to the maximum height reference value, and the width is equal to the product of the scaling ratio and the width of the original target template image; S125: Perform grayscale conversion, filtering and noise reduction, and image enhancement processing on the scaled target template image in sequence. Use an adaptive threshold to segment the processed target template image into a binary image. Extract the bright area contour according to the geometric shape of the target using an appropriate contour detection algorithm, and count the number of pixels in the contour as the bright area. S126: The total bright area is obtained by summing the bright areas of all target template images; S127: Calculate the ratio of the total bright area to the total calculated area of ​​all regions of interest bounding boxes, and subtract this ratio from 1 to calculate the dark area ratio. The total calculated area of ​​all regions of interest bounding boxes is the sum of the calculated areas of each region of interest bounding box. The calculated area of ​​a single region of interest bounding box is equal to the product of the maximum height reference value, the corresponding scaling ratio, and the width of the original template image.

2. The method of claim 1, wherein, In step S1, obtaining the template image corresponding to each target in the monitoring scene includes the following steps: S111: Manually adjust the camera's exposure value and exposure gain value until the contrast between light and dark of the target in the camera's image meets the preset standard; S112: In the imaging image where the contrast between light and dark meets the standard, extract the corresponding area image of each target as the template image; S113: Name the template image with the corresponding target number and store it in a preset template folder so that each target corresponds to a unique template image; S114: Repeat steps S111-S113 until template images of all targets in the monitoring scene are obtained; wherein, the template images are adapted to targets with various geometric shapes, and for the differences in target imaging area caused by different shooting distances and angles, a corresponding template image is collected for each target separately.

3. The programmed automatic exposure method for long-distance displacement monitoring using machine vision according to claim 1, characterized in that, In step S2, the generation of a grayscale histogram through multi-region grayscale information integration includes the following steps: S211: When performing normalized scaling on each captured region of interest, the width of the scaled region of interest is the scaling ratio of the bounding box of the region of interest multiplied by the original width of the bounding box of the region of interest, and the height of the scaled region of interest is equal to the maximum height reference value of all bounding boxes of the regions of interest. S212: The region of interest is scaled using a bilinear interpolation algorithm to maintain the pixel quality of the region of interest image; S213: Horizontally stitch together all standardized and scaled region of interest images to form a single composite image; convert the composite image into a 256-level grayscale image, and finally output the grayscale histogram corresponding to the grayscale image.

4. The programmed automatic exposure method for long-distance displacement monitoring using machine vision according to claim 1, characterized in that, In step S2, the generation of a grayscale histogram through multi-region grayscale information integration includes the following steps: S221: When performing normalized scaling on each captured region of interest, the width of the scaled region of interest is the scaling ratio of the bounding box of the region of interest multiplied by the original width of the bounding box of the region of interest, and the height of the scaled region of interest is equal to the maximum height reference value of all bounding boxes of the regions of interest. S222: The region of interest is scaled using a bilinear interpolation algorithm to maintain the pixel quality of the region of interest image; S223. Convert each scaled region of interest image into a 256-level grayscale image and calculate the 256-level grayscale histogram corresponding to each region of interest. S224. Assign a preset weight coefficient to the grayscale histogram of each region of interest, perform weighted calculations on the grayscale histograms of all regions of interest according to the preset weight coefficients, and then iteratively accumulate them to generate a merged grayscale histogram as the final output grayscale histogram.

5. The programmed automatic exposure method for long-distance displacement monitoring using machine vision according to claim 1, characterized in that, In step S3, the process of calculating a boundary score based on the end point of the dark area, calculating a bimodal difference score based on the difference between the peak value of the dark area and the peak value of the bright area, and then weighting the boundary score and the bimodal difference score using a preset weighting coefficient to obtain the final score includes the following steps: S31 - The maximum score for the preset rating; S32 - Boundary Score Calculation: A preset ideal range for the end point of the dark area is defined. If the end point of the dark area is within the ideal range, the boundary score is the preset full score. If the end point of the dark area exceeds the ideal range, the deviation between the end point of the dark area and the ideal range is calculated first, then the maximum allowable deviation is calculated, followed by the ratio of the deviation to the maximum allowable deviation. This ratio is then multiplied by the full score to obtain the deduction value. Finally, the result of subtracting the deduction value from the full score is used as the boundary score, and the minimum boundary score is 0. S33 - Bimodal Difference Score Calculation: A preset expected baseline bimodal difference is calculated; based on the peak value of the dark area and the peak value of the bright area, the absolute difference between the peak value of the dark area and the peak value of the bright area is calculated, and then the ratio of the absolute difference to the expected baseline bimodal difference is calculated. This ratio is then multiplied by the full score to obtain the basic score. If the basic score exceeds the preset full score, the bimodal difference score is the full score; if the basic score does not exceed the full score, the bimodal difference score is the basic score. S34 - Final Score Calculation: The final score is obtained by weighting the calculated boundary score and the bimodal difference score using preset weighting coefficients.

6. The programmed automatic exposure method for long-distance displacement monitoring using machine vision according to claim 5, characterized in that, The process of obtaining the deviation value includes: Based on the dark area's end point, if the dark area's end point is lower than the lower limit of the ideal range of the dark area's end point, the deviation value is the difference between the lower limit of the ideal range of the dark area's end point and the dark area's end point; if the dark area's end point is higher than the upper limit of the ideal range of the dark area's end point, the deviation value is the difference between the dark area's end point and the upper limit of the ideal range of the dark area's end point. The process for obtaining the maximum permissible deviation value includes: Calculate the difference between the maximum grayscale value and the upper limit of the ideal range of the dark area's end point, and select the larger of this difference and the lower limit of the ideal range of the dark area's end point as the maximum allowable deviation value.

7. The programmed automatic exposure method for long-distance displacement monitoring using machine vision according to claim 1, characterized in that, In step S42, optimizing the gain value according to the coarse adjustment stage and the fine adjustment stage includes the following steps: S421 - Coarse Gain Adjustment Stage: Preset a set of gain test points arranged in ascending order, and obtain the full score corresponding to the final score in step S3; set the camera gain to each test point in ascending order of gain value, and execute steps S2 and S3 on the image corresponding to each test point to obtain the final score; record the gain value corresponding to the highest final score among all test points as the temporary optimal gain value; determine the initial search range for fine gain adjustment by taking the test point before the temporary optimal gain value as the lower bound of the search range and the test point after the temporary optimal gain value as the upper bound of the search range; S422 - Gain Fine-tuning Stage: Calculate the midpoint gain value of the current range, where the midpoint gain value is the average of the lower and upper bounds of the search range; obtain the final scores corresponding to the lower, upper, and midpoint gain values ​​of the search range respectively; if the final score corresponding to the lower bound of the search range is greater than the final score corresponding to the upper bound of the search range, update the search range to the lower bound of the search range ~ the midpoint gain value; otherwise, update the search range to the midpoint gain value ~ the upper bound of the search range; repeat the update of the search range until the difference between the upper and lower bounds of the search range is less than a preset threshold; at this point, select the gain value corresponding to the highest final score in the current range as the optimal gain value.

8. The programmed automatic exposure method for long-distance displacement monitoring using machine vision according to claim 7, characterized in that, The preset threshold is set according to the accuracy requirements of machine vision long-distance displacement monitoring.

9. A programmed automatic exposure system for long-distance displacement monitoring using machine vision, employing the programmed automatic exposure method for long-distance displacement monitoring using machine vision as described in any one of claims 1-8, characterized in that, The system includes: The preprocessing module is configured to: acquire template images corresponding to each target in the monitoring scene, and calculate the dark area ratio based on the template images; The frame processing module is configured to continuously capture camera video streams and perform normalization processing on each frame image. The normalization processing includes: extracting the corresponding region of interest according to the bounding box coordinates of the region of interest of each target, normalizing and scaling each region of interest by a scaling ratio matching the target number, and generating a grayscale histogram by integrating grayscale information from multiple regions. The evaluation and scoring module is configured to: analyze the grayscale histogram output by the frame processing module; determine the dark area end point based on the dark area proportion and the cumulative number of pixels; and determine the grayscale value with the highest frequency in the dark area and the bright area respectively based on the dark area end point as the dark area peak value and the bright area peak value; calculate the boundary score based on the dark area end point; calculate the bimodal difference score by the difference between the dark area peak value and the bright area peak value; and then use a preset weighting coefficient to perform a weighted average of the boundary score and the bimodal difference score to obtain the final score. The parameter optimization module is configured to determine the optimal exposure value and the optimal gain value based on the final score output by the evaluation and scoring module through a step-by-step optimization strategy. The calculation of the dark area ratio based on the template image includes the following steps: S121: For each target template image, capture a frame containing all targets in the monitoring scene, draw the region of interest bounding box of each target on the image, and record the height and width of each region of interest bounding box, as well as the original width and original height of the corresponding target template image; S122: Calculate the maximum height reference value of the bounding boxes of all regions of interest; S123: Calculate the ratio of the maximum height reference value to the height of the bounding box of each region of interest as the scaling ratio corresponding to the bounding box of that region of interest; S124: Adjust the size of the target template image with the corresponding number according to the scaling ratio, so that the height of the adjusted template image is equal to the maximum height reference value, and the width is equal to the product of the scaling ratio and the width of the original target template image; S125: Perform grayscale conversion, filtering and noise reduction, and image enhancement processing on the scaled target template image in sequence. Use an adaptive threshold to segment the processed target template image into a binary image. Extract the bright area contour according to the geometric shape of the target using an appropriate contour detection algorithm, and count the number of pixels in the contour as the bright area. S126: The total bright area is obtained by summing the bright areas of all target template images; S127: Calculate the ratio of the total bright area to the total calculated area of ​​all regions of interest bounding boxes, and subtract this ratio from 1 to calculate the dark area ratio. The total calculated area of ​​all regions of interest bounding boxes is the sum of the calculated areas of each region of interest bounding box. The calculated area of ​​a single region of interest bounding box is equal to the product of the maximum height reference value, the corresponding scaling ratio, and the width of the original template image.