Inconsistent frames
n Python, wait for frames() is used to extract all the frames of the bag file, which are different from those obtained through rosbag. For example, rosbag only gets 5689 frames, while Python gets 6533 frames.
-
It is not unusual to get different frame counts from different approaches to reading a bag.
If Python is your preference, playing back the frames with real-time set to false may give more consistent results.
-
I've set this up, but it's still quite different.And, when I extracted only some of the frames, I found that they were identical.
This is the number of frames you see in matlab.


The results above are consistent with those obtained using rs-convert.exe.Using wait_for_frames() in python, however, results in very different frames.
-
Trying to select exact frame numbers from a bag can be awkward. For example, if you wanted to browse forward and back through frame numbers like watching a video, the recommended solution for rewinding to an earlier frame is to reset to the first frame and then skip ahead to the frame number that you want.
Instead of trying to select a batch of frame numbers, you may get better results if you use ROS' rosbag editing tool to pick out the batch frames you want by setting a start and end point, and save them as a new, smaller bag file.
https://github.com/IntelRealSense/librealsense/issues/4764#issuecomment-526466915
-
What I've done is I've looped from the first frame to the frame I want, which I think is the right thing to do.But the results were not satisfactory.
Here's part of my loop.
while (playback.current_status() == rs.playback_status.playing) :
n += 1
print n
x = np.zeros((848*480,1))
y = np.zeros((848*480,1))
frames = pipe.wait_for_frames()
if (n > start_num-1) and (n < (end_num+1)):
m +=1
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
******* -
The GitHub is the best place for this particular question, and I see that you have already posted it there.
Looking at your code though, my thoughts are:
- Have you defined the values of start_num and end_num, so that they are not both '0' by default?
- I would remove the n += 1 statement in your While loop, and have it in the If loop. This should ensure that it only increments by 1 every time the If loop is checked, if n is not currently smaller than the start value or larger than the end value. If you have the n statement true when playback is active, it gives the potential for n to increment uncontrollably.
- If Librealsense supports the notation, it may be tidier to use 'less than or equal' and 'greater than or equal':
if (n >= start_num) and (n <= (end_num)):
-
Sorry, I only put part of the statement, The values of start_num and end_num are set by me. M is the number of frames in the if statement.N is used to record all the frames of the bag file. What I want to do is process the frames when n is between start_num and end_num, that is, when wait_for_frames reach the one I need.
-
As I said, the GitHub may be the best place to get a solution for this. If I were writing it myself though, I would consider moving the wait_for_frames line outside of the while loop, so that it was on the line below the pipe.start() instruction in your script. 'n' is not going to increment unless playing is true anyway.
Please sign in to leave a comment.
Comments
10 comments