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

0 comments

Related Questions

Sponsored Content

3 Answered Questions

[SOLVED] Simple Digit Recognition OCR in OpenCV-Python

0 Answered Questions

Convert single BGR color to HSV C++ OpenCV 4

  • 2018-11-30 13:44:48
  • Manmohan Bishnoi
  • 407 View
  • 0 Score
  • 0 Answer
  • Tags:   c++ opencv

1 Answered Questions

0 Answered Questions

Finding exact hsv values for colors with green and purple in opencv

  • 2018-06-05 14:07:08
  • Vision123
  • 290 View
  • 1 Score
  • 0 Answer
  • Tags:   python opencv

1 Answered Questions

imshow window is cutoff

  • 2018-03-12 12:11:28
  • Bao Tran
  • 316 View
  • 0 Score
  • 1 Answer
  • Tags:   opencv imshow

0 Answered Questions

C++ OpenCV Color Thersholding HSV images Errors

  • 2017-09-16 22:35:27
  • Rohan G
  • 343 View
  • 0 Score
  • 0 Answer
  • Tags:   c++ opencv hsv

0 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
  • 1993 View
  • 3 Score
  • 1 Answer
  • Tags:   python opencv

1 Answered Questions

[SOLVED] HSV color detection with OpenCV

Sponsored Content