Skip to content

Armi1014/Realtime-Object-Recognition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Realtime Object Recognition

YOLOv8 Object Detection

Simple, real-time object detection using Ultralytics YOLOv8 and OpenCV.

This repo gives you a single script (detect.py) that can:

  • run YOLOv8 on your webcam, images, or videos
  • overlay bounding boxes, FPS, and per-class counts
  • optionally save annotated output to disk

Features

  • 🎥 Live webcam detection (--source 0 by default)
  • 🖼️ Image & video file support
  • 📊 Per-class object counts overlay (e.g. person: 3, car: 1)
  • FPS overlay showing inference speed
  • 💾 Optional saving of annotated images/videos (--save, --out, --fps)
  • 🧠 YOLOv8 model selection via --model (default: yolov8n.pt)
  • 🧪 Verbose logging for debugging (--verbose)

Requirements

  • Python: 3.8 – 3.12
    (avoid 3.13 for now, some wheels may be missing)
  • OS: Windows, Linux, or macOS

Python dependencies (in requirements.txt):

ultralytics>=8.2.0
opencv-python>=4.8.0
numpy>=1.24.0

Install them with:

pip install -r requirements.txt

Model weights (yolov8n.pt)

By default the script uses:

--model yolov8n.pt

If yolov8n.pt is not found locally, Ultralytics will automatically download it on first run.

You can also:

  • place yolov8n.pt in the project folder, or
  • use any other YOLOv8 model, e.g. --model yolov8s.pt or a custom .pt file.

Quick start

1. Clone / download the repo

git clone <your-repo-url>
cd <your-repo-folder>

2. Install dependencies

pip install -r requirements.txt

3. Run with your webcam

python detect.py --source 0 --show
  • 0 = default webcam
  • add --verbose if you want detailed logs

4. Run on an image

python detect.py --source path/to/image.jpg --show --save
  • --show → opens a window with detections
  • --save → writes image_det.jpg next to the original

5. Run on a video file

python detect.py --source path/to/video.mp4 --show --save --fps 30
  • --fps sets the output video FPS (for the saved file)

start.bat (Windows shortcut)

For convenience, the repo includes:

python detect.py --source 0 --show --verbose

You can:

  • double-click start.bat in Explorer to start webcam detection with verbose logging
  • or edit it if you want a different default model/source.

Command-line options

detect.py supports these arguments:

Option Default Description
--source "0" Input source: webcam index (0, 1, …), image path, video path, or stream URL (RTSP/HTTP).
--model yolov8n.pt YOLOv8 model weights file. Can be any .pt compatible with Ultralytics.
--conf 0.25 Confidence threshold (0–1). Higher = fewer, more confident detections.
--imgsz 640 Inference image size (pixels).
--device auto Device string, e.g. cpu, cuda:0. If omitted, Ultralytics auto-selects.
--show False Show a window with live detections.
--save False Save annotated image/video to disk.
--out None Output path for --save. If omitted, a default name is chosen.
--fps 0 Target FPS for saved video; 0 = use source FPS (or 30 if unknown).
--verbose False Print detailed startup and per-frame logs.

How it works (short version)

  • Dependencies (opencv-python, ultralytics, numpy) are imported lazily in ensure_deps() so startup is fast.

  • The script decides whether --source is:

    • a webcam index (like "0")
    • a file path (image/video)
    • or a generic stream URL
  • For images:

    • runs model.predict(...)
    • draws boxes + class labels
    • overlays per-class counts
    • optionally saves the annotated image
  • For video/streams:

    • reads frames in a loop
    • runs inference per frame
    • overlays boxes, FPS, and object counts
    • optionally shows a window and/or saves to a video file

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published