Thersholding using cv2.inRange() function

Question:

I am trying to seperate objects within certain color ranges in an image using opencv/python. I am using cv2.inRange() function for that and when I pass the following parameters to it cv2.inRange(hsv,(0,0,0),(170,255,255)) hsv being my image,
it raises the error below:

  File "c:/Users/fazil/Desktop/Bilgisayar Bilimi/Python/Python Konuları/Opencv/Projeler/Object Tracking.pyw", line 59, in find_the_positions
    threshold = cv2.inRange(hsv,color_down,color_up)
TypeError: Expected Ptr<cv::UMat> for argument 'lowerb'

Why is it doing that and how to fix it? Thank you.

Asked By: someone

||

Answers:

I believe you have to pass in Numpy arrays, or at least that’s what I did.

import numpy as np

lower_gray = np.array([0, 0, 50])
upper_gray = np.array([360, 255, 160])

mask = cv2.inRange(hsv, lower_gray, upper_gray)
Answered By: Levi Harrison