0

I'm trying to add multiple cameras using OpenCV python but in my case, it is not working. I printed out the return then one is given true and another is false. But when I use each camera as single then it works fine. I tried to solve it but the solution doesn't come. I have attached the output to this post. [Note] Python Version - 3.7.6 and OpenCV version - 4.4.0, usb cameras


import numpy as np
import cv2

video_capture_0 = cv2.VideoCapture(0, cv2.CAP_DSHOW)
video_capture_1 = cv2.VideoCapture(1, cv2.CAP_DSHOW)

while True:
    # Capture frame-by-frame
    ret0, frame0 = video_capture_0.read()
    ret1, frame1 = video_capture_1.read()
    print(ret0)
    print(ret1)
    cv2.imshow('Cam 1', frame1)

    if (ret0):
        # Display the resulting frame
        cv2.imshow('Cam 0', frame0)

    if (ret1):
        # Display the resulting frame
        cv2.imshow('Cam 1', frame1)

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

# When everything is done, release the capture
video_capture_0.release()
video_capture_1.release()
cv2.destroyAllWindows()

Output Image

enter image description here

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • 1
    possible duplicate [Capturing video from two cameras in OpenCV at once](https://stackoverflow.com/questions/29664399/capturing-video-from-two-cameras-in-opencv-at-once#:~:text=Using%20OPENCV%20and%20two%20standard,and%20window%20name%20as%20inputs.&text=This%20will%20open%20up%20a%20new%20thread%20for%20each%20webcam%20you%20have.) – Walulya francis Aug 22 '21 at 18:54
  • if, as you say, opening each camera alone succeeds, but opening both at the same time fails, that's a curious situation. using threads or not, as advised in the previous comment, should make **no difference**. please describe your system. **exactly** what cameras are those, exactly what USB controllers are in the system, on exactly which controller is each camera connected. *experiment: try* running two processes, where one opens the first and one opens the second camera. does this fail/succeed? **and**, run those things **outside** of IDLE. it may interfere. run from two cmd.exe terminals. – Christoph Rackwitz Aug 22 '21 at 19:48

0 Answers0