Ask Your Question

Revision history [back]

I've found the issue already.

  1. cv2.VideoCapture() just give you access to the camera. The actual image is retrieved when you do .read(). In your code, you are stacking cameras that is why your compiler is yelling at you.

  2. You have so many infinite loops. Just one will suffice.

Your general layout should be like this

import cv2 
import numpy as np

cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)
cap3 = cv2.VideoCapture(2)
cap4 = cv2.VideoCapture(3)

cap1.set(cv2.CAP_PROP_FRAME_WIDTH, 320);
cap1.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);
cap2.set(cv2.CAP_PROP_FRAME_WIDTH, 320); 
cap2.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);
cap3.set(cv2.CAP_PROP_FRAME_WIDTH, 320);
cap3.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);
cap4.set(cv2.CAP_PROP_FRAME_WIDTH, 320);
cap4.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);

while cap1.isOpened() and cap2.isOpened() and cap3.isOpened() and cap4.isOpened():
    ret1, frame1 = cap1.read()
    ret2, frame2 = ......


    #finish the rest
    if ret1 == True and ret2 == True:
        # do your stuff and stack frame1, frame2 etc instead