A comprehensive Python application for real-time object detection using YOLOv8 (You Only Look Once) deep learning model. This project supports video processing, webcam detection, and batch image processing with an intuitive command-line interface.
- Video Processing: Process video files and save annotated outputs
- Real-time Webcam Detection: Live object detection from webcam feed
- Batch Image Processing: Process multiple images in a directory
- Interactive Interface: User-friendly command-line menu system
- GPU Support: Automatic CUDA detection for faster processing
- Customizable Detection: Adjustable confidence thresholds
- Visual Annotations: Bounding boxes, labels, and confidence scores
- Progress Tracking: Real-time processing progress and statistics
- Python 3.8 or higher
- CUDA-compatible GPU (optional, for faster processing)
- Webcam (for real-time detection)
- Clone this repository:
git clone https://github.com/yourusername/object-detection.git
cd object-detection- Install the required dependencies:
pip install -r requirements.txt- The YOLOv8 model will be automatically downloaded on first run.
Run the main application:
python object_detection.py-
Process Video File:
- Input a video file path
- Get real-time processing with live display
- Save annotated video to output directory
-
Real-time Webcam Detection:
- Live object detection from webcam
- Press 'q' to quit
- Press 's' to save screenshots
- Option to record the session
-
Process Images:
- Batch process images from a directory
- Supports multiple image formats (JPG, PNG, BMP, TIFF)
- Save annotated images to output directory
-
Exit: Close the application
object-detection/
├── object_detection.py # Main application file
├── requirements.txt # Python dependencies
├── README.md # This file
├── video/ # Input videos (created automatically)
├── images/ # Input images (created automatically)
└── output/ # Processed outputs (created automatically)
The YOLOv8 model can detect 80 different object classes from the COCO dataset, including:
- People
- Vehicles (cars, trucks, buses, motorcycles, bicycles)
- Animals (cats, dogs, birds, horses, etc.)
- Household items (chairs, tables, laptops, phones, etc.)
- Sports equipment
- Food items
- And many more!
You can customize the detection parameters by modifying the VideoObjectDetector initialization:
detector = VideoObjectDetector(
model_name="yolov8n.pt", # Model size: n (nano), s (small), m (medium), l (large), x (extra large)
confidence_threshold=0.25 # Confidence threshold for detections
)- CPU: Works on any modern CPU, processing speed depends on video resolution and complexity
- GPU: Significantly faster processing with CUDA-compatible GPU
- Model Sizes:
yolov8n.pt: Fastest, lowest accuracyyolov8s.pt: Good balance of speed and accuracyyolov8m.pt: Higher accuracy, slower processingyolov8l.pt&yolov8x.pt: Highest accuracy, slowest processing
- "Could not open camera": Check if webcam is connected and not being used by another application
- "Video file not found": Ensure the video file path is correct and the file exists
- Slow processing: Consider using a smaller model size or reducing video resolution
- GPU not detected: Install CUDA-compatible PyTorch version
- Use GPU acceleration when available
- Process videos at lower resolution for faster results
- Close other applications to free up system resources
- Use appropriate model size for your hardware capabilities
- Videos: Saved as
detected_[original_name].mp4in the output directory - Images: Saved as
detected_[original_name].[ext]in the output directory - Screenshots: Saved as
screenshot_[frame_number].jpgin the output directory
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
- YOLOv8 by Ultralytics
- OpenCV for computer vision operations
- PyTorch for deep learning framework