在执行一些openCV工作时出现此错误代码

时间:2018-07-27 00:03:27

标签: python

这是显示为输出的内容:

OpenCV(3.4.1) Error: Assertion failed ((scn == 3 || scn == 4) && (depth == 0 
|| depth == 5)) in cv::cvtColor, file C:\projects\opencv- 
python\opencv\modules\imgproc\src\color.cpp, line 11214
Traceback (most recent call last):
File "set_hand_hist.py", line 70, in <module>
get_hand_hist()
File "set_hand_hist.py", line 38, in get_hand_hist
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
cv2.error: OpenCV(3.4.1) C:\projects\opencv- 
python\opencv\modules\imgproc\src\color.cpp:11214: error: (-215) (scn == 3 || 
scn == 4) && (depth == 0 || depth == 5) in function cv::cvtColor

1 个答案:

答案 0 :(得分:0)

看起来您的图像可能有4个颜色通道而不是3个,例如RGBA而不是RGB。您可以专门加载它以具有3个颜色通道,

img = cv2.IMREAD_COLOR('path/to/img')

请注意,这会载入BGR,因此您可以使用以下方法进行转换:

cv2.cvtcolor(img, cv2.COLOR_BGR2HSV)