By she hates me

2018-02-24 18:53:25 8 Comments

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)
k = cv2.waitKey(0) & 0xFF
if k == 27:


Related Questions

Sponsored Content

1 Answered Questions

1 Answered Questions

[SOLVED] How to find if color exists in an image

3 Answered Questions

[SOLVED] Simple Digit Recognition OCR in OpenCV-Python

1 Answered Questions

1 Answered Questions

[SOLVED] opencv - python - confused when using HSV color in cv2.inRange

1 Answered Questions

[SOLVED] opencv python copy mask region (black or white pixels) onto a BGR image region

  • 2016-06-01 16:13:20
  • cv2asker
  • 2298 View
  • 3 Score
  • 1 Answer
  • Tags:   python opencv

1 Answered Questions

[SOLVED] HSV color detection with OpenCV

Sponsored Content