How to Python Open CV Web Cam 4EA Real time Streaming

14 views Asked by At

I would like to apply Python OpenCV and 4 Web-CAMs to my laptop and capture them simultaneously. So, to check whether capture was running with OpenCV, I wrote the coding below.

Before starting, I checked whether the hardware was recognized by the laptop and completed the verification by running Windows Camera Web. We have confirmed that all four devices are recognized.

I ran the coding below, but the camera does not open.

How do I enable recognition of all four cameras?

help.

    import cv2 
    import threading

    def capture_camera(camera_index): 
       cap = cv2.VideoCapture(camera_index, cv2.CAP_DSHOW)

    if not cap.isOpened():
        print(f"Camera {camera_index} could not be opened.")
        return

    while True:
        ret, frame = cap.read()
        if not ret:
            print(f"Failed to grab frame from camera {camera_index}")
            break
        cv2.imshow(f'Camera {camera_index}', frame)

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

    cap.release()
    cv2.destroyAllWindows()
   
    cameras = [0, 1,2,3 ]
    threads = []
  
    for index in cameras:
        thread = threading.Thread(target=capture_camera, args=(index,))
        thread.start()
        threads.append(thread)

    for thread in threads: 
        thread.join()
0

There are 0 answers