Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenCV:获取HSV颜色并与inRange一起使用_Python_Opencv_Numpy_Python 3.4_Opencv3.0 - Fatal编程技术网

Python OpenCV:获取HSV颜色并与inRange一起使用

Python OpenCV:获取HSV颜色并与inRange一起使用,python,opencv,numpy,python-3.4,opencv3.0,Python,Opencv,Numpy,Python 3.4,Opencv3.0,因此,我尝试使用Python 3.4和Numpy和OpenCV来实现这一点: 1) Grab pixel color in HSV format in desired area. 2) Use it with cv2.inRange 3) Track given object 以下是我的代码片段: # Capture pixel color from HSV ret, frame = cap.read() frame = cv2.GaussianBlur(frame, (11, 11),

因此,我尝试使用Python 3.4和Numpy和OpenCV来实现这一点:

1) Grab pixel color in HSV format in desired area.
2) Use it with cv2.inRange
3) Track given object 
以下是我的代码片段:

# Capture pixel color from HSV
ret, frame = cap.read()

frame = cv2.GaussianBlur(frame, (11, 11), 0)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 

height, width = frame.shape[:2]
color = hsv[int(width/2)][int(height/2)] # Grab pixel at center
我的问题是,当我想要手动跟踪红色对象时,我需要按如下方式设置inRange:

lower_collor = np.array([0, 150, 150])
upper_collor = np.array([10, 255, 255])
mask = cv2.inRange(hsv, lower_color, upper_color)
它的工作原理(几乎)完美,但当我试图从像素中用上面的代码获取红色对象的颜色时,我得到了这个值:
18 84 183
。所以H和V值是+-OK,但S值完全超出范围

我想我只是错过了一些东西,但我想不出是什么