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.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()
 frame2 = cam2.read()

 k = cv2.waitKey(5) & 0xFF
 if k == 27:

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.

  • what happens if you use code for one camera and plug in both cameras?
    – jsotola
    Jun 13, 2019 at 15:34
  • In that case, single camera only run. If I used 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. Jun 14, 2019 at 4:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.