The integrated webcam in OpenCV on Ubuntu 16.04 is throwing back the below error. I checked cheese with a different program and it shows still images and video, therefore it seems not the camera itself to be the problem here.
The code I used to test this out :
import cv2
import numpy as np
import time
cam = cv2.VideoCapture(2)
if not cam.isOpened():
print('Cannot open camera')
while True:
ret,frame = cam.read()
cv2.imshow('webcam', frame)
if cv2.waitKey(1)&0xFF == ord('q'):
break
cam.release()
cv2.destroyAllWindows()
The error :
Cannot open camera (feedback from script at
if not cam.isOpened():
).OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /io/opencv/modules/highgui/src/window.cpp, line 325
Traceback (most recent call last): File "Video_test.py", line 13, in cv2.imshow('webcam', frame) cv2.error: /io/opencv/modules/highgui/src/window.cpp:325: error: (-215) size.width>0 && size.height>0 in function imshow
Any help would be appreciated. Thanks!