0

I try to show 2 usb_cameras with 2 differents windows at the same time using openCV -python (I want to implement stereo vision and deep estimation), but I only obtain one window at a time. Can you help me please!

import threading
import cv2

def usb_video1():
  cap = cv2.VideoCapture(2)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 200)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 150)
  while(True):
    ret, frame = cap.read()
    if ret == True:
      cv2.imshow('frame',frame)
      if cv2.waitKey(1) & 0xFF == ord('s'):
        break
    else :
        break
  cap.release()
  cv2.destroyAllWindows()

def usb_video2():
  cap = cv2.VideoCapture(4)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 200)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 150)
  while(True):
    ret, frame = cap.read()
    if ret == True:
     cv2.imshow('frame_2',frame)
     if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    else :
        break
  cap.release()
  cv2.destroyAllWindows()


t01 = threading.Thread(target=usb_video1())
t02 = threading.Thread(target=usb_video2())
t01.start()
t02.start()
Noemí
  • 33
  • 1
  • 5
  • Does this answer your question? [Capturing From 2 Cameras (OpenCV, Python)](https://stackoverflow.com/questions/8651948/capturing-from-2-cameras-opencv-python) – Julien Jun 15 '21 at 05:09
  • Hi Julien, not works for me. This works only if I use the webcam integrate on my laptop and an extra usb camera . But not 2 usb extra cameras – Noemí Jun 15 '21 at 20:43
  • Dirty solution: just open the cameras in two separated processes, i.e. executing `python camera1.py` and `python camera2.py`. – decadenza Mar 22 '22 at 18:06

0 Answers0