I purchased two webcams (Logitech C310 HD Webcam) to use with RaspberryPi (RPi 3 B+ model). When I run individual cameras, they are running fine but when I tried to run both cameras at the same time it didn't run. I came to know that it may be due to less power in Raspberry Pi, so I purchased a powered USB hub (Power USB hub). When I attached both cameras with raspberry pi through a power USB hub, it shows an error.
VIDIOC_QBUF: Invalid argument cv2.imshow("frame2",frame2) cv2.error: OpenCV(3.4.4) /home/pi/packaging/opencv-python/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
My code is:
import cv2 import numpy as np import imutils from imutils.video import WebcamVideoStream from imutils.video import VideoStream cam1 = WebcamVideoStream(src=0).start() cam2 = WebcamVideoStream(src=2).start() #cam1 = VideoStream(src=0).start() #cam2 = VideoStream(src=2).start() while (1): frame1 = cam1.read() cv2.imshow("frame1",frame1) frame2 = cam2.read() cv2.imshow("frame2",frame2) k = cv2.waitKey(5) & 0xFF if k == 27: break cam1.release() cam2.release() cv2.destroyAllWindows()
With single web camera, above code works fine (when this code modifiy for single cam.) Why there is an error while trying to run two cameras with Raspberry Pi? How I can run two webcams using Raspberry Pi.
cam1 = WebcamVideoStream(src=0).start(), then first cam run and if I used
cam1 = WebcamVideoStream(src=2).start(), then second cam runs. But, whenever I tried to run both cams, it shows error as mentioned in question.