close

How to detect two different colors using `cv2.inRange` in Python-OpenCV?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to detect two different colors using cv2.inRange in Python-OpenCV in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to detect two different colors using cv2.inRange in Python-OpenCV?

  1. How to detect two different colors using cv2.inRange in Python-OpenCV?

    # Make a copy of the image image_copy = np.copy(image) ## TODO: Define the color selection boundaries in RGB values # play around with these values until you isolate the blue background

  2. detect two different colors using cv2.inRange in Python-OpenCV

    # Make a copy of the image image_copy = np.copy(image) ## TODO: Define the color selection boundaries in RGB values # play around with these values until you isolate the blue background

Method 1

# Make a copy of the image

image_copy = np.copy(image)
## TODO: Define the color selection boundaries in RGB values
# play around with these values until you isolate the blue background

lower_blue = np.array([200,0,0]) 
upper_blue = np.array([250,250,255])

# Define the masked area

mask = cv2.inRange(image_copy, lower_blue, upper_blue)
# Vizualize the mask

plt.imshow(mask,cmap='gray')

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read