This repository contains scripts for performing object detection using the YOLOv5, YOLOv8, and Faster R-CNN models. The scripts are capable of detecting objects in real-time from live video streams captured by a webcam or an external camera.
The Webcam Object Detection YOLOv8 (cpu).py
script utilizes the YOLOv8 model for object detection. It connects to a webcam or an external camera and performs real-time object recognition. The script draws bounding boxes around detected objects along with labels indicating the type of object and its confidence score.
- Python 3.x
- OpenCV (
cv2
) - NumPy (
numpy
) - PIL (
Pillow
) - Ultralytics YOLO (
ultralytics
)
- Install required Python packages:
pip install opencv-python numpy Pillow ultralytics
- Install the YOLO v8 model:
from ultralytics import YOLO
model = YOLO('yolov8n.pt')
- Usage
python Webcam Object Detection YOLOv8 (cpu).py
By default, the script will use the built-in webcam (camera index 0) for object detection. Press 'q' to exit the program.
Parameters
- camera (int, optional): The camera index. Use 0 for the built-in webcam, or specify 1-n for other connected cameras. Default is 0.
- threshold (float, optional): Confidence threshold for object detection (between 0 and 1). Default is 0.5.
- font_size (int, optional): Font size for object labels. Default is 18.
The Webcam Object Detection YOLOv5 (cpu).py
script utilizes the YOLOv5 model for object detection. It connects to a webcam or an external camera and performs real-time object recognition. The script draws bounding boxes around detected objects along with labels indicating the type of object and its confidence score.
- Python 3.x
- OpenCV (
cv2
) - NumPy (
numpy
) - Torch (
torch
) - Ultralytics YOLO (
ultralytics
)
- Install required Python packages:
pip install opencv-python numpy torch torchvision
- Install the YOLOv5 model:
import torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
- Usage
python Webcam Object Detection YOLOv5 (cpu).py
By default, the script will use the built-in webcam (camera index 0) for object detection. Press 'q' to exit the program.
Parameters
- camera (int, optional): The camera index. Use 0 for the built-in webcam, or specify 1-n for other connected cameras. Default is 0.
- threshold (float, optional): Confidence threshold for object detection (between 0 and 1). Default is 0.5.
- font_size (int, optional): Font size for object labels. Default is 18.
The PyTorch Webcam Object Detection.py
script utilizes the Faster R-CNN model for object detection. It connects to a webcam or an external camera and performs real-time object recognition. The script draws bounding boxes around detected objects along with labels indicating the type of object and its confidence score.
- Python 3.x
- OpenCV (cv2)
- NumPy (numpy)
- TorchVision (torchvision)
- PyCOCO Tools (pycocotools)
- Install required Python packages:
pip install opencv-python numpy torchvision pycocotools
By default, the script will use the built-in webcam (camera index 0) for object detection. Press 'q' to exit the program.
This project utilizes the Ultralytics YOLO library for YOLOv8 object detection and TorchVision for Faster R-CNN object detection. YOLO (You Only Look Once) and Faster R-CNN are state-of-the-art, real-time object detection systems that identify multiple objects in images or video streams.
This project is licensed under the MIT License - see the LICENSE.md file for details.