使用nuscenes-devkit读取nuscenes的视频文件并输出为mp4视频

访问 https://github.com/nutonomy/nuscenes-devkit,下载依赖。
使用方法,可以学习教程 https://www.nuscenes.org/tutorials/nuscenes_tutorial.html

如何保存到路径

nusc.render_scene_channel(my_scene_token, 'CAM_FRONT', out_path=f"{query}.mp4")指定保存路径参数。

from nuscenes.nuscenes import NuScenes
import cv2


nusc = NuScenes(version='v1.0', dataroot=r'{path-to-nuscenes}', verbose=True)
print(nusc)
print(nusc.list_scenes())
table_name, field, query = 'scene', 'name', 'scene-0061'
print("field2token", nusc.field2token(table_name, field, query))
my_scene_token = nusc.field2token(table_name, field, query)[0]
print("token", my_scene_token)
nusc.render_scene_channel(my_scene_token, 'CAM_FRONT', out_path=f"{
      
      query}.mp4")

输出mp4视频

深入nusc.render_scene_channel,修改依赖包,文件D:\programs\anaconda\Lib\site-packages\nuscenes\nuscenes.py的render_scene_channel函数,如下两处:

if out_path is not None:
    assert osp.splitext(out_path)[-1] == '.avi' or osp.splitext(out_path)[-1] == '.mp4'
if out_path is not None:
    # fourcc = cv2.VideoWriter_fourcc(*'MJPG')
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    out = cv2.VideoWriter(out_path, fourcc, freq, imsize)

猜你喜欢

转载自blog.csdn.net/duoyasong5907/article/details/131250784