Capturing video from two cameras in OpenCV at once

前端 未结 7 1161
别跟我提以往
别跟我提以往 2020-11-30 04:27

How do you capture video from two or more cameras at once (or nearly) with OpenCV, using the Python API?

I have three webcams, all capable of video streaming, locate

7条回答
  •  离开以前
    2020-11-30 04:46

    try to use this code... it worked as expected... this is for two cams,if you want more cams, just create the "VideoCapture()" objects...for example 3rd cam will have : cv2.VideoCapture(3) and corresponding code in the while loop

    import cv2
    
    frame0 = cv2.VideoCapture(1)
    frame1 = cv2.VideoCapture(2)
    while 1:
    
       ret0, img0 = frame0.read()
       ret1, img00 = frame1.read()
       img1 = cv2.resize(img0,(360,240))
       img2 = cv2.resize(img00,(360,240))
       if (frame0):
           cv2.imshow('img1',img1)
       if (frame1):
           cv2.imshow('img2',img2)
    
       k = cv2.waitKey(30) & 0xff
       if k == 27:
          break
    
    frame0.release()
    frame1.release()
    cv2.destroyAllWindows()
    

    ALL THE BEST !

提交回复
热议问题