Skip to content

This project implements a modular Python application for object detection using the YOLOv8 model. It supports video files, live webcam streams, and image directories. With a simple command-line interface, the system performs detection, overlays bounding boxes, and saves annotated results.

Notifications You must be signed in to change notification settings

Iamm3taphorical/object-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Object Detection using YOLOv8

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.

Features

  • 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

Requirements

  • Python 3.8 or higher
  • CUDA-compatible GPU (optional, for faster processing)
  • Webcam (for real-time detection)

Installation

  1. Clone this repository:
git clone https://github.com/yourusername/object-detection.git
cd object-detection
  1. Install the required dependencies:
pip install -r requirements.txt
  1. The YOLOv8 model will be automatically downloaded on first run.

Usage

Run the main application:

python object_detection.py

Menu Options

  1. Process Video File:

    • Input a video file path
    • Get real-time processing with live display
    • Save annotated video to output directory
  2. Real-time Webcam Detection:

    • Live object detection from webcam
    • Press 'q' to quit
    • Press 's' to save screenshots
    • Option to record the session
  3. Process Images:

    • Batch process images from a directory
    • Supports multiple image formats (JPG, PNG, BMP, TIFF)
    • Save annotated images to output directory
  4. Exit: Close the application

Directory Structure

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)

Supported Object Classes

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!

Configuration

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
)

Performance Notes

  • 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 accuracy
    • yolov8s.pt: Good balance of speed and accuracy
    • yolov8m.pt: Higher accuracy, slower processing
    • yolov8l.pt & yolov8x.pt: Highest accuracy, slowest processing

Troubleshooting

Common Issues

  1. "Could not open camera": Check if webcam is connected and not being used by another application
  2. "Video file not found": Ensure the video file path is correct and the file exists
  3. Slow processing: Consider using a smaller model size or reducing video resolution
  4. GPU not detected: Install CUDA-compatible PyTorch version

Performance Tips

  • 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

Output Files

  • Videos: Saved as detected_[original_name].mp4 in the output directory
  • Images: Saved as detected_[original_name].[ext] in the output directory
  • Screenshots: Saved as screenshot_[frame_number].jpg in the output directory

License

This project is open source and available under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

  • YOLOv8 by Ultralytics
  • OpenCV for computer vision operations
  • PyTorch for deep learning framework

About

This project implements a modular Python application for object detection using the YOLOv8 model. It supports video files, live webcam streams, and image directories. With a simple command-line interface, the system performs detection, overlays bounding boxes, and saves annotated results.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages