Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

imho, your ranges are a bit off. it will definitely get better, if you add some pixel-testing code to your prog to test the actual hsv values, like:

def onmouse(k,x,y,s,p): global hsv if k==1: # left mouse, print pixel at x,y print hsv[y,x]

cv2.namedWindow("hsv") cv2.setMouseCallback("hsv",onmouse); cv2.imshow('hsv',hsv)

using your image above i get something like:

[ 83 218 237]

then, you can adjust your ranges, maybe to:

lower_green = np.array([75,200,200]) upper_green = np.array([85,255,255])

and get a beautiful mask:

imho, your ranges are a bit off. it will definitely get better, if you add some pixel-testing code to your prog to test the actual hsv values, like:

def onmouse(k,x,y,s,p):
    global hsv
    if k==1:   # left mouse, print pixel at x,y
        print hsv[y,x]

hsv[y,x]

cv2.namedWindow("hsv") cv2.setMouseCallback("hsv",onmouse); cv2.imshow('hsv',hsv)

cv2.imshow('hsv',hsv)

using your image above i get something like:

[ 83 81 218 237]

then, you can adjust your ranges, maybe to:

lower_green = np.array([75,200,200])
upper_green = np.array([85,255,255])

np.array([85,255,255])

and get a beautiful mask:

image description