This project is a simple real-time color detection system built using Python, OpenCV, NumPy, and Pillow. It captures video from a webcam, detects a specific color (green by default), and draws a bounding box around the detected object.
This project is useful for:
- Learning basic computer vision concepts
- Understanding HSV color space
- Practicing real-time webcam processing
- Building simple object tracking systems
- Real-time webcam video capture
- HSV-based color detection
- Automatic mask creation
- Bounding box around detected object
- Easy to customize for other colors
- Python
- OpenCV (
cv2) - NumPy
- Pillow (
PIL)
color-detection/
│
├── main.py # Main program for webcam color detection
├── util.py # HSV color range helper function
├── README.md # Project documentationgit clone https://github.com/your-username/your-repo-name.git
cd your-repo-namepip install opencv-python numpy pillowRun the following command:
python main.py- The webcam captures live video frames.
- Each frame is converted from BGR to HSV color space.
- The program detects the selected color range.
- A mask is created to isolate the detected color.
- A bounding box is drawn around the object.
To detect another color, simply change this line in main.py:
green = [0, 255, 0]Example:
- Red →
[0, 0, 255] - Blue →
[255, 0, 0]
- Press Q to quit the application.
- Support multiple colors
- Add object centroid tracking
- Improve detection accuracy with contour filtering
- Add GUI for color selection
Created as a beginner computer vision project using OpenCV.