This project presents a real-time colour detection system using Python and OpenCV. It leverages the HSV (Hue, Saturation, Value) colour space for robust segmentation and accurate colour identification under varying lighting conditions. The system captures live video from a webcam and detects predefined colour ranges such as Red, Green, Blue, Yellow, Orange, and Purple. Detected colours are highlighted with bounding boxes and labels on the video feed. The project demonstrates fundamental concepts of image processing, colour space transformation, masking, and contour detection, making it a valuable introduction to computer vision applications.
Colour detection is a fundamental application of computer vision used in various fields such as robotics, surveillance, and augmented reality. This project aims to detect and identify specific colours in real-time using a webcam feed. By converting frames from BGR to HSV colour space, the system can efficiently filter and recognize colours under different lighting conditions. The project is implemented in Python using OpenCV, and it highlights detected colours with bounding boxes and labels, making it a practical and interactive tool for understanding image processing and colour segmentation techniques.
Video Capture
The system uses a webcam to capture live video frames using OpenCV’s VideoCapture function.
Preprocessing
Each frame is resized for consistency and converted from BGR to HSV colour space to simplify colour detection.
Colour Range Definition
HSV ranges are predefined for common colours (Red, Green, Blue, Yellow). Red is handled with two ranges due to its hue wrapping around the HSV scale.
Masking
A binary mask is created for each color range using cv2.inRange(), isolating regions matching the specified HSV values.
Contour Detection
Contours are extracted from each mask using cv2.findContours(). Contours with significant area are selected to avoid noise.
Color Labeling and Bounding
Detected regions are highlighted with rectangles and labeled with the color name using cv2.rectangle() and cv2.putText().
Display and Exit
The processed frame is displayed in a window. The loop continues until the user presses 'q' to quit.
The colour detection system successfully identifies and highlights predefined colours in real-time using a webcam. By leveraging the HSV colour space, the project ensures reliable colour segmentation even under varying lighting conditions. The implementation demonstrates the practical use of image processing techniques such as masking, contour detection, and bounding box annotation. This project serves as a foundational step towards more advanced computer vision applications like object tracking, gesture recognition, and autonomous systems.