Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Color-Based Object Detection

A cross-platform computer vision system for real-time color object detection using HSV-based filtering. Supports high-resolution industrial cameras (IMX415 4K) and standard consumer webcams (Logitech), with platform-specific implementations for macOS and Windows.


Overview

The system works in two stages:

  1. Calibration — interactively tune HSV color thresholds for your target object under your lighting conditions
  2. Detection — run real-time detection with bounding boxes, centroid markers, area measurements, and a live FPS counter

Project Structure

ComputerVisionProject/
├── MacOS/
│   └── IMX415/
│       ├── calibration.py          # HSV calibration tool for macOS + IMX415
│       └── colorodDetection.py     # Real-time detection for macOS + IMX415
└── Windows/
    ├── IMX415/
    │   ├── calibrationWindows.py   # HSV calibration tool for Windows + IMX415
    │   └── colorDetectionWindows.py# Real-time detection for Windows + IMX415
    └── Logitech/
        ├── calibrationWindows.py   # HSV calibration tool for Windows + Logitech
        └── colorodDetectionWindows.py # Real-time detection for Windows + Logitech

Requirements

  • Python 3.7+
  • OpenCV
  • NumPy

Install dependencies:

pip install opencv-python numpy

Usage

Step 1 — Calibrate

Run the calibration script for your platform and camera. Interactive sliders let you adjust the HSV range until only your target object is visible in the mask.

macOS (IMX415):

python MacOS/IMX415/calibration.py

Windows (IMX415):

python Windows/IMX415/calibrationWindows.py

Windows (Logitech):

python Windows/Logitech/calibrationWindows.py

The calibration window shows three panels side by side:

Panel Description
Original Raw camera feed
Mask Binary mask from HSV threshold
Result Masked output (target object isolated)

Press S to save the calibrated HSV values. Press Q to quit.


Step 2 — Detect

Run the detection script. It uses the calibrated HSV values to find and track the object in real time.

macOS (IMX415):

python MacOS/IMX415/colorodDetection.py

Windows (IMX415):

python Windows/IMX415/colorDetectionWindows.py

Windows (Logitech):

python Windows/Logitech/colorodDetectionWindows.py

Each detected object is annotated with:

  • Green bounding box
  • Red dot at the centroid
  • Label showing pixel area and center coordinates (x, y)

A color-coded FPS counter is displayed in the top-left corner:

Color FPS
Green ≥ 20 fps
Orange ≥ 10 fps
Red < 10 fps

Press Q to quit.


Camera Details

IMX415

  • Resolution: 3840×2160 (4K) for calibration, 1920×1080 for detection
  • Codec: MJPEG
  • Target FPS: 60
  • Backend: CAP_AVFOUNDATION (macOS) / CAP_MSMF (Windows)

Logitech (USB Webcam)

  • Standard webcam resolution
  • Backend: CAP_MSMF (Windows)

How It Works

  1. Each frame is captured from the camera and converted from BGR to HSV color space.
  2. A binary mask is generated by thresholding the HSV frame within the calibrated color range.
  3. Morphological open and close operations remove noise and fill gaps in the mask.
  4. Contours are extracted from the cleaned mask. Contours below a minimum area threshold are ignored.
  5. For each valid contour, the bounding box and centroid are calculated and drawn on the frame.

HSV color space is used instead of RGB because it separates color information (hue) from lighting intensity (value), making detection more robust under varying lighting conditions.


Calibration Tips

  • Run calibration under the same lighting conditions you plan to use for detection.
  • Start by isolating the Hue channel to match your object's color, then refine Saturation and Value to exclude background noise.
  • The minimum area threshold in the detection script can be adjusted to filter out small false positives.

About

Just another fun weekend project

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages