A traffic accident detection method based on the isolated forest algorithm and target tracking

Through the combined method of isolated forest algorithm and target tracking, vehicle motion indicators are calculated and attention redistribution mechanism is used to solve the accuracy and efficiency of existing traffic accident detection, and the precise and efficient detection and positioning of traffic accidents are achieved.

CN116681722BActive Publication Date: 2025-07-25XIDIAN UNIV
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310596197.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-24
Publication Date
2025-07-25
Estimated Expiration
2043-05-24

AI Technical Summary

Technical Problem

The existing traffic accident detection algorithm still needs to be improved in terms of detection effect and performance, and it is difficult to accurately and efficiently detect and locate traffic accidents.

Method used

Using an isolated forest algorithm and target tracking method, the motion trajectory of vehicles and pedestrians is obtained, motion indicators are calculated, abnormal vehicles are screened, and abnormal segments are weighted using attention redistribution mechanism to determine accident vehicles in segments.

Benefits of technology

It realizes accurate and efficient detection and positioning of traffic accidents in traffic videos, reduces the error detection rate, and improves the real-time and fine-grained positioning capabilities of the algorithm.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116681722B_ABST
    Figure CN116681722B_ABST
Patent Text Reader

Abstract

The present invention discloses a traffic accident detection method based on the isolated forest algorithm and object tracking, aiming at the problem that the traffic accident detection effect in the prior art still needs to be improved. The invention uses an object tracking algorithm to obtain the movement trajectories of each vehicle and pedestrian in the traffic video; calculates the movement indexes of each vehicle according to its movement trajectory; uses the isolated forest algorithm to screen out abnormal vehicles; after screening, a scoring mechanism is proposed to accumulate abnormal scores for each abnormal vehicle; a attention reallocation mechanism is proposed, and the abnormal scores of each vehicle are weighted by the attention coefficient obtained by using this mechanism to highlight the accident vehicle among all abnormal vehicles at the same moment; the video is segmented into multiple discrimination time periods, and in each discrimination time period, the scoring efficiency of each abnormal vehicle is calculated according to the accumulated abnormal scores, and the accident vehicle is determined according to the scoring efficiency. The present invention can accurately and efficiently detect traffic accidents in traffic videos and accurately locate the accident vehicles.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and particularly to a traffic accident detection method based on the isolated forest algorithm and target tracking. Background Art

[0002] With the continuous acceleration of the urbanization process in today's society, the scale of urban traffic is becoming increasingly large, and traffic accidents occur more frequently. The society's demand for intelligent traffic accident recognition is becoming increasingly urgent.

[0003] In the past few decades, the problem of event detection has attracted extensive interest from many researchers at home and abroad. Traffic accident detection algorithms based on methods such as pattern recognition, neural networks, support vector machines, fuzzy logic, Kalman filtering, and time series analysis have achieved varying degrees of results.

[0004] The California algorithm is an early freeway traffic detection algorithm that discriminates possible sudden traffic events by comparing traffic flow parameter data between adjacent detection points. Subsequently, the standard deviation algorithm, double exponential smoothing algorithm, and Bayesian algorithm emerged. The McMaster algorithm based on catastrophe theory first took the frequent congestion caused by excessive traffic demand as the object of analysis and judgment. Among the early traffic event detection algorithms, the California algorithm and the McMaster algorithm have obvious advantages in terms of accuracy and real-time performance, and are considered to be the two classic algorithms with the best comprehensive performance, and are usually used as the benchmarks for evaluating other algorithms. After the 1990s, a series of artificial intelligence algorithms gradually appeared in the traffic event automatic detection algorithms. Among them, Chew et al. proposed an artificial neural network structure model and achieved good detection results in traffic event detection. Abdulhai applied the probabilistic neural network to the detection of sudden traffic events. Fang Yuan and Rucy LongCheu proposed a traffic event detection algorithm based on support vector machines. Shaurya Agarwal proposed a hybrid model using wavelet transform and logistic regression to detect traffic events. Looking at the development process of traffic event detection, the early AID algorithm was based on pattern recognition and catastrophe theory and became a classic algorithm for freeway traffic event detection. The later artificial intelligence AID algorithm is based on the innovation of emerging theories and hardware technologies and has more advantages in terms of detection effect and detection performance. However, the current traffic accident detection algorithms have not achieved ideal results, so the core algorithms still need to be studied in depth. Summary of the Invention

[0005] Aiming at the problem that the traffic accident detection effect in the prior art still needs to be improved, the present invention provides a traffic accident detection method based on the isolated forest algorithm and target tracking, which has more advantages in terms of detection effect and performance.

[0006] The technical solution of the present invention is to provide a traffic accident detection method based on the isolation forest algorithm and target tracking, which includes the following steps: Step 1: For the input traffic video data, first use the target tracking technology to obtain the positions of vehicles and pedestrians in each frame of the image, and perform data association on the positions of vehicles and pedestrians in different frames to obtain the movement trajectories of each vehicle and pedestrian in the video; Step 2: Calculate the movement indicators of each vehicle according to its movement trajectory; Step 3: Use the isolation forest algorithm to screen out abnormal vehicles according to different movement indicators respectively; Step 4: According to the screening results of the isolation forest algorithm, propose a scoring mechanism to accumulate abnormal scores for each abnormal vehicle; Step 5: Propose an attention reallocation mechanism, and weight the abnormal scores of each vehicle through the obtained attention coefficients to highlight the accident vehicles among all abnormal vehicles at the same moment; Step 6: Divide the video into multiple discrimination time periods, and in each discrimination time period, calculate the scoring efficiency of each abnormal vehicle according to the accumulated abnormal scores, and determine the accident vehicle according to the scoring efficiency.

[0007] Preferably, in step 1, traffic accident detection is based on the single-modal data of the video, and the target tracking algorithm is used to obtain the movement trajectories of vehicles and pedestrians in the video data. For each vehicle and pedestrian in each frame of the image, the specific form of its movement trajectory is: the center point pixel coordinates, the pixel height of the detection frame, the pixel width of the detection frame, the track ID, and the frame number.

[0008] Preferably, in step 2, the movement indicators of each vehicle are calculated according to its movement trajectory. First, the movement trajectory information of vehicles and pedestrians is compressed in the time dimension. For the multi-frame trajectory information corresponding to each second in the video, different vehicles and pedestrians are distinguished according to the track ID, and only the trajectory information when each vehicle and pedestrian first appears is retained. The smallest time unit after trajectory compression is called a moment. Then, according to the positions of each vehicle at multiple moments, the speed, acceleration, and heading angle of the vehicle are calculated respectively. The specific steps are as follows: Different vehicles are distinguished according to the track ID. Let the two trajectory information of the same vehicle at two adjacent moments t1 and t2 (t1 < t2) be: the center point pixel abscissa x1, pixel ordinate y1, detection frame pixel height h1, and detection frame pixel width w1 at t1; the center point pixel abscissa x2, pixel ordinate y2, detection frame pixel height h2, and detection frame pixel width w2 at t2.

[0009] Calculate the scale normalization coefficient as follows:

[0010]

[0011] Calculate the speed as follows:

[0012]

[0013]

[0014]

[0015] where v t2 x is the normalized velocity component in the x-axis direction at time t2, and v t2 y is the normalized velocity component in the y-axis direction at time t2, and v t2 is the velocity at time t2;

[0016] The acceleration is calculated as follows:

[0017]

[0018] The heading angle is calculated as follows:

[0019]

[0020] where σ is a very small positive number.

[0021] Preferably, in step 3, the pre-trained isolation forest algorithm is used to screen abnormal vehicles according to different motion indexes. The speeds, accelerations, and heading angles of all vehicles at the same moment are respectively input into three isolation forest models to obtain the vehicles with abnormal speed, acceleration, and heading angle respectively.

[0022] Preferably, in step 4, according to the screening results of the isolation forest algorithm, a scoring mechanism is proposed to accumulate abnormal scores for each abnormal vehicle. The scoring mechanism includes: abnormal score for motion index and abnormal score for vehicle environment. For a vehicle with an abnormal motion index, its abnormal score for the motion index is calculated, and then it is judged whether its vehicle environment is abnormal. If it is abnormal, the abnormal score for the vehicle environment is calculated. Finally, the average value of the two is taken to obtain the abnormal score;

[0023] The formula for calculating the abnormal score of the motion index is:

[0024] S motion = α·S speed + β·S acc + γ·S θ , (α + β + γ = 1),

[0025] In the above formula, α, β, and γ are the weight of the abnormal speed score, the weight of the abnormal acceleration score, and the weight of the abnormal heading angle score respectively; S speed 、S acc 、S θ are the abnormal speed score, the abnormal acceleration score, and the abnormal heading angle score respectively. When the vehicle speed is abnormal, S speed is 1, otherwise it is 0; when the vehicle acceleration is abnormal, S accis 1, otherwise it is 0; when the vehicle heading angle is abnormal, S θ is 1, otherwise it is 0;

[0026] Among them, the vehicle environment abnormality determination method is: score when there are people near the vehicle and the normalized distance between the person and the vehicle is less than 1. The calculation formula for the normalized distance between the person and the vehicle is:

[0027]

[0028] In the above formula, x person is the abscissa of the center point pixel of the person, y person is the ordinate of the center point pixel of the person, h person is the pixel height of the detection frame of the person, w person is the pixel width of the detection frame of the person, x car is the abscissa of the center point pixel of the vehicle, y car is the ordinate of the center point pixel of the vehicle, h car is the pixel height of the detection frame of the vehicle, w car is the pixel width of the detection frame of the vehicle;

[0029] For each abnormal vehicle, if the vehicle environment is normal, that is, the minimum value among all the normalized distances between pedestrians and vehicles is greater than 1, then the vehicle environment abnormality score is 0. Otherwise, calculate the vehicle environment abnormality score according to the following formula:

[0030] S distance = 1 - d min ,

[0031] In the above formula, d min is the minimum value among all the normalized distances between pedestrians and vehicles;

[0032] The calculation formula for the vehicle abnormality score is:

[0033]

[0034] In the above formula, S motion is the abnormal score of the motion index, S distance is the abnormal score of the vehicle environment.

[0035] Preferably, in step 5, the attention reallocation mechanism partially transfers the attention coefficients of some abnormal vehicles at the same moment to other abnormal vehicles, and uses the obtained attention coefficients to weight the abnormal scores of each vehicle to highlight the accident vehicle among all abnormal vehicles at the same moment; among them, the attention reallocation mechanism is: the attention coefficient of each abnormal vehicle before attention transfer is 1, and the total attention value at each moment is equal to the number of abnormal vehicles at that moment; for each abnormal vehicle, query its warning times T before the current moment, and map its warning times T to a weight W according to the following formula t :

[0036]

[0037] Statistically calculate the maximum anomaly score S of all anomaly vehicles at the current moment max For each anomaly vehicle at the current moment, map its anomaly score S to a weight W according to the following formula s :

[0038]

[0039] For each anomaly vehicle, assume the total number of anomaly vehicles at the current moment is N, and calculate the attention coefficient of each anomaly vehicle after attention reallocation according to the following formula

[0040]

[0041] Preferably, in step 6, the video is segmented into multiple discrimination time periods. In each discrimination time period, calculate the scoring efficiency of each anomaly vehicle according to the accumulated anomaly score, determine the accident vehicle according to the scoring efficiency, where different anomaly vehicles are distinguished by track ID, accumulate their warning times according to whether the scoring efficiency of each anomaly vehicle exceeds the warning threshold, and determine the anomaly vehicle with a scoring efficiency exceeding the alarm threshold as the accident vehicle. The calculation formula of the scoring efficiency is

[0042]

[0043] where L is the total number of moments of this continuous frame, W i j and S i j are respectively the attention coefficient and the anomaly score of the i-th anomaly vehicle at the j-th moment

[0044] Compared with the prior art, the traffic accident detection method based on the isolation forest algorithm and target tracking of the present invention has the following advantages: The present invention calculates various motion indexes of vehicles based on the vehicle motion trajectories obtained by the target tracking algorithm, can quickly and accurately locate and distinguish vehicles in the video, and only uses a single modality data of images as the algorithm input, which can effectively improve the algorithm operation efficiency and reduce the hardware cost. The isolation forest algorithm is used to screen vehicles with abnormal motion indexes and score them. Compared with directly judging accidents according to whether the motion indexes are abnormal, an outlier discrimination method is introduced to detect abnormalities, which can effectively avoid false detections caused by special situations such as red lights and traffic jams. In addition, an attention redistribution mechanism is introduced to highlight the accident vehicles among the abnormal vehicles. This mechanism can effectively increase the difference in abnormality scores between the accident vehicles and other abnormal vehicles, reduce false detections caused by the abnormal motion indexes of surrounding vehicles caused by accident vehicles, and improve the overall performance of the algorithm. Finally, accident discrimination is carried out by calculating the scoring efficiency of vehicles within a continuous frame, and the method of segment discrimination is adopted, which can reduce false detections caused by accidental factors such as temporary braking by drivers and errors in the pre-step of the algorithm within a short time.

[0045] The present invention can accurately and efficiently detect traffic accidents in traffic videos, and can accurately locate the position of accident vehicles in the images. Its real-time performance and fine-grained positioning ability greatly improve the practicality of the present invention, enabling users to quickly and accurately understand the road conditions. Brief Description of the Drawings

[0046] Figure 1 is a schematic diagram of the working process of the present invention;

[0047] Figure 2 is a schematic diagram of the working steps of the present invention;

[0048] Figure 3 is a schematic diagram of the structure of the attention redistribution mechanism in the present invention;

[0049] Figure 4 is a broken line diagram of vehicle abnormalities when the attention redistribution mechanism is not used in the present invention;

[0050] Figure 5 is a broken line diagram of vehicle abnormalities when the attention redistribution mechanism is used in the present invention;

[0051] Figure 6 is a visualization diagram of the detection results in the present invention. Detailed Embodiments

[0052] To enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0053] The following further describes the traffic accident detection method based on the isolation forest algorithm and target tracking of the present invention in conjunction with the accompanying drawings and specific embodiments: In this embodiment, as Figure 1 and Figure 2 shown, Step 1: For the input traffic video data, first use the target tracking technology to obtain the positions of vehicles and pedestrians in each frame of the image, and perform data association on the positions of vehicles and pedestrians in different frames to obtain the movement trajectories of each vehicle and pedestrian in the video. The specific form of the vehicle movement trajectory is: the central point pixel coordinates, the detection frame pixel height, the detection frame pixel width, the vehicle track ID, and the frame number of each vehicle in each frame of the image; the YOLOX target detection algorithm is used to obtain the positions of vehicles and pedestrians in each frame of the video. The YOLOX target detection algorithm adopts an anchor-free mechanism in the sample matching algorithm during the training process, which specifically improves the performance of small object detection. In the urban traffic scenario involved in the present invention, the small objects in the video data are the targets far from the image acquisition device. Therefore, using a target detection algorithm that performs well on small objects can effectively increase the working distance of the algorithm and thus reduce the hardware cost. It should be noted that the present invention does not limit the selection of the target detection algorithm.

[0054] In this embodiment, the ByteTrack multi-object tracking algorithm is used to perform data association on the vehicle positions in different frames to obtain the movement trajectories of each vehicle and pedestrian in the video. In the urban traffic scenario involved in the present invention, there are many small objects and serious occlusion between targets, resulting in the target detection algorithm tending to output a large number of low-score detection frames, and the ReID features between adjacent targets are similar. The ByteTrack multi-object tracking algorithm abandons the ReID features of the targets and only uses the motion model for data association. And compared with other target tracking algorithms, it does not directly discard the low-score detection frames, but uses the low-score frames for secondary trajectory matching. It should be noted that the present invention does not limit the selection of the target tracking algorithm.

[0055] Optionally, the target detection algorithm model and the target tracking algorithm model can be trained using the bdd100k dataset. The bdd100k dataset is a large-scale and diverse autonomous driving dataset released by the AI Laboratory of the University of Bernoulli, containing 100,000 images, 10 categories, and a total of about 1.84 million labeled boxes.

[0056] In this embodiment, the YOLOX object detection algorithm is adopted, and the network model parameters are initialized using the yolox-m pre-trained model provided by the official. The model is trained using the bdd100k dataset and the self-built dataset respectively, and the training cycle is 300 rounds. The trained yolox-m model is embedded into the ByteTrack multi-object tracking algorithm to obtain the motion trajectories of each vehicle in the video.

[0057] Step 2: Calculate the motion indicators of each vehicle according to its motion trajectory. Among them, to ensure the accuracy of the motion indicator calculation and reduce the algorithm complexity, first compress the motion trajectory information of vehicles and pedestrians in the time dimension. The smallest time unit after trajectory compression is called a moment. Then, according to the positions of each vehicle at multiple moments, calculate the speed, acceleration, and heading angle of the vehicle respectively. The method for compressing the trajectory information is as follows: for the multi-frame trajectory information corresponding to each second in the video, distinguish different vehicles and pedestrians according to the track ID, and only retain the trajectory information when each vehicle and pedestrian first appears.

[0058] In this embodiment, the frame rate of the video is 25 frames per second. The method for compressing the trajectory information is as follows: every time 25 consecutive frames of data are accumulated, distinguish different vehicles according to the track ID, and only retain the trajectory information when each vehicle first appears.

[0059] Specifically, the trajectory information includes: the center point pixel coordinates of the vehicle in the image, the pixel height of the detection box, the pixel width of the detection box, the vehicle track ID, and the frame number. The frame number is the frame number when the vehicle first appears in 25 consecutive frames.

[0060] In this embodiment, the calculation methods of speed, acceleration, and heading angle are as follows: distinguish different vehicles according to the track ID. Let the two trajectory information of the same vehicle at two adjacent moments t1 and t2 (t1 < t2) be: the horizontal center point pixel coordinate x1, the vertical pixel coordinate y1, the pixel height h1 of the detection box, and the pixel width w1 of the detection box at moment t1, and the horizontal center point pixel coordinate x2, the vertical pixel coordinate y2, the pixel height h2 of the detection box, and the pixel width w2 of the detection box at moment t2.

[0061] Due to the size difference between the vehicles in the distance and the vehicles nearby in the image, the scale normalization coefficient must be calculated first according to the following formula:

[0062]

[0063] Calculate the speed according to the following formula:

[0064]

[0065]

[0066]

[0067] where v t2 x is the normalized velocity component in the x-axis direction at time t2, and v t2 y is the normalized velocity component in the y-axis direction at time t2, and v t2 is the velocity at time t2.

[0068] Calculate the acceleration according to the following formula:

[0069]

[0070] Calculate the heading angle according to the following formula:

[0071]

[0072] where σ is a very small positive number.

[0073] In this embodiment, different vehicles are distinguished by track ID, and a data structure is maintained to record the latest vehicle state of each vehicle. The vehicle state includes: frame number, pixel abscissa, pixel ordinate, pixel height of the detection box, pixel width of the detection box, velocity, acceleration, and heading angle. For all vehicles at each moment, find their vehicle states in this data structure according to the track ID. If not, create a new vehicle state; if so, calculate the normalized motion state at the current moment according to the existing vehicle state and the trajectory information at the current moment, and then update the vehicle state.

[0074] Specifically, use nested dictionaries in Python to implement this data structure. When the trajectory information of a vehicle appears for the first time, record its pixel abscissa, pixel ordinate, pixel height of the detection box, and pixel width of the detection box; when the trajectory information of a vehicle appears for the second time, calculate the size normalization coefficient according to the existing vehicle state and the trajectory information at the current moment, calculate the velocity in sequence according to formulas (2), (3), and (4), and then update the vehicle state; when the trajectory information of a vehicle appears for the third time, calculate the size normalization coefficient according to the existing vehicle state and the trajectory information at the current moment, calculate the velocity in sequence according to formulas (2), (3), and (4), calculate its acceleration according to formula (5), calculate its heading angle according to formula (6), and then update the vehicle state. After the trajectory information of a vehicle appears three times, all variables in the vehicle state have been assigned values. When the trajectory information of this vehicle appears again, update the vehicle state in the above manner.

[0075] Step 3: Use the Isolation Forest algorithm to screen for abnormal vehicles according to different motion indicators. Specifically, the speeds, accelerations, and heading angles of all vehicles at the same moment are respectively fed into three Isolation Forest models to obtain the vehicles with abnormal speeds, accelerations, and heading angles. The three Isolation Forest models are pre-trained; in this embodiment, the training method of the Isolation Forest model is as follows:

[0076] Step (1): Use the YOLOX object detection algorithm to obtain the vehicle position information in each frame of the video;

[0077] Step (2): Use the ByteTrack multi-object tracking algorithm to perform data association on the vehicle positions in different frames to obtain the motion trajectories of each vehicle and pedestrian in the video;

[0078] Step (3): Calculate the motion indicators of each vehicle according to its motion trajectory, including speed, acceleration, and heading angle;

[0079] Step (4): Initialize three Isolation Forest models using the IsolationForest class in the open-source machine learning toolkit scikit-learn, and then use the fit method of the IsolationForest class to train the Isolation Forest models according to speed, acceleration, and heading angle respectively. The three obtained Isolation Forest models can be used to screen for abnormal speed, abnormal acceleration, and abnormal heading angle respectively.

[0080] In this embodiment, the method of using the Isolation Forest algorithm to screen for abnormal vehicles according to different motion indicators is to feed the speeds, accelerations, and heading angles of each vehicle at the same moment into the corresponding Isolation Forest models respectively, and use the decision_function method of the IsolationForest class to obtain abnormal speeds, accelerations, and heading angles respectively. Specifically, for a set of input speeds, accelerations, or heading angles, the decision_function method of the IsolationForest class correspondingly outputs a set of scoring efficiency numbers, and the speeds, accelerations, or heading angles corresponding to the scoring efficiency numbers less than 0 are determined as abnormal values, and the corresponding vehicles are marked as speed abnormal, acceleration abnormal, or heading angle abnormal.

[0081] Step 4: According to the screening results of the Isolation Forest algorithm, a scoring mechanism is proposed to accumulate abnormal scores for each abnormal vehicle. In this embodiment, the proposed scoring mechanism is as follows: According to the screening results of the Isolation Forest algorithm, for a vehicle with abnormal motion indicators, calculate its abnormal score of motion indicators, then determine whether its vehicle environment is abnormal. If it is abnormal, calculate the abnormal score of the vehicle environment, and finally take the average of the two to obtain the abnormal score, which specifically includes: Step (1): For any moment, for the vehicle with abnormal motion indicators output by the Isolation Forest algorithm at the current moment, calculate the abnormal score of motion indicators according to the following formula:

[0082] S motion =α·S speed +β·S acc +γ·S θ’ (α + β + γ = 1), (7);

[0083] Where α, β, and γ are the weights of the abnormal score of speed, the weight of the abnormal score of acceleration, and the weight of the abnormal score of heading angle, and their values are 0.4, 0.2, and 0.4 respectively; S speed 、S acc 、S θ are the abnormal score of speed, the abnormal score of acceleration, and the abnormal score of heading angle respectively. When the vehicle speed is abnormal, S speed is 1, otherwise it is 0; when the vehicle acceleration is abnormal, S acc is 1, otherwise it is 0; when the vehicle heading angle is abnormal, S θ is 1, otherwise it is 0.

[0084] Step (2): For each abnormal vehicle, calculate its normalized distance from all pedestrians at this moment according to the following formula and select the minimum value. This minimum value is the pedestrian with the closest normalized distance to the abnormal vehicle. If this minimum value is less than 1, it is determined that the vehicle environment of this vehicle is abnormal;

[0085]

[0086] In the above formula, x person is the abscissa of the center point pixel of the person, y person is the ordinate of the center point pixel of the person, h person is the pixel height of the detection frame of the person, w person is the pixel width of the detection frame of the person, x car is the abscissa of the center point pixel of the vehicle, y car is the ordinate of the center point pixel of the vehicle, h car is the pixel height of the detection frame of the vehicle, w car is the pixel width of the detection frame of the vehicle.

[0087] Step (3): For each abnormal vehicle, if the vehicle environment is normal, that is, the minimum value among the normalized distances between all pedestrians and vehicles is greater than 1, the vehicle environment anomaly is classified as 0; otherwise, calculate the vehicle environment anomaly score according to the following formula:

[0088] S distance = 1 - d, (9);

[0089] Step (4): Calculate the anomaly score of the vehicle according to the following formula:

[0090]

[0091] It should be noted that according to the above calculation method, the maximum anomaly score that each abnormal vehicle can obtain at each moment is 1.

[0092] It should be noted that only when the vehicle motion index is abnormal will it be determined as an abnormal vehicle and scored. Vehicles with abnormal vehicle environment but normal motion index will not be determined as abnormal vehicles.

[0093] Step 5: Propose an attention reallocation mechanism, and use the attention coefficients obtained by this mechanism to weight the anomaly scores of each vehicle to highlight the accident vehicles among all abnormal vehicles at the same moment. As Figure 3 shown in the schematic diagram of the attention reallocation mechanism, the attention reallocation mechanism is as follows: Naturally, the attention coefficient of each abnormal vehicle before attention transfer is 1, and the total attention value at each moment is equal to the number of abnormal vehicles at that moment; for each abnormal vehicle, look up its anomaly times in the warning ID pool according to its trackID, and calculate the weight W accordingly t ; for each abnormal vehicle, divide its anomaly score by the maximum value of the anomaly scores of all vehicles at the current moment to obtain the normalized anomaly score, and calculate the weight W according to the normalized anomaly score s ; for each abnormal vehicle, for its W t and the weight W s take the geometric mean to obtain its comprehensive weight; use the softmax function to convert the comprehensive weights of all vehicles into attention reallocation coefficients; for each abnormal vehicle, multiply its attention reallocation coefficient by the total attention value to complete the attention reallocation, specifically including:

[0094] Step (1): Maintain a warning ID pool to record the warning times of each vehicle. For each abnormal vehicle at each moment, query its anomaly times T in the warning ID pool according to its track ID, and map its anomaly times to the weight W according to the following formula t :

[0095]

[0096] Step (2): At any moment, calculate the maximum anomaly score S of all abnormal vehicles at the current moment. max For each abnormal vehicle at the current moment, map its anomaly score S to a weight W according to the following formula s :

[0097]

[0098] In the above formula, divide the anomaly score S of each vehicle by S max to normalize the anomaly score value of each vehicle to (0, 1], and then use the sine function to map the normalized anomaly score to the weight W s ;

[0099] Step (3): For each abnormal vehicle, assume that the total number of abnormal vehicles at the current moment is N, and calculate the attention coefficient of each abnormal vehicle after attention reallocation according to the following formula:

[0100]

[0101] In the above formula, for each abnormal vehicle, take the geometric mean of its weight W t and weight W s to obtain the comprehensive weight. Use the softmax function to convert the comprehensive weights of all vehicles into attention reallocation coefficients, and then multiply the total attention value at this moment by the attention reallocation coefficient of each abnormal vehicle to obtain the attention coefficient of the corresponding abnormal vehicle after attention reallocation.

[0102] See Figure 4 and Figure 5 , Figure 4 is the line graph of vehicle anomaly scores without using the attention reallocation mechanism, Figure 5 is the line graph of vehicle anomaly scores when using the attention reallocation mechanism. In these two graphs, the horizontal axis is the frame number, the vertical axis is the anomaly score, and the label is the track ID of the abnormal vehicle. It can be seen that compared with not using the attention reallocation mechanism, using this mechanism can effectively increase the gap between the anomaly scores of accident vehicles and other abnormal vehicles among abnormal vehicles, which is more conducive to discriminating abnormal vehicles after calculating the scoring efficiency.

[0103] Step 6: Divide the video into multiple discrimination time periods. In each discrimination time period, calculate the scoring efficiency of each abnormal vehicle according to the accumulated anomaly scores, determine the abnormal vehicles with scoring efficiency exceeding the alarm threshold as accident vehicles, and at the same time, according to the track ID, accumulate the number of early warning times of each abnormal vehicle according to whether its scoring efficiency exceeds the early warning threshold as the calculation basis of the attention transfer mechanism. In this embodiment, calculate the scoring efficiency of each abnormal vehicle according to the accumulated anomaly scores every 250 frames.

[0104] Specifically, as mentioned in Step 2 above: the frame rate of the video is 25 frames per second, and the trajectory information of every 25 frames is compressed into the trajectory information at 1 moment. The number of moments for 250 consecutive frames is 10. For each abnormal vehicle, accumulate the product of the attention coefficient and the abnormality score at all moments within this segment of consecutive frames, and then divide by the number of moments in this segment of consecutive frames to obtain the scoring efficiency of this abnormal vehicle as an accident vehicle within this segment of consecutive frames. The calculation formula is as follows:

[0105]

[0106] In the above formula, L is the total number of moments in this segment of consecutive frames, W i j and S i j are respectively the attention coefficient and the abnormality score of the i-th abnormal vehicle at the j-th moment, and C i is the scoring efficiency of the i-th abnormal vehicle as an accident vehicle within these 250 consecutive frames.

[0107] In this embodiment, for each abnormal vehicle, if its scoring efficiency is greater than 0.5, then accumulate its warning times in the warning ID pool as the calculation basis for the subsequent moment attention reallocation mechanism; if its scoring efficiency is greater than 1, then it is determined as an accident vehicle.

[0108] Please refer to Figure 6 the visualization diagram of the detection result. In this embodiment, the open-source computer vision library opencv is used to visualize the detection result. Specifically, save the trajectory information of the vehicle in a txt file, and the file content includes: frame number, vehicle track ID, detection box position; save the detection result in a json file, and the file content includes: discriminant frame segment length, discriminant frame segment start frame number, and the track ID and scoring efficiency of abnormal vehicles in each discriminant frame segment; read and combine the vehicle trajectory information in the txt file and the detection result in the json file, and use the rectangle function in the opencv library to mark the track ID and detection box of all vehicles in the original video, and at the same time fill the detection box of the accident vehicle with (red).

[0109] The evaluation metrics used in this embodiment include: Classification Rate (abbreviated as CR), Detection Rate (abbreviated as DR), Specificity, False Alarm Rate (abbreviated as FAR), Precision, and F1-Score. The above metrics need to be calculated with the help of a confusion matrix, as shown in Table 1. Among them, True Positive (abbreviated as TP) represents the number of positive class events correctly classified, True Negative (abbreviated as TN) represents the number of negative class events correctly classified, False Positive (abbreviated as FP) represents the number of positive class events misclassified, and False Negative (abbreviated as FN) represents the number of negative class events misclassified.

[0110] Table 1 Confusion Matrix

[0111]

[0112] In this embodiment, for each frame in the video, if the algorithm alarms, the Prediction Class is Positive, otherwise the Prediction Class is Negative. If there is a traffic accident, the Actual Class is True, otherwise the Actual Class is False. On this basis, the meanings and calculation methods of each evaluation metric are as follows:

[0113] (1) Classification Rate (abbreviated as CR)

[0114] The classification accuracy rate is the percentage of the number of correctly classified events among all occurring events. The calculation formula is:

[0115]

[0116] (2) Detection Rate (abbreviated as DR)

[0117] The detection rate is the percentage of the number of events correctly detected among all actual occurring events. The calculation formula is:

[0118]

[0119] (3) Specificity

[0120] The specificity is the percentage of the number of correctly detected negative example events in the total number of actually occurring negative class events. The calculation formula is as follows:

[0121]

[0122] (4) False Alarm Rate (FAR)

[0123] The false alarm rate is the percentage of the number of events wrongly predicted as correct in the total number of actually occurring negative class events. The calculation formula is as follows:

[0124]

[0125] (5) Precision

[0126] Precision is the percentage of the number of events detected as positive example events in the total number of actually occurring positive class events. The calculation formula is as follows:

[0127]

[0128] (6) F1-Score

[0129] The F1-Score is the harmonic mean of precision and recall. The calculation formula is as follows:

[0130]

[0131] In this embodiment, the algorithm was tested using the self-built dataset with and without the attention redistribution mechanism. The experimental results are shown in Tables 2 and 3.

[0132] Table 2 Traffic accident detection indicators with the attention redistribution mechanism

[0133]

[0134] Table 3 Traffic accident detection indicators without the attention redistribution mechanism

[0135]

[0136] As can be seen from Table 2 and Table 3 above, with the increase of the alarm threshold, the classification accuracy rate (CR), detection rate (DR), false alarm rate (FAR), and F-measure (F1-Score) gradually decrease, while the specificity and precision gradually increase. It should be noted that since the adoption of the attention redistribution mechanism will lead to an increase in the upper limit of the scoring efficiency, the ranges of the alarm thresholds selected in the two experiments are slightly different. By comparing the two tables, it can be found that compared with the adoption of the attention redistribution mechanism, it is difficult for the six indicators to reach a good level simultaneously when the mechanism is not adopted. The reason is that when the mechanism is not adopted, the scoring efficiency gap between accident vehicles and other vehicles is not large. Therefore, when a relatively high alarm threshold is selected, a large number of accident vehicles are screened out while normal vehicles are also screened out, resulting in good specificity, false alarm rate (FAR), and precision indicators, but very poor classification accuracy rate (CR), detection rate (DR), and F-measure (F1-Score) indicators. On the contrary, when a relatively low alarm threshold is selected, a large number of ordinary vehicles are retained while most accident vehicles are also retained, resulting in good classification accuracy rate (CR), detection rate (DR), and F-measure (F1-Score) indicators, but very poor specificity, false alarm rate (FAR), and precision indicators. In contrast, when the attention redistribution mechanism is adopted, each indicator is relatively stable and performs well at different alarm thresholds.

[0137] In addition, in this embodiment, the frame rate of the algorithm (Frames Per Second, abbreviated as FPS) is about 27.53 frames per second, which is greater than the video frame rate of 25 frames per second. Therefore, it can meet the real-time detection requirements.

[0138] The above content is a further detailed description of the present invention in combination with specific preferred implementation manners, and it cannot be determined that the specific implementation of the present invention is only limited to these descriptions. For those of ordinary skill in the technical field to which the present invention belongs, without departing from the concept of the present invention, several simple deductions or substitutions can still be made, and all should be regarded as belonging to the protection scope of the present invention.

Claims

1. A traffic accident detection method based on the isolated forest algorithm and target tracking, characterized in that: It includes the following steps: Step 1: For the input traffic video data, first use target tracking technology to obtain the positions of vehicles and pedestrians in each frame of the image, and perform data association on the positions of vehicles and pedestrians in different frames to obtain the movement trajectories of each vehicle and pedestrian in the video. Step 2: Calculate the motion indicators of each vehicle according to its motion trajectory. First, compress the motion trajectory information of vehicles and pedestrians in the time dimension. For the multi-frame trajectory information corresponding to each second in the video, distinguish different vehicles and pedestrians according to the track ID, and only retain the trajectory information when each vehicle and pedestrian first appears. The smallest time unit after trajectory compression is called a moment. Then, according to the positions of each vehicle at multiple moments, calculate the speed, acceleration, and heading angle of the vehicle respectively. The specific steps are as follows: Distinguish different vehicles according to the track ID. Let the two trajectory information of the same vehicle at two adjacent moments t1 and t2 (t1 < t2) be: the abscissa x1 of the center point pixel, the ordinate y1 of the pixel, the pixel height h1 of the detection frame, and the pixel width w1 of the detection frame at the moment t1; the abscissa x2 of the center point pixel, the ordinate y2 of the pixel, the pixel height h2 of the detection frame, and the pixel width w2 of the detection frame at the moment t2. Calculate the scale normalization coefficient as follows: Calculate the speed as follows: where v t2 x is the normalized velocity component in the x-axis direction at time t2, v t2 y is the normalized velocity component in the y-axis direction at time t2, v t2 is the velocity at time t2; Calculate the acceleration as follows: Calculate the heading angle as follows: where σ is a very small positive number. Step 3: Use the Isolation Forest algorithm to screen out abnormal vehicles according to different motion indicators respectively. Step 4: According to the screening results of the Isolation Forest algorithm, propose a scoring mechanism to accumulate abnormal scores for each abnormal vehicle. The scoring mechanism includes: abnormal scoring of motion indicators and abnormal scoring of vehicle environment. For vehicles with abnormal motion indicators, calculate their abnormal scores of motion indicators, and then judge whether their vehicle environment is abnormal. If abnormal, calculate the abnormal scores of the vehicle environment. Finally, take the average of the two to get the abnormal score. The formula for calculating the abnormal score of motion indicators is: S motion = α·S speed + β·S acc + γ·S θ , (α + β + γ = 1), In the above formula, α, β, and γ are the weights of the speed anomaly component, the acceleration anomaly component, and the heading angle anomaly component respectively; S speed , S acc , S θ are the speed anomaly component, the acceleration anomaly component, and the heading angle anomaly component respectively. When the vehicle speed is abnormal, S speed is 1, otherwise it is 0; when the vehicle acceleration is abnormal, S acc is 1, otherwise it is 0; when the vehicle heading angle is abnormal, S θ is 1, otherwise it is 0; The method for judging abnormal vehicle environment is: score when there are people near the vehicle and the normalized distance between the person and the vehicle is less than 1. The formula for calculating the normalized distance between the person and the vehicle is: In the above formula, x person is the abscissa of the central point pixel of a person, y person is the ordinate of the central point pixel of a person, h person is the pixel height of the detection box of a person, w person is the pixel width of the detection box of a person, x car is the abscissa of the central point pixel of a vehicle, y car is the ordinate of the central point pixel of a vehicle, h car is the pixel height of the detection box of a vehicle, w car is the pixel width of the detection box of a vehicle; For each abnormal vehicle, if the vehicle environment is not abnormal, that is, the minimum value of the normalized distance between all pedestrians and the vehicle is greater than 1, then the abnormal score of the vehicle environment is 0. Otherwise, calculate the abnormal score of the vehicle environment according to the following formula: S distance = 1 - d min , In the above formula, d min is the minimum value among the normalized distances between all pedestrians and vehicles; The formula for calculating the abnormal score of the vehicle is: In the above formula, S motion is the abnormal score of the motion index, and S distance is the abnormal score of the vehicle environment; Step 5: Propose an attention reallocation mechanism to weight the abnormal scores of each vehicle through the obtained attention coefficients to highlight the accident vehicle among all abnormal vehicles at the same moment. Step 6: Divide the video into multiple discrimination time periods. In each discrimination time period, calculate the scoring efficiency of each abnormal vehicle according to the accumulated abnormal scores, and judge the accident vehicle according to the scoring efficiency.

2. The traffic accident detection method based on the isolated forest algorithm and target tracking according to claim 1, wherein: In Step 1, traffic accident detection is based on the single-modal data of the video. The target tracking algorithm is used to obtain the movement trajectories of vehicles and pedestrians in the video data. For each vehicle and pedestrian in each frame of the image, the specific form of its movement trajectory is: the center point pixel coordinates, the pixel height of the detection frame, the pixel width of the detection frame, the track ID, and the frame number.

3. The traffic accident detection method based on the isolated forest algorithm and target tracking according to claim 1, wherein In step 3, the pre-trained isolation forest algorithm is used to screen abnormal vehicles according to different motion indexes. The speeds, accelerations, and heading angles of all vehicles at the same moment are respectively input into three isolation forest models to obtain the vehicles with abnormal speed, acceleration, and heading angle respectively.

4. The traffic accident detection method based on the isolation forest algorithm and target tracking according to claim 1, characterized in that, In step 5, the attention reallocation mechanism partially transfers the attention coefficients of some abnormal vehicles at the same moment to other abnormal vehicles, and uses the obtained attention coefficients to weight the abnormal scores of each vehicle to highlight the accident vehicles among all abnormal vehicles at the same moment. Among them, the attention reallocation mechanism is as follows: before the attention is transferred, the attention coefficient of each abnormal vehicle is 1, and the total attention value at each moment is equal to the number of abnormal vehicles at that moment; for each abnormal vehicle, query its early warning times T before the current moment, and map its early warning times T to a weight W according to the following formula t : Statistically calculate the maximum anomaly score S of all anomaly vehicles at the current moment max , for each anomaly vehicle at the current moment, map its anomaly score S to a weight W according to the following formula s : For each abnormal vehicle, assuming that the total number of abnormal vehicles at the current moment is N, the attention coefficient of each abnormal vehicle after attention reallocation is calculated according to the following formula:

5. The traffic accident detection method based on the isolation forest algorithm and target tracking according to claim 1, characterized in that In step 6, the video is segmented into multiple discrimination time periods. In each discrimination time period, the scoring efficiency of each abnormal vehicle is calculated according to the accumulated abnormal scores, and the accident vehicle is determined according to the scoring efficiency. Among them, different abnormal vehicles are distinguished by track ID, and the warning times of each abnormal vehicle are accumulated according to whether its scoring efficiency exceeds the warning threshold. The abnormal vehicle with a scoring efficiency exceeding the alarm threshold is determined as the accident vehicle. The calculation formula of the scoring efficiency is: Among them, L is the total number of moments of this continuous frame, W i j and S i j are respectively the attention coefficient and the anomaly score of the i-th abnormal vehicle at the j-th moment.

Citation Information

Patent Citations

  • Accident detection method in traffic monitoring based on computer vision

    CN116824523A

  • Method and system for detecting abnormal traffic behavior

    US20250078516A1

  • Detecting accidents in motorsports by using anomaly detection

    WO2024005636A1