This project uses Ultralytics YOLOv8 and OpenCV to perform real-time object detection on videos or live webcam feeds. It identifies and counts people and vehicles (cars, trucks, buses, motorcycles), displaying detection results and FPS directly on the video stream.
- ✅ Real-time detection using YOLOv8 Nano (fastest variant)
- 🚗 Detects and counts people and vehicles.
- ⚡ Runs on GPU (CUDA) for high-speed inference.
- 💾 Logs all detected labels with timestamps to
detected_objects.txt. - 📊 Displays FPS, people count, and vehicle count on the screen.
Image preview : https://github.com/piyushkadam96k/car-human/blob/main/demo.jpeg
Make sure you have the following dependencies installed:
pip install ultralytics opencv-python torch torchvision💡 Optional: Install CUDA-compatible PyTorch for GPU acceleration.
See: https://pytorch.org/get-started/locally/
📂 yolo-detection/
│
├── detection.py # Main detection script
├── detected_objects.txt # Auto-generated log of detections
├── requirements.txt # Python dependencies
└── README.md # Project documentation
- The YOLOv8 Nano model (
yolov8n.pt) is loaded. - The model is moved to GPU (
model.to('cuda')) for faster inference. - The program opens a video file or webcam feed.
- Each frame is processed and analyzed:
- Bounding boxes and class labels are drawn.
- Counts for people and vehicles are displayed.
- Detected objects are logged with timestamps.
- Press
qto exit the detection window.
-
Clone or download this repository
git clone https://github.com/piyushkadam96k/car-human cd yolo-detection -
Run the detection script
python detection.py
-
Input source
- Replace
"The Fate of the Furious | Harpooning Dom's Car.mp4"
with your own video path or set it to0for webcam:cap = cv2.VideoCapture(0)
- Replace
-
Exit
- Press
qanytime to close the video window.
- Press
While running, the script shows:
People Count: 3
Vehicle Count: 5
FPS: 32.45
And logs detections like this in detected_objects.txt:
2025-10-30 12:05:43: person, car, truck
2025-10-30 12:05:44: person, motorcycle
- For maximum FPS, use:
yolov8n.pt(Nano) oryolov8s.pt(Small)- Lower resolution frames (e.g., 640x400)
- Use GPU (CUDA) if available:
model.to('cuda')
| Model | Size | Speed | mAP (50) | Best for |
|---|---|---|---|---|
yolov8n.pt |
6.2 MB | ⚡ Fastest | ~37.3 | Real-time |
yolov8s.pt |
21.2 MB | Fast | ~44.9 | Better accuracy |
yolov8m.pt |
49.0 MB | Medium | ~50.2 | Balanced |
yolov8l.pt |
83.7 MB | Slower | ~52.9 | High accuracy |
Amit Kadam
📧 kadamamit462@gmail.com
📍 Bhalki
🔗 GitHub: piyushkadam96k
This project is open-source and free to use under the MIT License