同一台摄像机的Opencv视频流window

Opencv videostream of two cameras in the same window

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

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

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

#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)