The basic logic for object detection in videos is:
- extract the frames from video using OpenCV:
cap = cv2.VideoCapture(videopath)
_, frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- apply yolo detection on the extracted frame
pilimg = Image.fromarray(frame)
detections = detect_image(pilimg)
- apply Kalman filter for detection estimation
mot_tracker = Sort()
tracked_objects = mot_tracker.update(detections.cpu())
SORT (Simple Online and Realtime Tracking) combines object detection and Kalman filter for object tracking.
- install dependencies
pip install -r requirements.txt
- downoad yolo weights
wget https://pjreddie.com/media/files/yolov3.weights -O config/yolov3.weights
- upload a
.mp4
video to./videos
and run object_tracking_Sort.ipynb
You can also ran object_tracking_Sort.py to save the video with annotations
See the full video with annotations: Object tracking using SORT
- YOLOv3: https://pjreddie.com/darknet/yolo/
- YOLO paper: https://pjreddie.com/media/files/papers/YOLOv3.pdf
- SORT paper: https://arxiv.org/pdf/1602.00763.pdf
- Alex Bewley's SORT implementation: https://github.com/abewley/sort