Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to read videos from three cameras in the same time?

Hello,

I tried to getting videos from three cameras in the same time, but I have the following error, do you have any idea how to read videos from three cameras in python with opencv? It's possible?

This is my code:

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

while True:
    print("In while")
    test1, frame1 = cap1.read()
    test2, frame2 = cap2.read()
    test3, frame3 = cap3.read()
    gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
    gray2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
    gray3 = cv2.cvtColor(frame3, cv2.COLOR_BGR2GRAY)

    if(test1):
         cv2.imshow('frame1', gray1)
         print("Frame 1")
     if(test2):
         cv2.imshow('frame2', gray2)
         print("Frame 2")
     if(test3):
         cv2.imshow('frame3', gray3)
         print("Frame 3")

     if cv2.waitKey(1) & 0xFF == ord('q'):
         break

cap1.release()
cap2.release()
cap3.release()
cv2.destroyAllWindows()

And this is the error:

[ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772 [ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772 [ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772

Traceback (most recent call last):
File "main.py", line 21, in <module> gray3 = cv2.cvtColor(frame3, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(3.4.5) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

[ WARN:1] terminating async callback [ WARN:1] terminating async callback

Can you help me, please, to clarify this topic? Thank you in advance! :)