【问题标题】:Opencv videostream of two cameras in the same window同一窗口中两个摄像头的Opencv视频流
【发布时间】:2022-01-07 09:06:42
【问题描述】:

我正在尝试使用 opencv 将两个摄像头同时流式传输到一个窗口中。知道我该怎么做吗? 我可以使用不同的窗口和线程来做到这一点,但我想将两个流合并到一个窗口中。

注意:相机具有相同的分辨率

【问题讨论】:

    标签: python opencv video stream capture


    【解决方案1】:

    这应该适用于以下示例。请试试这个。

    #for image
    ret1, img1 = camera1.read()
    ret2, img2 = camera2.read()
    if ret1==False or ret2==False:
          print("could not read from cameras !")
          return
    
    # now, you can do this either vertical (one over the other):
    final = cv2.vconcat([img1, img2])
    
    # or horizontal (next to each other):
    #final = cv2.hconcat([img1, img2])
    
    imshow("I", final)
    waitKey(10)
    

    更多参考请看https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga4676b1376cdc4e528dab6bd9edc51c1a

    #for video: P.S: It should be like this, but I didn't test it with video.
    
    cap_1= cv2.VideoCapture(CAP_ANY)
    cap_2 = cv2.VideoCapture(CAP_ANY)
      
    while true:
          ret_1, frame_1 = cap_1.read()
          ret_2, frame_2 = cap_2.read()
    
    # now, you can do this either vertical (one over the other):
         final = cv2.vconcat([frame_1, frame_2])
    
    # or horizontal (next to each other):
    #final = cv2.hconcat([img1, img2])
    
           imshow("I", final)
           waitKey(10)
    

    【讨论】:

    • 但这不是一个流,这只是一个捕获。我想要一个视频(也许使用 cv2.VideoCapture)。
    • 尝试在while循环中逐帧添加。答案已更新并立即查看。
    • 相机会随着时间的推移而分开。这不会长期有效。
    猜你喜欢
    • 2015-06-22
    • 2014-05-06
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    相关资源
    最近更新 更多