Capturing webcam in python
I have been trying to capture my webcam in Ubuntu environment using python using the following 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
When everything done, release the capture
cap.release() cv2.destroyAllWindows()
However, I'm getting the following error all the time
File "/home/mina/untitled10.py", line 22, in <module> cv2.imshow('frame',frame)
error: /root/mc-x64-2.7/conda-bld/opencv-3_1482256854890/work/opencv-3.1.0/modules/highgui/src/window.cpp:281: error: (-215) size.width>0 && size.height>0 in function imshow
How can I fix that? Thank you