I have the following simple python code:
import numpy as np
import cv2
'''Device index is just the number to specify
which camera. Normally one camera will be connected
(as in my case). So I simply pass 0 (or -1)
'''
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
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
But it doesn't run, and i get the error message:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file C:\OpenCV-2.4.2\sources\modules\imgproc\src\color.cpp, line 3739
Traceback (most recent call last):
File "C:\Users\dom\Dropbox\eclipse_luna\testpythen\video_capture.py", line 18, in <module>
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: C:\OpenCV-2.4.2\sources\modules\imgproc\src\color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor
I'm new to OpenCV so dont know how to get this code working. I've googled around this error, but am a bit lost. Could it be a problem with my color.cpp module; or the setup of my webcam?
I'm using Eclipse to edit my python scripts.