import argparse
import pyrealsense2 as rs
import numpy as np
import cv2
import os
"""
this is a file for convert .bag files to .png files for RealSense RGB-D data
"""
# every n_skip, save one image
n_skip = 10
def main():
if not os.path.exists(args.depth_directory):
os.mkdir(args.depth_directory)
if not os.path.exists(args.color_directory):
os.mkdir(args.color_directory)
try:
pipeline = rs.pipeline()
config = rs.config()
rs.config.enable_device_from_file(config, args.input, repeat_playback=False)
config.enable_stream(rs.stream.depth, 848, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)
pipeline.start(config)
rs.align(rs.stream.color)
# start to convert
i = 0
while i <= 300: # fps = 30, usually, each video lasts around 10 sec.
frames = pipeline.wait_for_frames()
print("num", frames.frame_number)
if i % n_skip == 0:
print("Saving frame:", i)
# saving depths
depth_frame = frames.get_depth_frame()
depth_image = np.asanyarray(depth_frame.get_data())
cv2.imwrite(args.depth_directory + "/" + str(i).zfill(6) + ".png", depth_image)
# saving RGBs
color_frame = frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
print(color_image.shape)
cv2.imwrite(args.color_directory + "/" + str(i).zfill(6) + ".png", color_image)
i += 1
finally:
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-d_d", "--depth_directory", type=str, help="Path to save the depth images")
parser.add_argument("-c_d", "--color_directory", type=str, help="Path to save the RGB images")
parser.add_argument("-i", "--input", type=str, help="Bag file to read")
args = parser.parse_args()
main()
python提取bag文件中的图片数据
转载
不论你在什么时候开始,重要的是开始之后就不要停止。
不论你在什么时候结束,重要的是结束之后就不要悔恨。
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:python 图片转pdf
下一篇:亲测linux上安装mysql
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
七牛云直播转mp4并截取视频
利用七牛云指令把m3u8转成mp4,并截取视频
七牛 直播 mp4 视频截取 -
Commons Collections - Bag组
先来看Bag组。
360 Apache apache System java