Line feature matching-based traffic monitoring video anomaly detection method and system

By using a video anomaly detection method based on line feature matching, the problem of difficulty in identifying structural anomalies in existing technologies is solved. This method effectively detects camera occlusion, offset, and blur, reduces the false alarm rate, and ensures the reliability of the traffic signal control system.

CN122244813APending Publication Date: 2026-06-19HUNAN PRECISION INTELLIGENT CONTROL TRANSPORTATION TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUNAN PRECISION INTELLIGENT CONTROL TRANSPORTATION TECHNOLOGY CO LTD
Filing Date
2026-05-25
Publication Date
2026-06-19

Smart Images

  • Figure CN122244813A_ABST
    Figure CN122244813A_ABST
Patent Text Reader

Abstract

This application proposes a method and system for anomaly detection in traffic monitoring videos based on line feature matching. The method includes: extracting line features from the current video frame to obtain a list of line segments; performing greedy matching between the list of line segments and a set of stable line segments in a pre-generated template to calculate the survival rate, median center offset, and median angle offset; plotting the list of line segments as a binary edge map, calculating and normalizing the Chamfer distance between the line segments and the template edge map; calculating and normalizing the deviation of the above four indicators from their corresponding thresholds to obtain a risk score; weighting and summing the results according to preset weights to obtain an anomaly score; and determining that the current frame has an anomaly when the anomaly score is greater than or equal to a preset score threshold. This application can effectively detect anomalies such as camera occlusion, offset, blur, and changes in scene structure. It is robust to changes in illumination, has a low false alarm rate, low computational load, and can run in real time in intelligent traffic signal control systems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of computer vision and traffic control technology, specifically to a method and system for anomaly detection in traffic monitoring videos based on line feature matching, which is particularly suitable for fixed-position traffic monitoring scenarios. Background Technology

[0002] In intelligent traffic signal control systems, video detectors are key sensing devices for acquiring traffic flow data and implementing adaptive signal control. Fixed-position cameras (such as traffic checkpoints, intersection monitoring, PTZ cameras, and high-angle cameras) often experience video quality degradation in actual operation due to environmental or external factors. These include: lens obstruction by foreign objects (leaves, plastic bags, snow, etc.); camera angle shift caused by strong winds, collisions, or foundation settlement; image blurring due to dirty lenses, fogging, or rain / snow; abnormal image contrast caused by drastic changes in lighting (backlighting, shadows, sunrise / sunset); and PTZ cameras rotating away from their preset positions to capture illegally parked vehicles. These anomalies directly affect the accuracy of upstream algorithms such as vehicle detection and queue length estimation, leading to signal control strategy failure and even causing traffic congestion or safety accidents.

[0003] Existing video anomaly detection methods are mostly based on global statistical features of images (such as brightness, contrast, and sharpness), which makes it difficult to effectively identify structural anomalies (such as local occlusion and geometric displacement), and they are sensitive to changes in ambient lighting, which can easily lead to false alarms. Summary of the Invention

[0004] To address the aforementioned technical issues, this application provides a traffic monitoring video anomaly detection method and system based on line feature matching. This method can effectively detect anomalies such as camera occlusion, offset, blurring, and changes in scene structure. It is robust to changes in illumination, has a low false alarm rate, and requires minimal computation.

[0005] This application provides a method for anomaly detection in traffic surveillance videos based on line feature matching, including: S1. Extract line features from the current video frame to obtain a list of line segments for the current video frame; each line segment in the list is represented as a feature vector containing normalized center point coordinates, direction angle, and normalized length. S2. Greedily match the line segment list of the current video frame with the set of stable line segments in the pre-generated template to calculate the current value of the target metric for the current video frame. The template includes the set of stable line segments and the corresponding template edge map, as well as the pre-statistical metric thresholds. The target metrics include survival rate, median center offset, and median angle offset. The metric thresholds are baseline values ​​obtained from normal video frames during the database construction phase, including the lower limit threshold for survival rate, the upper limit threshold for median center offset, the upper limit threshold for median angle offset, and the upper limit threshold for Chamfer distance. S3. After drawing the list of line segments of the current video frame into a binary edge map, calculate the Chamfer distance between the binary edge map and the template edge map, and normalize the obtained Chamfer distance by dividing it by the length of the image diagonal. S4. Calculate the degree of deviation of the current video frame’s survival rate, median center offset, median angle offset, and normalized Chamfer distance from the corresponding index thresholds and perform normalization processing to obtain the survival rate risk score, center offset risk score, angle offset risk score, and Chamfer distance risk score. S5. The survival rate risk score, center offset risk score, angle offset risk score and Chamfer distance risk score are weighted and summed according to the preset weights to obtain the anomaly score of the current video frame. S6. When the abnormal score is greater than or equal to the preset score threshold, it is determined that there is an abnormality in the current video frame.

[0006] In one embodiment, step S1 includes: Perform grayscale conversion on the current video frame to obtain a grayscale image; CLAHE was used to perform local contrast enhancement processing on the grayscale image; Gaussian filtering is applied to the enhanced grayscale image for noise reduction. The Canny edge detection operator is used to perform edge extraction processing on the denoised grayscale image to obtain the edge image; Line segment extraction processing is performed on the edge image using LSD or FLD; The extracted line segments are subjected to length filtering to remove line segments whose length is less than the product of a preset ratio and the length of the image diagonal; Perform directional filtering on the filtered line segments to retain line segments whose directional angle deviates from the horizontal or vertical direction by less than a preset angle threshold, thus obtaining a list of line segments for the current video frame.

[0007] In one embodiment, step S2 includes: Initialize an empty set to record the indices of the matched line segments in the line segment list of the current video frame; Iterate through each stable line segment in the template and perform the following operations: Based on the set, all unused line segments in the current video frame are determined, and candidate line segments that meet the matching threshold conditions are selected from all unused line segments. The matching threshold conditions include: the normalized center point distance is less than or equal to the preset distance, the absolute difference of the direction angle is less than or equal to the preset angle, and the absolute value of the normalized length difference is less than or equal to the preset length value. From the candidate line segments that meet the matching threshold conditions, select the candidate line segment with the minimum matching cost as the matching object; the matching cost is calculated by the function cost=center_distance+angle_diff / π + length_diff, where center_distance is the normalized center point distance, angle_diff is the absolute difference of the direction angle considering the periodicity of π, and length_diff is the absolute value of the normalized length difference. If a matching object is found, the current stable line segment of the template and the matching object are recorded as a line segment pair. The normalized center point distance and absolute difference of the direction angle of the line segment pair are calculated and recorded, and the index of the matching object is added to the set. The survival rate is obtained by dividing the total number of successfully matched line segment pairs by the total number of stable line segments in the template. The median is calculated based on the normalized center point distance and absolute difference of direction angle of each line segment pair, respectively, to obtain the median center offset and median angle offset.

[0008] In one implementation, Survival risk score = min(max((lower survival threshold - survival rate) / lower survival threshold, 0), 1); Center offset risk score = min(max((median center offset - median center offset upper limit threshold) / median center offset upper limit threshold, 0), 1); Angle offset risk score = min(max((median angle offset - median angle offset upper limit threshold) / median angle offset upper limit threshold, 0), 1); Chamfer distance risk score = min(max((normalized Chamfer distance - Chamfer distance upper limit threshold) / Chamfer distance upper limit threshold, 0), 1).

[0009] In one embodiment, the preset weights include: a weight of 0.45 for the survival risk score, a weight of 0.20 for the center offset risk score, a weight of 0.20 for the angle offset risk score, and a weight of 0.15 for the Chamfer distance risk score.

[0010] In one embodiment, the method further includes: After determining that there is an anomaly in the current video frame, the anomaly reason label is output according to the following rules: If the survival rate is less than the product of the first preset value and the lower limit threshold of the survival rate, then output the occlusion or scene change label. Otherwise, if the Chamfer distance is greater than the product of the second preset value and the upper limit threshold of the Chamfer distance, the output edge will not match the label. Otherwise, if the median angle offset is greater than the product of the third preset value and the upper limit threshold of the median angle offset, then output a camera rotation or displacement label; Otherwise, output the unknown exception label.

[0011] In one implementation, the pre-generated template is obtained through the following library creation steps: Several frames of images from a period of time without abnormalities are collected from a fixed camera video stream and used as the database construction frames. Extract the line features of each database creation frame to obtain a list of line segments corresponding to each database creation frame; Cross-frame clustering is performed on line segments in the line segment list of different database construction frames to group geometrically similar line segments into the same cluster, and clusters with a number of frames greater than or equal to a preset frame number threshold are selected as stable line segments to form a stable line segment set. Plot all stable line segments onto the binary image to obtain the template edge map; Each database creation frame is greedily matched with the generated set of stable line segments to calculate the survival rate, median center offset, median angle offset, and Chamfer distance of each database creation frame. The first quantile of the survival rate of all database creation frames is taken as the lower limit threshold of the survival rate, and the second quantile of the median center offset, median angle offset, and Chamfer distance are taken as the corresponding upper limit thresholds.

[0012] In one embodiment, cross-frame clustering is performed on line segments in the line segment lists of different database construction frames to group geometrically similar line segments into the same cluster, and clusters with a number of frames greater than or equal to a preset frame number threshold are selected as stable line segments to form a stable line segment set, including: An online incremental clustering algorithm is used to perform the following operations on each line segment frame by frame: the current line segment is compared with the representative line segments of existing clusters. If the matching threshold condition is met, the current line segment is assigned to the cluster with the lowest matching cost, and the representative line segment of the cluster with the lowest matching cost is updated using an incremental averaging method; if the current line segment does not meet the matching threshold condition with any of the representative line segments of existing clusters, a new cluster is created, and the current line segment is used as the representative line segment of the new cluster. Record the different frame indices of each cluster, and count the number of frames in each cluster after the clustering is completed. Keep the clusters with a number of frames greater than or equal to the preset number of frames as stable line segments.

[0013] This application also provides a computer device, including: a memory and a processor, wherein the memory stores computer program instructions for execution on the processor, and when the processor executes the computer program instructions, it implements the traffic monitoring video anomaly detection method based on line feature matching as described above.

[0014] This application also provides a computer storage medium storing a computer program, which, when executed by a processor, implements the above-described traffic monitoring visual anomaly detection method based on line feature matching.

[0015] As described above, the traffic monitoring video anomaly detection method based on line feature matching provided in this application can eliminate the influence of image resolution differences on distance and length measurements by extracting line segments from the current video frame and representing them with feature vectors of normalized center point coordinates, orientation angles, and normalized lengths. This allows the method to adapt to fixed-position cameras with different resolutions while preserving stable geometric structure information in the scene. By greedily matching the line segment list of the current video frame with the set of stable line segments in a pre-generated template, the survival rate, median center offset, and median angle offset are calculated. This enables the quantitative evaluation of the structural integrity, displacement, and rotation of the current video frame relative to the normal scene without manual intervention, thereby effectively identifying structural anomalies such as local occlusion, camera offset, and angle changes, and is insensitive to changes in illumination. After drawing the line segment list of the current video frame into a binary edge map, the Chamfer distance between the current video frame and the template edge map is calculated and normalized by dividing by the image diagonal length. It can measure overall scene changes (such as foreign object intrusion or edge loss due to strong lighting) from the perspective of global edge distribution, making up for the insufficiency of survival rate reflecting only the number of line segment matches, and providing complementary anomaly discrimination criteria. By calculating the deviation of survival rate, median center offset, median angle offset and normalized Chamfer distance from the corresponding indicator thresholds and normalizing them, each risk score is obtained. It can unify the original indicators of different dimensions into the [0,1] interval, eliminate the influence of the difference in magnitude between indicators on subsequent fusion, and make the weighted sum result have clear physical meaning. By weighting and summing the four risk scores according to preset weights to obtain the anomaly score, and judging the existence of anomalies when the anomaly score is greater than or equal to the preset score threshold, it can make robust anomaly decisions by comprehensively considering multi-dimensional evidence, avoid false alarms of a single indicator (for example, when the change in lighting only causes an increase in Chamfer distance while the survival rate is normal, weighted fusion can suppress false alarms), and at the same time retain the highest sensitivity to the decline in structural integrity. Therefore, through the multi-level calculation process described above, from local line segment matching to global edge matching, from raw indicators to risk scores and then to weighted fusion, it is possible to detect quality anomalies such as occlusion, offset, blur and scene structure changes in fixed-position videos in real time while maintaining lightweight and low false alarm rate. It can be directly applied to intelligent traffic signal control systems to automatically switch to backup control schemes in case of anomalies, thus ensuring system reliability. Attached Figure Description

[0016] Figure 1 A flowchart illustrating a traffic monitoring video anomaly detection method based on line feature matching, provided in an embodiment of this application; Figure 2 This is a flowchart illustrating a traffic control method provided in an embodiment of this application. Detailed Implementation

[0017] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative and are not intended to limit the scope of this application.

[0018] like Figure 1 As shown, this embodiment provides a traffic monitoring video anomaly detection method based on line feature matching. This method can be applied to electronic devices, such as traffic control intelligent devices, video detectors, and other electronic devices. In this embodiment, the method is described using an electronic device as the executing entity. The method includes: Step S1: Extract line features from the current video frame to obtain a list of line segments for the current video frame; each line segment in the list is represented as a feature vector containing normalized center point coordinates, direction angle, and normalized length.

[0019] In this embodiment, a video frame refers to each image in a sequence of images continuously captured by a fixed-position camera (such as a traffic monitoring camera or an intersection checkpoint). A fixed position means that the camera's installation location, height, pitch angle, and horizontal orientation remain unchanged during normal operation, thus ensuring a stable spatial distribution and geometric features of the scene's geometric structures (such as lane lines, curbs, and poles) in the image. However, when the lens is obstructed by foreign objects, or when strong winds, collisions, or foundation settlement cause the camera angle to shift, the geometric structures in the scene (such as lane lines, curbs, and poles) will change in the image.

[0020] The current video frame refers to the image frame to be detected, which is captured in real time from the video stream of a fixed camera position and sent into the detection process. It is continuously captured by the same fixed camera position and has the same source as the images in the database construction stage (i.e., database construction frames) (such as an intersection or the same angle). Line feature extraction refers to the process of detecting and extracting geometric line segments from the image (i.e., video frame), including grayscale conversion, CLAHE enhancement, Gaussian filtering, Canny edge detection, LSD or FLD line segment detection, length filtering, and direction filtering, ultimately obtaining the normalized center point coordinates, direction angle, and normalized length of each line segment. The normalized center point coordinates are the coordinate values ​​obtained by dividing the pixel coordinates of the line segment's center point by the width and height of the image, respectively, with a value range of [0,1], which can be used to eliminate the influence of different image resolutions on distance measurement. The direction angle is the direction angle of the line segment, with a value range of [0, π) radians, representing the orientation of the line segment in the image plane. Normalized length is the value obtained by dividing the actual pixel length of a line segment by the length of the image diagonal. The value range is [0,1], and it can be used to eliminate the influence of image size on length measurement.

[0021] It is understandable that by extracting line segments from the current video frame and using feature vectors with normalized center point coordinates, orientation angles, and normalized lengths, the influence of image resolution differences on distance and length measurements can be eliminated, making the method adaptable to fixed-position cameras with different resolutions while preserving stable geometric structure information in the scene.

[0022] In one embodiment, step S1 includes: Perform grayscale conversion on the current video frame to obtain a grayscale image; CLAHE was used to perform local contrast enhancement processing on the grayscale image; Gaussian filtering is applied to the enhanced grayscale image for noise reduction. The Canny edge detection operator is used to perform edge extraction processing on the denoised grayscale image to obtain the edge image; Line segment extraction processing is performed on the edge image using LSD or FLD; The extracted line segments are subjected to length filtering to remove line segments whose length is less than the product of a preset ratio and the length of the image diagonal; Perform directional filtering on the filtered line segments to retain line segments whose directional angle deviates from the horizontal or vertical direction by less than a preset angle threshold, thus obtaining a list of line segments for the current video frame.

[0023] Specifically, first, the current video frame (hereinafter referred to as the current frame) is converted into a grayscale image to reduce computational complexity. Next, Limit Contrast Adaptive Histogram Equalization (CLAHE) is applied to the grayscale image to enhance the contrast of local areas, making edges and line segments more prominent. The block size and contrast limit parameters of CLAHE can be preset (e.g., block size 8×8, contrast limit 2.0). Then, a Gaussian filter (kernel size can be set to 5×5, standard deviation σ=1.0) is applied to the enhanced grayscale image to suppress noise interference and prevent noise from being falsely detected as line segments. Next, the Canny edge detection operator is used to extract edges from the denoised grayscale image, resulting in a binary edge image. The high and low thresholds of Canny can be preset according to the scene (e.g., low threshold 40, high threshold 120) and can be dynamically adjusted via configuration files. Finally, for the edge image, the LSD (Line Segment Detector) or FLD (Fast Line Detector) algorithm is used to extract line segments. LSD can output sub-pixel precision line segment detection results in linear time, with each line segment represented by its endpoint coordinates (x1, y1) and (x2, y2). Next, length filtering is performed on the extracted line segments, including calculating the diagonal length of the image. (W and H are the width and height of the image, respectively), retain length satisfy The line segments, where min_len_ratio is a preset ratio (e.g., 0.05), and the filtered length... The line segments are then filtered. Next, a direction filtering process is performed on the remaining line segments, including calculating the direction angle of each line segment. Only line segments whose direction angle deviates from the horizontal (0°) or vertical (90°) direction by less than a preset angle threshold are retained. The preset angle threshold can be 20°~45°, for example, set to 30°. This filtering can retain the main stable structures in the scene (such as lane lines, curbs, poles, etc.) while excluding messy diagonal lines. Next, for each line segment that passes the filtering, the corresponding normalized features are calculated based on the following formula: (1) Normalized center point coordinates (2) Direction angle (3) Normalized length length _ n = L / D Ultimately, each line segment is represented as a feature vector. x 1, y 1, x 2, y 2, cx , cy , , length_n The set of all line segments is the line segment list of the current video frame.

[0024] Thus, through sequential processing of grayscale conversion, CLAHE enhancement, Gaussian filtering, Canny edge detection, LSD / FLD line segment extraction, length filtering, and direction screening, representative geometric line segments can be stably extracted from the original video frames, noise and irrelevant directions can be filtered out, and the quality of line features and the accuracy of subsequent matching can be improved.

[0025] Step S2: Perform a greedy match between the line segment list of the current video frame and the set of stable line segments in the pre-generated template to calculate the current value of the target index of the current video frame; the template includes the set of stable line segments and the corresponding template edge map, as well as the pre-statistical index thresholds; the target indexes include survival rate, median center offset, and median angle offset; the index thresholds are baseline values ​​obtained from normal video frames during the database construction phase, including the lower limit threshold for survival rate, the upper limit threshold for median center offset, the upper limit threshold for median angle offset, and the upper limit threshold for Chamfer distance.

[0026] Here, "template" refers to a pre-constructed dataset based on the database construction frame during the database construction phase. It includes a stable line segment set, a template edge map, and pre-calculated threshold values. The stable line segment set is a collection of line segments that repeatedly appear in normal video frames and represent the fixed geometric structure of the scene, after cross-frame clustering and frequency filtering. The template edge map is an image obtained by plotting all stable line segments on a binary image (1 pixel line width), used to calculate the Chamfer distance. Survival rate is the ratio of the number of successfully matched template line segments in the current video frame to the total number of stable line segments in the template, reflecting the degree to which the original structural integrity is preserved in the current frame. Successful matching refers to finding the corresponding line segment in the current frame that meets the matching threshold condition and has the lowest matching cost using a greedy matching algorithm. Median offset is the median distance between the normalized center points of two successfully matched line segments, reflecting the degree of camera displacement. When there is no successful match, the median offset can be preset to 1.0. Median angle offset refers to the median of the absolute difference in the direction angles of two successfully matched line segments (i.e., min(|ab|, π-|ab|)). 'a' and 'b' represent the direction angles of the two line segments, reflecting the degree of camera rotation or distortion. If no match is found, the median angle offset can be preset to π / 2. Chamfer distance refers to the average Euclidean distance from an edge pixel on the template edge map to the nearest pixel on the current frame's edge map, divided by the image diagonal length after normalization. It reflects the degree of change in the overall edge structure. The lower survival rate threshold is the value obtained by taking a preset first quantile (e.g., 5%) of the survival rate distribution for all database-built frames during the database-building phase. Values ​​below this value indicate a significantly low survival rate. The upper thresholds for median center offset, median angle offset, and Chamfer distance are the values ​​obtained by taking a preset second quantile (e.g., 95%) of the median center offset, median angle offset, and Chamfer distance distribution for the database-built frames during the database-building phase. Values ​​above these values ​​indicate a significantly high corresponding indicator.

[0027] Greedy matching is a line segment matching strategy. For each stable line segment in the template, it searches among the unused line segments in the current video frame for the line segment that meets the matching threshold and has the lowest matching cost. This line segment is then marked as used, ensuring that each current line segment is matched at most once. Essentially, by greedily matching the line segment list of the current video frame with the set of stable line segments in the pre-generated template, and calculating the survival rate, median offset, and median angle offset, it can quantitatively assess the structural integrity, displacement, and rotation of the current video frame relative to a normal scene without manual intervention. This effectively identifies structural anomalies such as local occlusion, camera offset, and angular changes, and is insensitive to changes in lighting.

[0028] In one embodiment, step S2 includes: Initialize an empty set to record the indices of the matched line segments in the line segment list of the current video frame; Iterate through each stable line segment in the template and perform the following operations: Based on the set, all unused line segments in the current video frame are determined, and candidate line segments that meet the matching threshold conditions are selected from all unused line segments. The matching threshold conditions include: the normalized center point distance is less than or equal to the preset distance, the absolute difference of the direction angle is less than or equal to the preset angle, and the absolute value of the normalized length difference is less than or equal to the preset length value. From the candidate line segments that meet the matching threshold conditions, select the candidate line segment with the minimum matching cost as the matching object; the matching cost is calculated by the function cost=center_distance+angle_diff / π+length_diff, where center_distance is the normalized center point distance, angle_diff is the absolute difference of the direction angle considering the periodicity of π, and length_diff is the absolute value of the normalized length difference. If a matching object is found, the current stable line segment of the template and the matching object are recorded as a line segment pair. The normalized center point distance and absolute difference of the direction angle of the line segment pair are calculated and recorded, and the index of the matching object is added to the set. The survival rate is obtained by dividing the total number of successfully matched line segment pairs by the total number of stable line segments in the template. The median is calculated based on the normalized center point distance and absolute difference of direction angle of each line segment pair, respectively, to obtain the median center offset and median angle offset.

[0029] The matching threshold conditions are used to determine whether two line segments may belong to the same geometric structure. These conditions include: the normalized center point distance is less than or equal to a preset distance (e.g., 0.07 or 0.09 meters), the absolute difference in direction angle is less than or equal to a preset angle (e.g., 15° or 18°), and the absolute value of the normalized length difference is less than or equal to a preset length value (e.g., 0.1 or 0.15). The matching cost is a quantified value used to measure the degree of difference between two line segments. A line segment pair is a one-to-one correspondence established by a template stable line segment (also called a template line segment) and a current frame line segment through successful matching.

[0030] Specifically, first, an empty set `used_indices` is created to record the indices of the currently matched line segments in the video frame (ensuring that each line segment in the current video frame is matched at most once). Then, for each stable line segment `ref` in the template (in any order), the following sub-steps are performed: (1) Among all unused line segments in the current video frame (i.e., line segments whose indices are not in `used_indices`), candidate line segments that simultaneously meet the following matching threshold conditions are selected: the normalized center distance is less than or equal to the preset distance, the absolute difference of the direction angle is less than or equal to the preset angle, and the absolute value of the normalized length difference is less than or equal to the preset length value. The normalized center distance is `center_distance = sqrt((cx_ref - cx_cur)^2+ (cy_ref - cy_cur)^2)`, the absolute difference of the direction angle is `angle_diff = min(|θ_ref - θ_cur|, π - |θ_ref - θ_cur|)`, and the absolute value of the normalized length difference is `length_diff = |length_n_ref - ...`. length_n_cur|, where cx_ref and cy_ref represent the normalized center point coordinates of the current template line segment, cx_cur and cy_cur represent the normalized center point coordinates of the current frame line segment (i.e., the line segment to be matched), θ_ref represents the direction angle of the current template line segment, θ_cur represents the direction angle of the current frame line segment, length_n_ref represents the normalized length of the current template line segment, and length_n_cur represents the normalized length of the current frame line segment; (2) If there are candidate line segments that meet the matching threshold conditions, calculate the matching cost of each candidate line segment and select the candidate line segment with the smallest cost as the matching object (i.e., the current video frame line segment that is most similar to the current template line segment); (3) If a matching object is found, record the match as a line segment pair (ref, cur_match), and calculate the normalized center point distance center_distance and the absolute difference of the direction angle angle_diff of the line segment pair. At the same time, add the index of the matching object cur_match in the original current video frame line segment list to used_indices. The set is marked as used; if no matching object is found (i.e. the set used_indices is empty), that is, there are no unused line segments that meet the matching threshold conditions, the current template line segment cannot be matched in the current frame and is regarded as missing. At this time, no matching pair is generated, and no distance or angle difference is recorded. The template line segment is skipped directly and the next template line segment is processed.

[0031] Next, after traversing all template-stabilized segments, three target metrics for the current frame are calculated based on the recorded information: survival rate (survival), median center offset (median_center), and median angle offset (median_angle). Survival = len(center_dists) / M, where M is the total number of stable segments in the template. Survival rate represents the proportion of successfully matched template segments, reflecting the integrity of the original geometry preserved in the current frame. median_center = median(center_dists). If center_dists is empty (no match), it can be set to a preset maximum value (e.g., 1.0). This metric reflects the degree of camera displacement (median noise immunity). median_angle = median(angle_diffs). If angle_diffs is empty, it is set to π / 2. This metric reflects the degree of camera rotation or distortion.

[0032] In addition, two empty lists, center_dists and angle_diffs, can be created to store the normalized center distance and absolute difference of direction angle for each successfully matched pair (considering the periodicity of π). That is, the normalized center distance center_distance and absolute difference of direction angle angle of the calculated line segment pair are added to the lists center_dists and angle_diffs respectively, to facilitate the subsequent calculation of the median offset and median angle offset.

[0033] Thus, by using the index set, matching threshold conditions, matching cost minimization, matching pair records, and median calculation in greedy matching, a unique and most similar current frame line segment can be found for each template line segment, avoiding duplicate matching, and accurately calculating the survival rate, median center offset, and median angle offset, providing reliable structural integrity and geometric offset indicators for anomaly detection.

[0034] Step S3: After drawing the list of line segments of the current video frame into a binary edge map, calculate the Chamfer distance between the binary edge map and the template edge map, and normalize the obtained Chamfer distance by dividing it by the length of the image diagonal.

[0035] The process of drawing a binary edge map from the list of line segments in the current video frame can be achieved by creating a binary image edge_cur with the same size as the current video frame (width W, height H), initializing all pixels to 0 (black); traversing each line segment in the list of line segments in the current frame, and using the Bresenham line algorithm or the OpenCV algorithm, drawing the line segment with a line width of 1 pixel on the binary image edge_cur, setting the pixels on the line segment to 255 (white), thus obtaining the binary edge map edge_cur of the current frame.

[0036] The Chamfer distance measures the overall similarity between two edge maps and is defined as the average Euclidean distance from each edge pixel in the template edge map to the nearest edge pixel in the current edge map. Calculating the Chamfer distance between the binary edge map and the template edge map can be achieved by: first, performing an Euclidean distance transformation on the binary edge map `edge_cur` of the current video frame to generate a distance transformation map `dist_map`, where the value of each pixel in the distance transformation map represents the Euclidean distance from that pixel to the nearest white pixel in `edge_cur`; next, extracting the coordinate set `P_template` of all white pixels (edge ​​points) in the template edge map `edge_template`; then, for each edge point `p` in `P_template`, reading the distance value `d(p)` at that location from the distance transformation map `dist_map`, summing these distance values, and calculating the arithmetic mean `mean_distance` as the Chamfer distance.

[0037] In this study, considering that the absolute value range of Euclidean distance varies with different image sizes, the obtained Chamfer distance needs to be normalized to make it independent of image size. The normalization of the Chamfer distance can be achieved using the formula: chamfer_norm = mean_distance / D, where D is the diagonal length of the image. This can be understood as follows: by plotting the line segment list of the current video frame as a binary edge map, calculating the Chamfer distance between it and the template edge map, and normalizing it by dividing by the image diagonal length, we can measure overall scene changes (such as foreign object intrusion or edge loss due to strong lighting) from the perspective of global edge distribution. This compensates for the insufficiency of the survival rate, which only reflects the number of matching line segments, and provides complementary anomaly detection criteria.

[0038] Step S4: Calculate the degree of deviation of the current video frame’s survival rate, median center offset, median angle offset, and normalized Chamfer distance from the corresponding index thresholds and perform normalization processing to obtain the survival rate risk score, center offset risk score, angle offset risk score, and Chamfer distance risk score.

[0039] The risk score refers to the value of the original indicator, normalized to the [0,1] interval after comparing it with the corresponding threshold, reflecting the degree to which the indicator deviates from the normal range. A higher survival rate risk score indicates a lower survival rate (more severe structural loss). A higher center shift risk score indicates a more severe center shift. A higher angular shift risk score indicates a more severe angular shift. A higher Chamfer distance risk score indicates a more significant change in the overall marginal structure.

[0040] In one embodiment, the formulas for calculating the survival risk score, center offset risk score, angular offset risk score, and Chamfer distance risk score are as follows: Survival risk score = min(max((lower survival threshold - survival rate) / lower survival threshold, 0), 1); Center offset risk score = min(max((median center offset - median center offset upper limit threshold) / median center offset upper limit threshold, 0), 1); Angle offset risk score = min(max((median angle offset - median angle offset upper limit threshold) / median angle offset upper limit threshold, 0), 1); Chamfer distance risk score = min(max((normalized Chamfer distance - Chamfer distance upper limit threshold) / Chamfer distance upper limit threshold, 0), 1).

[0041] It is understandable that by calculating the degree of deviation of the survival rate, median center shift, median angle shift, and normalized Chamfer distance from the corresponding indicator thresholds and then normalizing them to obtain each risk score, the original indicators of different dimensions can be unified into the [0,1] interval, eliminating the influence of the difference in magnitude between indicators on subsequent fusion, and making the weighted summation result have a clear physical meaning.

[0042] Step S5: The survival rate risk score, center offset risk score, angle offset risk score and Chamfer distance risk score are weighted and summed according to preset weights to obtain the anomaly score of the current video frame.

[0043] The anomaly score is a weighted sum of four risk scores used to determine whether a video frame is abnormal. The weights of the survival rate risk score, center offset risk score, angle offset risk score, and Chamfer distance risk score are summed to 1. Based on the analysis of the importance of the four indicators in this embodiment, the survival rate most directly reflects structural integrity and therefore receives the highest weight; center offset and angle offset reflect geometric changes in the camera and have the next highest weight; Chamfer distance, as an auxiliary indicator, has the lowest weight. In one embodiment, the preset weights include: 0.45 for the survival rate risk score, 0.20 for the center offset risk score, 0.20 for the angle offset risk score, and 0.15 for the Chamfer distance risk score. Thus, by setting differentiated weights for survival rate, center offset, angle offset, and Chamfer distance, the dominant role of structural integrity in anomaly detection can be highlighted, while also considering geometric offset and global edge changes, avoiding false alarms from a single indicator.

[0044] Step S6: When the abnormal score is greater than or equal to the preset score threshold, it is determined that there is an abnormality in the current video frame.

[0045] In this scenario, with all four risk scores normalized to the [0,1] interval and their weights summed to 1, the anomaly score also falls within the [0,1] interval. The closer the anomaly score is to 1, the higher the anomaly level of the current video frame; the closer it is to 0, the closer it is to the normal template state. The preset score threshold (score_threshold) is a pre-defined critical value (e.g., 0.62) used to distinguish between normal and abnormal frames. This threshold can be adjusted according to the false positive / false negative rate requirements of the actual application scenario. For example, to reduce the false negative rate, the threshold can be appropriately lowered; to reduce the false positive rate, the threshold can be appropriately increased.

[0046] If the abnormal score is greater than or equal to the preset score threshold score_threshold, the current video frame is determined to be abnormal; if the abnormal score is less than the preset score threshold score_threshold, the current video frame is determined to be normal.

[0047] When an anomaly is detected in the current video frame, an anomaly alarm can be output. This alarm can include the timestamp of the anomaly occurrence, the anomaly score, and can also record the anomaly video frame number, time, and anomaly score for subsequent maintenance analysis (such as calculating camera failure frequency and triggering manual inspections). It can be understood that by weighting and summing four risk scores according to preset weights to obtain an anomaly score, and determining an anomaly when the anomaly score is greater than or equal to a preset threshold, robust anomaly decisions can be made based on multi-dimensional evidence, avoiding false alarms from a single indicator (for example, when changes in illumination only cause an increase in Chamfer distance while the survival rate remains normal, weighted fusion can suppress false alarms), while retaining the highest sensitivity to structural integrity degradation.

[0048] In summary, the method provided in the above embodiments, through the multi-level calculation process from local line segment matching to global edge matching, from original indicators to risk scores, and then to weighted fusion, can detect quality anomalies such as occlusion, offset, blur, and scene structure changes in fixed-position videos in real time while maintaining lightweight design and low false alarm rate. It can be directly applied to intelligent traffic signal control systems to automatically switch to backup control schemes in case of anomalies, ensuring system reliability. Furthermore, line segment detection uses efficient algorithms such as LSD, and feature matching employs a greedy strategy, resulting in low computational load and meeting the requirements of real-time video stream processing (e.g., 2 frames per second). The database construction process can also be executed asynchronously without blocking the main detection process.

[0049] In one embodiment, the method further includes: After determining that there is an anomaly in the current video frame, the anomaly reason label is output according to the following rules: If the survival rate is less than or equal to the product of the first preset value and the lower limit threshold of the survival rate, then output the occlusion or scene change label; Otherwise, if the Chamfer distance is greater than or equal to the product of the second preset value and the upper limit threshold of the Chamfer distance, the overall edge of the output label will not match. Otherwise, if the median angle offset is greater than or equal to the product of the third preset value and the upper limit threshold of the median angle offset, then output a camera rotation or displacement label; Otherwise, output the unknown exception label.

[0050] Specifically, after determining that there is an anomaly in the current video frame, the calculated survival rate, median angle offset, and Chamfer distance are compared with the corresponding thresholds obtained from the database construction phase, and fine-grained anomaly cause labels are output to help maintenance personnel quickly locate the fault type.

[0051] Among them, under the premise that the current video frame has been determined to be abnormal (i.e., the abnormal score is greater than or equal to the preset score threshold), the cause is classified in the following order: (1) If the survival rate is less than or equal to the product of the first preset value (taking 0.65 as an example) and the lower limit threshold of the survival rate, it indicates that the survival rate has dropped to below 65% of the normal baseline value, indicating that a large number of inherent geometric structures are lost. The most likely reason is that the lens is blocked by foreign objects (such as leaves, plastic bags, snow) or the scene has changed drastically (such as the camera being moved drastically). Then the output label "Obstruction or Scene Change" is displayed. (2) If the survival rate is greater than the product of the first preset value and the lower limit of the survival rate, and the Chamfer distance is greater than or equal to the product of the second preset value (taking 1.4 as an example) and the upper limit of the Chamfer distance, it indicates that although the survival rate decreases not significantly (there may still be some matching), the overall edge structure has shifted significantly compared with the template (the Chamfer distance exceeds 1.4 times the normal upper limit). This is common in strong light changes (backlight, shadow), lens dirt / fog, or foreign objects partially obscuring but not completely covering the key line segments. In this case, the overall edge mismatch label will be output. (3) If the survival rate is greater than the product of the first preset value and the lower limit of the survival rate threshold, the Chamfer distance is less than the product of the second preset value and the upper limit of the Chamfer distance threshold, and the median angle offset is greater than or equal to the product of the third preset value (taking 1.4 as an example) and the upper limit of the median angle offset threshold, it indicates that the geometric offset index is significantly exceeded, but the survival rate is acceptable and the overall edge structure is roughly matched. The main reason may be that the camera has rotated (such as the angle change caused by strong wind) or slightly displaced (such as collision). At this time, the center point of the line segment may also be significantly offset, but the rule takes the angle offset as the main criterion, so the camera rotation or displacement label is output. (4) If none of the above conditions are met, but the abnormal score still exceeds the threshold, it indicates that the comprehensive score is abnormal, but the single index has not reached the level of prominence. It may be caused by a slight superposition of multiple factors (such as weak light change + slight shaking) or other unexpected reasons. At this time, the unknown abnormal label is output, and manual review is recommended.

[0052] In this way, by using hierarchical judgment rules (first check the survival rate, then check the Chamfer distance, and finally check the angle offset), fine-grained anomaly cause labels (occlusion / scene change, edge mismatch, rotation / displacement, unknown) can be further output after an anomaly is determined, to help maintenance personnel quickly locate the fault type.

[0053] In one embodiment, the pre-generated template is obtained through the following library creation steps: Several frames of images from a period of time without abnormalities are collected from a fixed camera video stream and used as the database construction frames. Extract the line features of each database creation frame to obtain a list of line segments corresponding to each database creation frame; Cross-frame clustering is performed on line segments in the line segment list of different database construction frames to group geometrically similar line segments into the same cluster, and clusters with a number of frames greater than or equal to a preset frame number threshold are selected as stable line segments to form a stable line segment set. Plot all stable line segments onto the binary image to obtain the template edge map; Each database creation frame is greedily matched with the generated set of stable line segments to calculate the survival rate, median center offset, median angle offset, and Chamfer distance of each database creation frame. The first quantile of the survival rate of all database creation frames is taken as the lower limit threshold of the survival rate, and the second quantile of the median center offset, median angle offset, and Chamfer distance are taken as the corresponding upper limit thresholds.

[0054] Cross-frame clustering refers to grouping geometrically similar line segments in different frames into the same category to discover recurring stable structures in a scene. The preset frame threshold is the minimum number of frames required for a cluster to be considered stable; for example, 30% of the total number of frames in the database (e.g., 30% of 48 frames is approximately 15 frames). Quantiles refer to sorting a set of data from smallest to largest; the p% quantile indicates that p% of the data are less than or equal to that value. The preset first quantile can be any value between 5% and 10%, and the preset second quantile can be any value between 90% and 95%. Taking a preset first quantile of 5% and a preset second quantile of 95% as an example, the 5% quantile represents the lower boundary of the survival rate in normal frames, and the 95% quantile represents the upper boundary of each error index in normal frames.

[0055] The database construction phase is executed offline during system initialization or when template updates are needed. It automatically extracts stable geometric structures from a video stream without anomalies and calculates baseline thresholds for various metrics. First, for fixed-camera video streams (such as those captured by traffic cameras), within the first 70% of the database construction duration (build_duration_sec, e.g., 300 seconds), database construction frames (build_threshold, e.g., 48 frames) are sampled at uniform time intervals, ensuring they originate from normal operating periods and are free of anomalies. Next, line feature extraction, identical to step S1, is performed on each database construction frame to obtain a list of line segments corresponding to each frame. Then, cross-frame clustering is performed on the line segments in the lists of different database construction frames to group geometrically similar line segments into the same cluster. Clusters with a number of frames greater than or equal to a preset frame threshold are selected as stable line segments, forming a stable line segment set.

[0056] In this way, by collecting database construction frames during normal periods, filtering stable line segments through cross-frame clustering, generating template edge maps, calculating the distribution of various indicators in the database construction frames, and taking preset quantiles as thresholds, online adaptive database construction without manual intervention can be achieved. The templates and thresholds are highly matched with the current scenario and can be reused after system restart.

[0057] In one embodiment, cross-frame clustering is performed on line segments in the line segment lists of different database construction frames to group geometrically similar line segments into the same cluster, and clusters with a number of frames greater than or equal to a preset frame number threshold are selected as stable line segments to form a stable line segment set, including: An online incremental clustering algorithm is used to perform the following operations on each line segment frame by frame: the current line segment is compared with the representative line segments of existing clusters. If the matching threshold condition is met, the current line segment is assigned to the cluster with the lowest matching cost, and the representative line segment of the cluster with the lowest matching cost is updated using an incremental averaging method; if the current line segment does not meet the matching threshold condition with any of the representative line segments of existing clusters, a new cluster is created, and the current line segment is used as the representative line segment of the new cluster. Record the different frame indices of each cluster, and count the number of frames in each cluster after the clustering is completed. Keep the clusters with a number of frames greater than or equal to the preset number of frames as stable line segments.

[0058] Specifically, an empty cluster list `clusters` is initialized. Each line segment in all database creation frames is traversed sequentially to perform the following operations: The current line segment is compared with the representative line segment of an existing cluster. If the matching threshold condition is met, the matching cost `cost = center_distance + angle_diff / π + length_diff` is calculated, and the cluster with the lowest matching cost is selected. If a cluster meeting the condition is found, the current line segment is assigned to that cluster, and the representative line segment of that cluster is updated using an incremental averaging method. Simultaneously, the frame index is added to the frame index set of that cluster (the frame index set records which frames have appeared in that cluster). If no cluster meeting the condition is found, a new cluster is created, using the current line segment as the initial representative line segment, and the frame index set is initialized to the current frame index. After all line segments have been processed, the number of occurrence frames for each cluster (i.e., the number of elements in its frame index set) is counted, and clusters with occurrence frames greater than or equal to a preset frame number threshold are retained as stable line segments. All stable line segments constitute a stable line segment set.

[0059] The generation of the template edge map may include: creating a binary image (completely black) with the same size as the original image; traversing each line segment in the stable line segment set and drawing it as white with a 1-pixel line width (pixel value 255) to obtain the template edge map. When updating the representative line segment of the cluster, each attribute is processed separately: for the normalized center point coordinates (cx, cy) and the normalized length_n, the incremental averaging formula is used, i.e., new component = (original component × total number of line segments in the original cluster + corresponding component of the current line segment) / (total number of line segments in the original cluster + 1); for the orientation angle θ, to avoid periodic effects, the orientation angle is first converted into a unit vector (cosθ, sinθ), and the above incremental averaging is performed on the two components of the unit vector to obtain the average vector (u_avg, v_avg), and then the average orientation angle is calculated using atan2(v_avg, u_avg).

[0060] In this process, each database creation frame is greedily matched with the already generated set of stable line segments (using the same algorithm as in step S2). Four metrics are calculated for each frame: survival rate, median center offset, median angle offset, and Chamfer distance. This generates a distribution list for each metric (length equal to the number of database creation frames, e.g., 48 values). The 5th percentile of the survival rate distribution list is used as the lower threshold for survival rate; the 95th percentile of the median center offset distribution list is used as the upper threshold for median center offset; the 95th percentile of the median angle offset distribution list is used as the upper threshold for median angle offset; and the 95th percentile of the Chamfer distance distribution list is used as the upper threshold for Chamfer distance.

[0061] Thus, by using online incremental clustering, matching threshold condition judgment, cluster selection with matching cost minimization, incremental average update of representative line segments, and frame number filtering, geometrically similar line segments in multiple frames can be automatically merged into stable structures, temporary noise can be eliminated, and the spatiotemporal consistency of representative line segments can be ensured, thereby improving the robustness and long-term stability of the template.

[0062] In one embodiment, the method further includes: All algorithm parameters are managed through configuration files and support dynamic updates at runtime without restarting the service. Parameters include: low and high thresholds for Canny edge detection; minimum length ratio and direction deviation threshold for line segment filtering; preset distance, preset angle, and preset length values ​​in the matching threshold conditions; indicator thresholds; preset weights; and preset score thresholds.

[0063] In the system settings interface of the intelligent traffic signal control system, maintenance personnel can directly edit configuration options to adjust algorithm parameters, quickly adapt to different scenarios, and significantly improve the maintainability and flexibility of the algorithm.

[0064] Based on the same inventive concept as the foregoing embodiments, this embodiment provides a traffic control method that can be applied to signal control intelligent devices, such as... Figure 2 As shown, the method includes: Step S10: Perform anomaly detection on the video frames collected by the video surveillance equipment set at the target intersection, and output scene anomaly flags indicating whether there is occlusion, offset or scene structure change.

[0065] The aforementioned traffic monitoring video anomaly detection method based on line feature matching can be used to detect anomalies in video frames captured by video surveillance equipment (such as fixed-position cameras). Specifically, the signal control intelligent device extracts line features from each frame in the video stream and performs greedy matching with a pre-established normal scene template to calculate the survival rate, median offset, median angle offset, and Chamfer distance, thereby determining whether there are anomalies such as occlusion, offset, or blurring. When an anomaly is detected, a scene anomaly flag is generated.

[0066] The target intersection refers to the intersection requiring traffic control, which can be a crossroads, a T-junction, or other types of intersections, without specific limitations. The target phase may also differ at different times. For example, at 6:21:10 AM, the target phase may be north-south straight traffic, while at 6:22:00 AM, the target phase may be north-south left turns, etc.

[0067] Step S20: For each phase in the target stage, calculate the phase-level vehicle detection status value and the phase-level pedestrian detection status value based on the scene anomaly flags and the number of vehicles and pedestrians in the detection area.

[0068] The phase-level imported vehicle inspection status value can take the values ​​0, 1, or 2. Specifically: if there are no abnormalities in the scene and the number of vehicles in the tactical detection zone of the imported vehicle is greater than the first vehicle threshold, the transient vehicle value is 1; if there are no abnormalities in the scene and the number of vehicles is less than or equal to the first vehicle threshold, the transient vehicle value is 0; if there are abnormalities in the scene, the transient vehicle value is 2. At the same time, a sliding window of length N is maintained to record the transient vehicle values ​​of the most recent N frames. When the transient vehicle values ​​of N consecutive frames within the window are all the same, this value is output as the phase-level imported vehicle inspection status value; otherwise, 1 is output.

[0069] The phase-level pedestrian detection state value can take the values ​​0 or 1. Specifically: if there are no abnormalities in the scene and the number of pedestrians in the pedestrian detection area is greater than the pedestrian threshold, the transient pedestrian value is 1; if there are no abnormalities in the scene and the number of pedestrians is less than or equal to the pedestrian threshold, the transient pedestrian value is 0; if there are abnormalities in the scene, the transient pedestrian value is 0. Simultaneously, a sliding window of length N is maintained to record the transient pedestrian values ​​of the most recent N frames. When the transient pedestrian values ​​of N consecutive frames within the window are all the same, this value is output as the phase-level pedestrian detection state value; otherwise, 0 is output.

[0070] In the target phase, the phases refer to those related to the target phase. For example, when the target phase is north-south straight traffic, the phases in the target phase include the north-south straight traffic phase, the east-side pedestrian phase, and the west-side pedestrian phase. At the current moment, the light status of each phase in the target phase may be the same or different; for example, some phases in the target phase may be green, while others may be red. The detection area may include vehicle detection areas (such as exit vehicle detection areas, import vehicle tactical detection areas, and import vehicle strategic detection areas) and pedestrian detection areas.

[0071] In one embodiment, the first vehicle threshold is 1, the pedestrian threshold is 1, and the sliding window length N=3; The output rules for the phase-level vehicle detection status value are as follows: output 2 when all 3 consecutive frames are 2, output 0 when all 3 consecutive frames are 0, otherwise output 1; the output rules for the phase-level pedestrian detection status value are as follows: output 1 when all 3 consecutive frames are 1, otherwise output 0.

[0072] It should be noted that for each phase in the target stage, its inbound vehicle inspection status value no longer relies solely on the number of vehicles in the video detection area as in existing technologies, but instead comprehensively considers scene anomaly indicators. If there is no scene anomaly, the transient value is obtained according to the conventional logic (1 if the number of vehicles is greater than 1, otherwise 0); if there is a scene anomaly, the transient value is forcibly set to 2 (representing unreliable detection). To avoid transient interference, a sliding window of length 3 is used to smooth the transient value: when all 3 consecutive frames are 2, the phase-level inbound vehicle inspection status value is output as 2; when all 3 consecutive frames are 0, the value is output as 0; otherwise, the value is output as 1.

[0073] Step S30: Calculate the stage-level vehicle phase state value based on the phase-level inlet vehicle detection state value of each phase in the target stage, and calculate the stage-level pedestrian phase state value based on the phase-level pedestrian detection state value of each phase.

[0074] Specifically, if any phase-level vehicle detection status value is 1, then the stage-level vehicle phase status value is 1; otherwise, the minimum value of all phase status values ​​is taken (i.e., if there is a 0, then 0 is taken; if all are 2, then 2 is taken). If any phase-level pedestrian detection status value is 1, then the stage-level pedestrian phase status value is 1; otherwise, it is 0.

[0075] It should be noted that the phase status value of the stage is aggregated from the import vehicle inspection status values ​​of all phases included in that stage according to the following rules: if any phase status value is 1, it indicates that there is a vehicle demand, and the stage value is 1; otherwise, the minimum value is taken (i.e., if there is 0, then 0 is taken, and if all are 2, then 2 is taken).

[0076] Step S40: Perform traffic control operations based on the stage-level vehicle phase state values ​​and the stage-level pedestrian phase state values.

[0077] Specifically, when the stage-level vehicle phase state value is 2, the current video detection is determined to be completely unusable, triggering a backup control scheme (such as fixed timing control or sensor control based solely on radar data) to avoid traffic signal errors caused by camera malfunctions. When the stage-level pedestrian phase state value is 0 and there are no other phase requirements, the pedestrian green light time can be shortened (e.g., shortened by 5 seconds).

[0078] In summary, the above methods, by combining video frame anomaly detection, can automatically identify unreliable video data when the camera is obstructed, offset, or blurred, and switch to backup control strategies (such as fixed timing control or radar data-based control). This can effectively ensure the safety and efficiency of traffic at intersections and further improve the robustness and safety of the traffic control system.

[0079] This application also provides a computer device, including a processor and a memory, wherein the memory stores computer program instructions for execution on the processor, and when the processor executes the computer program instructions, it implements the traffic monitoring video anomaly detection method based on line feature matching as described above.

[0080] This application also provides a computer storage medium storing computer instructions, which, when executed by a processor, implement the above-described traffic monitoring video anomaly detection method based on line feature matching.

Claims

1. A method for anomaly detection in traffic monitoring videos based on line feature matching, characterized in that, The method includes the following steps: S1. Extract line features from the current video frame to obtain a list of line segments. Each line segment in the list is represented as a feature vector containing normalized center point coordinates, orientation angle, and normalized length. S2. Perform a greedy matching operation between the current video frame's line segment list and the set of stable line segments in a pre-generated template to calculate the current value of the target metric for the current video frame. The template includes a set of stable line segments and the corresponding template edge map, as well as pre-statistically calculated metric thresholds. Target metrics include survival rate, median center offset, and median angle offset. The metric thresholds are baseline values ​​obtained from normal video frames during the database construction phase, including a lower limit threshold for survival rate, an upper limit threshold for median center offset, an upper limit threshold for median angle offset, and an upper limit threshold for Chamfer distance. S3. After drawing the list of line segments of the current video frame into a binary edge map, calculate the Chamfer distance between the binary edge map and the template edge map, and normalize the obtained Chamfer distance by dividing it by the length of the image diagonal. S4. Calculate the degree of deviation of the current video frame’s survival rate, median center offset, median angle offset, and normalized Chamfer distance from the corresponding index thresholds and perform normalization processing to obtain the survival rate risk score, center offset risk score, angle offset risk score, and Chamfer distance risk score. S5. The survival rate risk score, center offset risk score, angle offset risk score and Chamfer distance risk score are weighted and summed according to the preset weights to obtain the anomaly score of the current video frame. S6. When the abnormal score is greater than or equal to the preset score threshold, it is determined that there is an abnormality in the current video frame.

2. The method as described in claim 1, characterized in that, Step S1 includes: Perform grayscale conversion on the current video frame to obtain a grayscale image; CLAHE was used to perform local contrast enhancement processing on the grayscale image; Gaussian filtering is applied to the enhanced grayscale image for noise reduction. The Canny edge detection operator is used to perform edge extraction processing on the denoised grayscale image to obtain the edge image; Line segment extraction processing is performed on the edge image using LSD or FLD; The extracted line segments are subjected to length filtering to remove line segments whose length is less than the product of a preset ratio and the length of the image diagonal; Perform directional filtering on the filtered line segments to retain line segments whose directional angle deviates from the horizontal or vertical direction by less than a preset angle threshold, thus obtaining a list of line segments for the current video frame.

3. The method as described in claim 1 or 2, characterized in that, Step S2 includes: Initialize an empty set to record the indices of the matched line segments in the line segment list of the current video frame; Iterate through each stable line segment in the template and perform the following operations: Based on the set, all unused line segments in the current video frame are determined, and candidate line segments that meet the matching threshold conditions are selected from all unused line segments. The matching threshold conditions include: the normalized center point distance is less than or equal to the preset distance, the absolute difference of the direction angle is less than or equal to the preset angle, and the absolute value of the normalized length difference is less than or equal to the preset length value. From the candidate line segments that meet the matching threshold conditions, select the candidate line segment with the minimum matching cost as the matching object; the matching cost is calculated by the function cost=center_distance + angle_diff / π + length_diff, where center_distance is the normalized center point distance, angle_diff is the absolute difference of the direction angle considering the periodicity of π, and length_diff is the absolute value of the normalized length difference. If a matching object is found, the current stable line segment of the template and the matching object are recorded as a line segment pair. The normalized center point distance and absolute difference of the direction angle of the line segment pair are calculated and recorded, and the index of the matching object is added to the set. The survival rate is obtained by dividing the total number of successfully matched line segment pairs by the total number of stable line segments in the template. The median is calculated based on the normalized center point distance and absolute difference of direction angle of each line segment pair, respectively, to obtain the median center offset and median angle offset.

4. The method as described in claim 1, characterized in that, Survival risk score = min(max((lower survival threshold - survival rate) / lower survival threshold, 0), 1); Center offset risk score = min(max((median center offset - median center offset upper limit threshold) / median center offset upper limit threshold, 0), 1); Angle offset risk score = min(max((median angle offset - median angle offset upper limit threshold) / median angle offset upper limit threshold, 0), 1); Chamfer distance risk score = min(max((normalized Chamfer distance - Chamfer distance upper limit threshold) / Chamfer distance upper limit threshold, 0), 1).

5. The method as described in claim 1, characterized in that, The preset weights include: 0.45 for survival risk score, 0.20 for center offset risk score, 0.20 for angle offset risk score, and 0.15 for Chamfer distance risk score.

6. The method as described in claim 1, characterized in that, The method further includes: After determining that there is an anomaly in the current video frame, the anomaly reason label is output according to the following rules: If the survival rate is less than or equal to the product of the first preset value and the lower limit threshold of the survival rate, then output the occlusion or scene change label; Otherwise, if the Chamfer distance is greater than or equal to the product of the second preset value and the upper limit threshold of the Chamfer distance, the overall edge of the output label will not match. Otherwise, if the median angle offset is greater than or equal to the product of the third preset value and the upper limit threshold of the median angle offset, then output a camera rotation or displacement label; Otherwise, output the unknown exception label.

7. The method as described in claim 3, characterized in that, The pre-generated template is obtained through the following library creation steps: Several frames of images from a period of time without abnormalities are collected from a fixed camera video stream and used as the database construction frames. Extract the line features of each database creation frame to obtain a list of line segments corresponding to each database creation frame; Cross-frame clustering is performed on line segments in the line segment list of different database construction frames to group geometrically similar line segments into the same cluster, and clusters with a number of frames greater than or equal to a preset frame number threshold are selected as stable line segments to form a stable line segment set. Plot all stable line segments onto the binary image to obtain the template edge map; Each database creation frame is greedily matched with the generated set of stable line segments to calculate the survival rate, median center offset, median angle offset, and Chamfer distance of each database creation frame. The first quantile of the survival rate of all database creation frames is taken as the lower limit threshold of the survival rate, and the second quantile of the median center offset, median angle offset, and Chamfer distance are taken as the corresponding upper limit thresholds.

8. The method as described in claim 7, characterized in that, Cross-frame clustering is performed on line segments in the line segment lists of different database construction frames to group geometrically similar line segments into the same cluster. Clusters with a number of frames greater than or equal to a preset frame number threshold are selected as stable line segments to form a stable line segment set, including: An online incremental clustering algorithm is used to perform the following operations on each line segment frame by frame: the current line segment is compared with the representative line segments of existing clusters. If the matching threshold condition is met, the current line segment is assigned to the cluster with the lowest matching cost, and the representative line segment of the cluster with the lowest matching cost is updated using an incremental averaging method; if the current line segment does not meet the matching threshold condition with any of the representative line segments of existing clusters, a new cluster is created, and the current line segment is used as the representative line segment of the new cluster. Record the different frame indices of each cluster, and count the number of frames in each cluster after the clustering is completed. Keep the clusters with a number of frames greater than or equal to the preset number of frames as stable line segments.

9. A computer device, characterized in that, include: Processor and memory used to store computer programs that can run on the processor; When the processor runs the computer program, it implements the traffic monitoring video anomaly detection method based on line feature matching as described in any one of claims 1 to 8.

10. A computer storage medium, characterized in that, The computer storage medium stores a computer program, characterized in that the computer program is executed by a processor to implement the traffic monitoring video anomaly detection method based on line feature matching as described in any one of claims 1 to 8.