Ask Your Question
1

How to define "lower" and "upper" range of two (or more) different color?

asked 2018-01-05 02:15:00 -0600

mrlyzin gravatar image

This topic: 134248/how-to-define-the-lower-and-upper-range-of-a-color/ gives me some question

How can I define "lower" and "upper" range of two different color, such as red and blue (because red and blue are not next to each other in the HSV color)

This one belongs to red:

lower_red = np.array([160,20,70])
upper_red = np.array([190,255,255])

and this one belongs to blue:

lower_blue = np.array([101,50,38])
upper_blue = np.array([110,255,255])

I tried to combine them using if condition or make their own function but not work, can you guys show me the solution?

edit retag flag offensive close merge delete

Comments

you should make seperate masks with inRange() for each color, and then combine those masks using cv2.bitwise_or()

berak gravatar imageberak ( 2018-01-05 05:32:21 -0600 )edit

you mean this?

lower_red = np.array([160,20,70])
upper_red = np.array([190,255,255])
lower_blue = np.array([101,50,38])
upper_blue = np.array([110,255,255])

mask1 = cv2.inRange(hsv, lower_red, upper_red)
mask2 = cv2.inRange(hsv, lower_blue, upper_blue)

mask = cv2.bitwise_xor(mask1, mask2)

I tried, it receive every red and blue thing (include the thing I don't want it receive), but when I run the program red and blue range one-by-one, it didn't do that? What is my mistake?

mrlyzin gravatar imagemrlyzin ( 2018-01-05 08:15:40 -0600 )edit

@mrlyzin. The answer is NOOOOOOOOoooooo! Look at stackoverflown how to detect color

supra56 gravatar imagesupra56 ( 2018-01-05 20:27:42 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-09-29 01:18:17 -0600

naomi fridman gravatar image

I had similar problem, so I wrote this port that describe with examples how to find the lower and upper boundaries. https://medium.com/@naomi.fridman/ima...

edit flag offensive delete link more

Comments

link only answer -- pretty useless here ;(

berak gravatar imageberak ( 2020-09-29 01:46:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-01-05 02:15:00 -0600

Seen: 12,660 times

Last updated: Jan 05 '18