This project implements a computer vision-based system to detect, track, and analyze pantographs in railway videos. Using a trained YOLOv8 model, the system identifies pantograph components, tracks their movement, detects sparks, and logs all relevant information for performance and safety analysis. The solution is optimized for real-world deployment in railway monitoring systems.
- YOLOv8 Object Detection: Detects pantograph, pantobar, and cables in each video frame.
- Movement Tracking: Calculates horizontal and vertical displacement of the pantograph between frames.
- Spark Detection: Identifies sparks in the pantobar region by analyzing high-intensity (bright) spots.
- Contact Point Analysis: Computes distances between pantobar and cables to check for proper alignment.
- CSV Logging: Records timestamped movement data, detected sparks, and contact distances.
- Annotated Video Output: Saves the processed video with bounding boxes, annotations, and overlays.
-
Python 3.8+
-
Required Libraries:
pip install opencv-python-headless numpy ultralytics
- Ensure you have a trained YOLOv8 model for pantograph detection.
- Update the
model_pathvariable in the script with the path to your weights file.
- Input Video: Set
input_video_pathto the location of your raw video. - Output Video: Set
output_video_pathwhere the processed annotated video will be saved. - CSV File: Set
csv_output_pathto define where the CSV log should be stored.
- Frame Capture: Reads each frame from the input video.
- Object Detection: Runs YOLOv8 inference to detect pantograph components.
- Movement Analysis: Compares pantograph position across consecutive frames.
- Spark Detection: Identifies bright pixel clusters within the pantobar region.
- Contact Analysis: Measures distances between pantobar and overhead cables.
- Logging: Writes structured data to a CSV file.
- Video Rendering: Saves annotated video with bounding boxes, spark highlights, and metrics overlay.
-
Update paths for model, input video, output video, and CSV inside the script.
-
Run the script:
python pantograph_tracking.py
-
Outputs:
- Processed video with annotations.
- CSV log file containing movement, spark count, and distances.
- Ensure YOLO is properly trained for pantograph, pantobar, and cable classes.
- Detection parameters may require tuning for different lighting or video conditions.
- Output files will be saved in paths configured in the script.