I am trying to run 4 USB cameras and feed them to a monitor. I would like to have the frames of each camera split vertically and horizontally on the monitor so one can see all four feeds at once. I am getting the error noted in the "question". What does this mean? PS - I am a newbie at coding and my knowledge is limited.
import cv2
import numpy as np
cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)
cap3 = cv2.VideoCapture(2)
cap4 = cv2.VideoCapture(3)
while(cap1.isOpened()):
ret, frame = cap1.read()
if ret==True:
cv2.imshow('Left Mold - Cavity 1 & 2', cap1)
while(cap2.isOpened()):
ret, frame = cap2.read()
if ret==True:
cv2.imshow('Left Mold - Cavity 2 & 3', cap2)
while(cap3.isOpened()):
ret, frame = cap3.read()
if ret==True:
cv2.imshow('Right Mold - Cavity 1 & 2', cap3)
while(cap4.isOpened()):
ret, frame = cap4.read()
if ret==True:
cv2.imshow('Right Mold - Cavity 3 & 4', cap4)
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);
#Stack camera 1 & 3 vertically and camera 2 & 4 horizontally to 1 & 3
numpy_vertical = np.vstack((cap1, cap3))
numpy_horizontal = np.hstack((cap2, cap4))
array([[cap1,cap2],
[cap3,cap4]])
#Put the camera feed on the specified axis
numpy_vertical_concat = np.concatenate((cap1, cap3), axis=0)
numpy_horizontal_concat = np.concatenate((cap2, cap4), axis=1)
key = cv2.waitKey(20)
if key == 27: # exit on ESC
sys.exit()
#When everything is done, release the capture
cap1.release()
cap2.release()
cap3.release()
cap4.release()
cv2.destroyAllWindows()