Read Bag Files
Hey,
i made a couple videos with the realsense d435i. Now i want to read the bag files. I found this script which i wanted to use. I added the locations for the bag file and started the script. Unforuntely i only get this message:
"No input paramater have been given."
Where's my mistake in the RealSense Viewer I can watch the video but not with this script?
Thank you very much :)
#####################################################
## Read bag from file ##
#####################################################
# First import library
import pyrealsense2 as rs
# Import Numpy for easy array manipulation
import numpy as np
# Import OpenCV for easy image rendering
import cv2
# Import argparse for command-line options
import argparse
# Import os.path for file path manipulation
import os.path
# Create object for parsing command-line options
parser = argparse.ArgumentParser(description=r"C:\Users\andif\Desktop\test\bag_test.bag")
# Add argument which takes path to a bag file as an input
parser.add_argument("-i", "--input", type=str, help=r"C:\Users\andif\Desktop\test\bag_test.bag")
# Parse the command line arguments to an object
args = parser.parse_args()
# Safety if no parameter have been given
if not args.input:
print("No input paramater have been given.")
print("For help type --help")
exit()
# Check if the given file have bag extension
if os.path.splitext(args.input)[1] != ".bag":
print("The given file is not of correct file format.")
print("Only .bag files are accepted")
exit()
try:
# Create pipeline
pipeline = rs.pipeline()
# Create a config object
config = rs.config()
# Tell config that we will use a recorded device from file to be used by the pipeline through playback.
rs.config.enable_device_from_file(config, args.input)
# Configure the pipeline to stream the depth stream
# Change this parameters according to the recorded bag file resolution
config.enable_stream(rs.stream.depth, rs.format.z16, 30)
# Start streaming from file
pipeline.start(config)
# Create opencv window to render image in
cv2.namedWindow("Depth Stream", cv2.WINDOW_AUTOSIZE)
# Create colorizer object
colorizer = rs.colorizer()
# Streaming loop
while True:
# Get frameset of depth
frames = pipeline.wait_for_frames()
# Get depth frame
depth_frame = frames.get_depth_frame()
# Colorize depth frame to jet colormap
depth_color_frame = colorizer.colorize(depth_frame)
# Convert depth_frame to numpy array to render image in opencv
depth_color_image = np.asanyarray(depth_color_frame.get_data())
# Render image in opencv window
cv2.imshow("Depth Stream", depth_color_image)
key = cv2.waitKey(1)
# if pressed escape exit program
if key == 27:
cv2.destroyAllWindows()
break
finally:
pass
-
Hi Andi Forster I see that you are using the RealSense SDK's read_bag_example.py Python bag reading example program.
Please try placing your bag file in the same folder location as your script and inputting the command below:
read_bag_example.py -i <name of bag>.bag
For example, if the bag file was called 'test.bag'":
read_bag_example.py -i test.bag
The above instruction assumes that you have named your script 'read_bag_example.py'. If your script has a different name then use your own program name. For example, if you called it 'bagreader.py':
bagreader.py -i test.bag
-
I have tried to read the bag file using the python wrapper example read bag file but I am not able to read the bag file. I have applied the above specified method but still the command just starts and then stops in split second without showing anything. Could you please provide the way by which I could read .bag file?
I also want to display the images from the recorded bag file and then save those images. Is it possible to perform that using the above example?
-
Hi Yadavashwani467 Do you have access to the RealSense Viewer tool? If you do then you can test playback of your bag to see whether the file itself is okay by dragging and dropping the bag file into the center panel of the Viewer to automatically initiate playback.
It should playback bag files that were recorded in the RealSense SDK, using the Viewer or a bag recording script. Bag files recorded in ROS with the command rosbag record will have incompatibility.
Please sign in to leave a comment.
Comments
3 comments