python opencv 同一窗口播放4个以及多个同帧率视频
names = ['/workspace/data/fusion_data/113/demo/1_camera.avi',
'/workspace/data/fusion_data/113/demo/2_camera.avi',
'/workspace/data/fusion_data/113/demo/3_lidar_bev.mp4',
'/workspace/data/fusion_data/113/demo/image_to_fusion_113_v2.avi']
window_titles = ['camera_1', 'camera_2', 'lidar_1', 'fusion']
cap = [cv2.VideoCapture(i) for i in names]
frames = [None] * len(names)
ret = [None] * len(names)
width = 480
height = 270
while True:
for i,c in enumerate(cap):
if c is not None:
ret[i], frames[i] = c.read()
frameLeftUp = cv2.resize(frames[0], (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frameRightUp = cv2.resize(frames[1], (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frameLeftDown = cv2.resize(frames[2], (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frameRightDown= cv2.resize(frames[3], (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frameUp = np.hstack((frameLeftUp, frameRightUp))
frameDown = np.hstack((frameLeftDown, frameRightDown))
frame = np.vstack((frameUp, frameDown))
cv2.imshow("Sensor fusion", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
for c in cap:
if c is not None:
c.release()
cv2.destroyAllWindows()