how can i track GREEN color in openCV? while red&blue worked

red and blue works fine, what happened to GREEN. i’ve read the similar question and another one,still doesn’t work. see my picture frame,mask,res

import cv2 as cv import numpy as np cap = cv.VideoCapture(0) while(1):     _, frame =     hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)     lower_blue = np.array([110,50,50])     upper_blue = np.array([130,255,255])     lower_green = np.array([45,100,20])     upper_green = np.array([75,255,255])     lower_red = np.array([0,100,100])     upper_red = np.array([10,255,255])     mask1 = cv.inRange(hsv, lower_blue, upper_blue)     mask2 = cv.inRange(hsv, lower_green, upper_green)     mask3 = cv.inRange(hsv, lower_red, upper_red)     res = cv.bitwise_and(frame,frame, mask= mask1+mask2+mask3)     cv.imshow('frame',frame)     cv.imshow('mask',mask1+mask2+mask3)     cv.imshow('res',res)     k = cv.waitKey(5) & 0xFF     if k == 27:         break cv.destroyAllWindows() 
Add Comment
1 Answer(s)

In HSV color space, Hue represents the traditional colors which we perceive. Another main difference is that when RGB color space represented as a cube, HSV is a cylinder so the range of Hue is actually 0 to 360 degrees. Hue represents Green values between ~121 to ~180 degrees and when we rescale that to the input range of Opencv functions (0-255) the value of green should be between 85 to 128. If you are looking for a visual representation this page has a nice interactive model for both RGB and HSV color spaces.

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.