Skip to content

Code to do object recognition for webcams, built in or external

License

Notifications You must be signed in to change notification settings

baileyarzate/WebcamObjectDetection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Object Detection using YOLOv8, YOLOv5, and Faster R-CNN

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.

YOLOv8 Object Detection

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.

Requirements

  • Python 3.x
  • OpenCV (cv2)
  • NumPy (numpy)
  • PIL (Pillow)
  • Ultralytics YOLO (ultralytics)

Installation

  1. Install required Python packages:
pip install opencv-python numpy Pillow ultralytics
  1. Install the YOLO v8 model:
from ultralytics import YOLO
model = YOLO('yolov8n.pt')
  1. 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.

YOLO v5 Object Detection

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.

Requirements

  • Python 3.x
  • OpenCV (cv2)
  • NumPy (numpy)
  • Torch (torch)
  • Ultralytics YOLO (ultralytics)

Installation

  1. Install required Python packages:
pip install opencv-python numpy torch torchvision
  1. Install the YOLOv5 model:
import torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
  1. 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.

Faster R-CNN Object Detection

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.

Requirements

  • Python 3.x
  • OpenCV (cv2)
  • NumPy (numpy)
  • TorchVision (torchvision)
  • PyCOCO Tools (pycocotools)
  1. 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.

Acknowledgments

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.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Code to do object recognition for webcams, built in or external

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages