Exp3 2
Exp3 2
Experiment - 3
Aim: Write a program for color detection.
Description: The provided Python program detect_color utilizes the OpenCV library to read
an image from a given file path. It then converts the image from the RGB color space to the
HSV (Hue, Saturation, Value) color space, which is more suitable for color detection tasks.
The lower and upper bounds of the color to be detected are defined in the HSV color space.
Using the specified lower and upper bounds, the program creates a binary mask that
identifies pixels within the specified color range. This mask is then applied to the original
image using bitwise AND operation, resulting in an image where only the pixels within the
specified color range are retained, while all other pixels are set to zero.
The resulting image, containing only the detected color, is returned as output. This allows
users to easily identify and analyze regions of interest within the image based on their color
characteristics.
import cv2
from google.colab.patches import cv2_imshow
import numpy as np
!wget -O image.jpg
https://imgeng.jagran.com/images/2023/oct/Jarvo1696758979907.jpg