For a robot to visualize the environment, along with the object detection, detection of its color in real-time is also very important.
Why this is important? : Some Real-world Applications
- In self-driving car, to detect the traffic signals.
- Multiple color detection is used in some industrial robots, to performing pick-and-place task in separating different colored objects.
This is an implementation of detecting multiple colors (here, only red, green and blue colors have been considered) in real-time using Python programming language.
Python Libraries Used:
Work Flow Description:
Step 1: Input: Capture video through webcam.
Step 2: Read the video stream in image frames.
Step 3: Convert the imageFrame in BGR(RGB color space represented as three matrices of red, green and blue with integer values from 0 to 255) to HSV(hue-saturation-value) color space. Hue describes a color in terms of saturation, represents the amount of gray color in that color and value describes the brightness or intensity of the color. This can be represented as three matrices in the range of 0-179, 0-255 and 0-255 respectively.
Step 4: Define the range of each color and create the corresponding mask.
Step 5: Morphological Transform: Dilation, to remove noises from the images.
Step 6: bitwise_and between the image frame and mask is performed to specificaly detect that particular color and discrad others.
Step 7: Create contour for the individual colors to display the detected colored region distinguishly.
Step 8: Output: Detection of the colors in real-time.
Below is the implementation.
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Python | Corner detection with Harris Corner Detection method using OpenCV
- Python | Corner Detection with Shi-Tomasi Corner Detection Method using OpenCV
- Object Detection with Detection Transformer (DERT) by Facebook
- Detection of a specific color(blue here) using OpenCV with Python
- Opening multiple color windows to capture using OpenCV in Python
- PyQt5 Label – Setting color to the Color Effect
- PyQt5 Label – Accessing color of the Color Effect
- Set Pandas dataframe background Color and font color in Python
- PyQt5 QColorDialog - Setting Multiple Color Dialog Options
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Face Detection using Python and OpenCV with webcam
- Python | Real time weather detection using Tkinter
- Car driving using hand detection in Python
- Python | Smile detection using OpenCV
- Python | Document field detection using Template Matching
- Circle Detection using OpenCV | Python
- ML | Training Image Classifier using Tensorflow Object Detection API
- White and black dot detection using OpenCV | Python
- Text detection using Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.