Locating end of bag file - poll for frame
Hi,
i am using the following to read from bag file.
in this example, the loop runs for 30 times, i do not know how many frames are actually read in this operation of 30 times. I tried the same on some of the bag files of my own and got mixed results. sometimes the same frame is read twice, other times, 4 or 5 frames are jumped. i get the frame number
frames.get_color_frame().get_frame_number();
Also, I found it hard to devise a foolproof way of finding the end of file using the above; as the wait time varies considerably. In a forum, i saw that it is recommended to poll for frames at nearly FPS rate.
So, can anyone help here?
1. how to find EOF.
2. How to set some waiting time if the polling for frame returns 0.
3. Will all the frames be read by polling?
This is intel i7, 16gb ram and SSD HDD.
Regards,
krishnan
-
Hello Srikrishnan V,
Thank you for your interest in the Intel RealSense Technology!
The frame skips can be due to several reasons including, record resolution auto-exposure and several other.
In the Git-hub linked below a user experienced similar issues(repeated/skipped frames) and solved it by upgrading to the latest Firmware and SDK available.
https://github.com/IntelRealSense/librealsense/issues/2214
Also, information and discussions about the poll-from frame function is linked below:
https://github.com/IntelRealSense/librealsense/issues/2711
You can also find more details about issues when reading from .bag files in the link provided below:
https://github.com/IntelRealSense/librealsense/issues/2749
Also, could you please provide us with more details in order to re-create the issues if the steps above do no solve the issue?
Best regards,
Alexandru
-
Hi Alexandru,
Thank you for links. I will look up the links for polling related articles. However, is there any simple way to find end of file?
Just a small feedback that, some of the example code could be updated to be more realistic, over time. As i said, this is a feedback request, not a crib.
Regards,
krishnan
-
Hi,
Here is a code snippet of what i am doing to read frame by frame till end of file. Note that i use a counter to count the number of frames in the file. For one of the files i captured, the frame counter at the end shows 421 OR 423 frames consistently. One occasion it shows 424.
For the other file, it shows 161 consistently. Is there any explanation for the variable count of frames in a bag file? Or am i making some mistake in below? Also, should i post in github or here?
thanks
/* ********************** */
void read_from_bag(unsigned int num_frames, std::string const fname )
{
rs2::pipeline pipeline;
rs2::config cfg;std::cout << fname << std::endl;
cfg.enable_device_from_file(fname);
cfg.enable_all_streams();
rs2::pipeline_profile pipe_profile;
rs2::frameset frameset;
uint32_t counter = 0;
rs2::device dev;
try
{
pipe_profile = pipeline.start(cfg);
dev = pipeline.get_active_profile().get_device();
rs2::playback playback = dev.as<rs2::playback>();
if (playback)
{
;
//std::cout << "Playback from file\n";
}
else
{
std::cerr << "playback error" << "\n";
}
playback.set_real_time(false);
std::chrono::nanoseconds duration = playback.get_duration();
std::cout <<"File duration: " << duration.count() << std::endl;
float frame_count = duration.count() / (1e9);
std::cout << "frames: " << frame_count * 30 << std::endl;
uint64_t curPos;
uint64_t lastPos = 0;
while (pipeline.try_wait_for_frames(&frameset))
{
curPos = playback.get_position();
if (curPos < lastPos)
break;
else
{
counter++;
lastPos = curPos;
depth_frame = frameset.get_depth_frame();
colour_frame = frameset.get_color_frame();
}
}
//std::cout << dev.get_info(RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION) << "\n";
}
catch (rs2::error &e)
{
std::cerr << "Problem in reading file. Failed in function:" <<
e.get_failed_function() << std::endl;
std::cerr << e.what() << std::endl; // What is the error
return;
}
std::cout << counter << " frames read." << std::endl;
pipeline.stop();return;
} -
Hello Srikrishnan V,
Your code works correctly. You will get different frame counters for each bag file because each bag file is a different length, therefore they will have different numbers of frames.
You can verify if your program works by running the tool rs-rosbag-inspector.exe. Open the target bag file, and look at the topics /device_0/sensor_0/depth_0/image/data or /device_0/sensor_1/color_0/image/data and look at the count.
Thank you,
Eliza
-
Hi Eliza,
thanks for reply. I do understand that two bag files will have different or same length depending on recording; i have that much familiarity of software. My doubt was that: i used the above code to count the number of frames in 2 different bag files of different recording duration. For one of the files, when i ran the code multiple times, i get a value of 161 frames consistently - hooray! Unfortunately, when i try the same code on the 2nd bag file, i get number either 423 or 424 - not so good. That is why i emailed to get opinion from experts regarding correctness of code.
But i will try your suggestion of the rosbag-inspector.
Thanks.
Regards,
Krishnan
-
Hello Gaurav,
There are a number of different reasons why a recording may have missing frames. It could be related to a glitch on the USB port or USB cable, or something occurring on the particular computing hardware that the bag was recorded on. For example, a 'bottleneck' in recording that can cause lag is if a fast storage mechanism such as an SSD hard drive was not used to record the data onto (an older type of drive such as a SATA may have difficulty keeping up with the rate of the incoming data)
On some computers, the processor chip of the computing device (the CPU) may have an incompatibility with the recorder's data compression algorithm. In these cases, turning off recording compression can help.
In the case of repeated frames, this may occur because the camera experiences a 'hiccup' during recording and so returns to the most recent "good" frame as a recovery measure and continues onward from that point.
If you are recording a bag, you may find that you get better results if you force a constant FPS speed.
https://github.com/IntelRealSense/librealsense/issues/2255#issuecomment-426186948
Please sign in to leave a comment.
Comments
9 comments