0

When trying to capture frames from two cameras (using a single USB hub) simultaneously, only one camera can return a valid frame, the other one will return None. When using one external camera and the internal camera from the laptop, it works fine.

The exact same code and hardware work fine on a Ubuntu system. So it might be problem with Windows or its driver, or there is something wrong using the hub (maybe bandwidth problem, but not power problem because the hub has external power supply)

import cv2
import numpy as np
from multiprocessing import Process
def show(camera_id):
    cap = cv2.VideoCapture(camera_id)
    cap.set(3,640)
    cap.set(4,480)
    cap.set(cv2.CAP_PROP_FPS, 30)
    while True:
        ret, frame = cap.read()
        cv2.imshow('test', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()

if __name__ == '__main__':
    p1 = Process(target=show, args=(0,))
    p2 = Process(target=show, args=(1,))
    p1.start()
    p2.start()
Wenbin Xu
  • 134
  • 2
  • 14
  • @HaBom thank you for your reply. The second process break at line 'ret, frame = cap.read()', so it may not be caused by the name of the windows. And this code works fine on my ubuntu machine. – Wenbin Xu Jan 04 '19 at 06:29
  • I just realise that it's not the problem. I don't have 2 usb cameras, so I try with ip cameras and videos also, but there's nothing wrong with the code. I think maybe it's a bandwidth problem as you've mentioned. I've found another post with the same problem as yours https://stackoverflow.com/questions/29664399/capturing-video-from-two-cameras-in-opencv-at-once – Ha Bom Jan 04 '19 at 06:56
  • @HaBom Thank you for your info. I'm not sure if both posts are referring to the same problem. In my case, multiple cameras can work on my workstation of my HP laptop if I insert them directly to usb ports on my machines. But if I use a usb hub and then connect two cameras to the same external hub, then this problem occurs. I checked that under both circumstances, both cameras are connected to the same usb bus (using 'lsusb'), so I'm a bit confused what may have caused my problem, seems like the hub is limiting the performance? – Wenbin Xu Jan 07 '19 at 01:47

0 Answers0