I'm trying to detect color-range using OpenCV Python.
When I use RGB colors on HSV converted image, it works fine. But when I change lower and upper colors to HSV, it cannot detect colors.
Here is a bit dirty code. lower and upper variables are BGR and I try to convert them below with hsv_lower and hsv_upper but when passed them to cv2.inRange() function, it results with empty black mask/screen.
image = cv2.imread('images/circles.jpg', 1)
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
green = np.uint8([[[0, 255, 0]]])
hsv_green = cv2.cvtColor(green, cv2.COLOR_BGR2HSV)
print hsv_green
lower = np.array([0, 100, 100], np.uint8);
upper = np.array([10, 255, 255], np.uint8);
lowerz = np.uint8([[[0, 100, 100]]]);
hsv_lower = cv2.cvtColor(lowerz, cv2.COLOR_BGR2HSV)
print hsv_lower
upperz = np.uint8([[[10, 255, 255]]]);
hsv_upper = cv2.cvtColor(upperz, cv2.COLOR_BGR2HSV)
print hsv_upper
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, hsv_lower, hsv_upper)
output = cv2.bitwise_and(image, image, mask=mask)
cv2.imshow("images", np.hstack([image, output]))
cv2.imshow('frame', image)
cv2.imshow('mask', mask)
cv2.imshow('res', output)
#cv2.waitKey(0)
k = cv2.waitKey(0) & 0xFF
if k == 27:
cv2.destroyAllWindows()