-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the depth frames from recorded .bag file using pyrealsense2? #1887
Comments
The code below takes two input parameter and extract the depth stream images and save them to a directory, you can just add in the color stream and do it the way you do when you have a live realsense camera. I think what went wrong is that you never start the pipeline using
|
Oh my God, how careless am I! T_T Thx @TheMikeyR |
By the way, I also want to know the difference between |
Hi @longjj Thanks @TheMikeyR |
Documentation for
Documentation for
|
@dorodnic Sure |
Thanks @dorodnic , @TheMikeyR . So what if I use I have try the script(only replace import argparse
import pyrealsense2 as rs
import numpy as np
import cv2
import os
def main():
if not os.path.exists(args.directory):
os.mkdir(args.directory)
try:
config = rs.config()
rs.config.enable_device_from_file(config, args.input)
pipeline = rs.pipeline()
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
pipeline.start(config)
i = 0
while True:
print("Saving frame:", i)
frames = rs.composite_frame(rs.frame())
pipeline.poll_for_frames(frames)
depth_frame = frames.get_depth_frame()
depth_image = np.asanyarray(depth_frame.get_data())
cv2.imwrite(args.directory + "/" + str(i).zfill(6) + ".png", depth_image)
i += 1
finally:
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--directory", type=str, help="Path to save the images")
parser.add_argument("-i", "--input", type=str, help="Bag file to read")
args = parser.parse_args()
main() and I get a RuntimeError:
Is it possible that |
I guess you need some logic which waits until a new frame is ready so you can process it and save it. I think your program crash since the frame is not ready yet and you don't have a handler for that. Do it like this:
|
Wow, it's so clear! Thank you so much! @TheMikeyR |
Hi, |
On the enable_device_from_file function, there is a repeat_playback
argument that controls looping over the bag.
|
Thanks a lot @lramati |
When I run @TheMikeyR code using TypeError: poll_for_frames(): incompatible function arguments. The following argument types are supported: |
hello,
|
I'm using the SDK Intel Realsense Viewer v.2.19.0 to create a 'bag' file.There are three cameras for bags. However,I can't press the Sync button.What can I do to solve this problem? |
@TheMikeyR @dorodnic Any views on this issue. I am also getting the same issue with your code |
See the next comment by atanase2. This issue is very old and the API has changed since TheMikeyR posted their code |
be aware that the poll_for_frame function doesn't work with win7. I spend lots of time on this function because of that. |
If I understand correctly there is no way to get the frames apart from streaming (in which you can loose frames if your extracting speed is slower than the actual FPS or the recording? |
@filipematosinov to read a .bag file without losing frames while script is processing images, you have to set as False a "real_time" parameter using the
|
Thanks @lbps for your suggestion it is working now :) |
To check if in |
Issue Description
I record the original data in
.bag
file using therealsense-viewer
's record button. How can I play back the.bag
file and get every depth_frame in it to extract the depth information in my own way, usingpyrealsense2
?I have read
rs-record-playback.cpp
and found that I should set configure first:config.enable_device_from_file("./20180614_105342.bag")
,and then call
pipeline.poll_for_frames()
rather thanpipeline.wait_for_frames()
.When I do these above I get such error :
Then I try
But it still didn't work.
In brief, I have succeed in using the stream:
And now I want to read
.bag
file to get the frames rather than get them from the stream. The code I try is something like that:Are there any example codes or instruction to show how to use
pyrealsense2
to get all depth frames and work on them? Thanks a lot.The text was updated successfully, but these errors were encountered: