0
我是OpenCV和Python的初学者,正在执行我的第一步... 我想运行使用OpenCv编写的Python测试代码。我收到一个错误说:Python openCV - 显示摄像头图像的错误
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp, line 3402
Traceback (most recent call last):
File "C:\cam.py", line 11, in <module>
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: ..\..\..\modules\imgproc\src\color.cpp:3402: error: (-215) scn == 3 || scn == 4
它将在空转(Python的GUI),但是,我想与Python的插件VS2010运行它 - 这是我得到的错误。 任何意见如何处理这个错误高度赞赏。
CODE:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
如果从IDLE运行良好,可能是vs2010的一个bug。 – M4rtini
不是因为我试图从cmd运行它并发生同样的错误... – Saint