Skip to content
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

C++ Rosbag: Failed to create ros reader: Bag unindexed #2835

Closed
HippoEug opened this issue Dec 4, 2018 · 15 comments
Closed

C++ Rosbag: Failed to create ros reader: Bag unindexed #2835

HippoEug opened this issue Dec 4, 2018 · 15 comments
Assignees

Comments

@HippoEug
Copy link

HippoEug commented Dec 4, 2018

Required Info
Camera Model D400
Firmware Version 05.10.13.00
Operating System & Version Win 10
Kernel Version (Linux Only)
Platform PC
SDK Version 2.16.5
Language C++
Segment others

Introduction

Hello, I am trying to do a short rosbag recording.

Goal

When a recording is done, with record.bag, I want to use rs-convert.exe to produce realsense_Color_7.png, realsense_Depth_5.png, and realsense_Depth_5.csv.

Issue

I am unable to record and open .bag files consistently. Without modifying my short rosbag recording code, I can sometimes open the .bag, but other time it gives me an error of
Failed to load file C:\Users\efoo1\Documents...\
Failed to create ros reader: Bag unindexed

image

ROSBAG Code:

if (camera_button_rosbag) {
	pipe->start(recordConfig);
	std::this_thread::sleep_for(std::chrono::milliseconds(1500));
	pipe->stop();

	std::cout << "Done Recording (ROSBAG)" << std::endl;
}

image

The pipeline is stopped successfully (or so I think), why would I still have the bag unindexed error? Sometimes I wouldn't have this error, sometimes I would. I am unable to find out what is causing this, since this is random and isn't consistent..

Any help is appreciated, thanks!

Edit

image

After a recording is done, if I close the program from the console window, I will get the bag unindexed error even though pipeline is closed. If i close the program from the main GLFW window instead, this error would occur lesser (or maybe none at all). Is there anything in the destructor that is causing this?

The information would be helpful to me because I plan to run the rosbag converter in the program itself right after rosbag recording, not using rs-convert.exe. Running the rosbag converter code copied from rs-convert.cpp right after a rosbag recording crashes the program too, caused by this bag unindexed error.

@dorodnic
Copy link
Contributor

dorodnic commented Dec 4, 2018

Hi @HippoEug
Yes, this is definitely destruction issue, since ROS-bag indexing is performed when closing the file.
Can you try pipe->stop(); pipe.reset(); to make sure everything is cleaned-up?
This might be a bug, if the recorder remains open after pipeline gets destroyed, so please let us know.

@HippoEug
Copy link
Author

HippoEug commented Dec 5, 2018

Hi Dorodnic,

pipe->stop(); followed by pipe.reset(); does not fix the issue. Closing the application from console instead of the OpenGL window even after doing pipe.reset(); results in Bag unindexed error when trying to open the .bag file.

However there is an interesting difference I do not understand.

Code:

// Rosbag Recording
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
pipe->stop(); // Stop the pipeline that holds the file and the recorder
std::cout << "Pipe Stopped (ROSBAG)" << std::endl;
pipe.reset();
std::cout << "Pipe Reset (ROSBAG)" << std::endl;


// Rosbag Conversion
rs2::config convertConfig;
convertToCSV.push_back(std::make_shared<rs2::tools::converter::converter_csv>("abc"));
convertToPNG.push_back(std::make_shared<rs2::tools::converter::converter_png>("abc"));
convertConfig.enable_device_from_file("record.bag");

pipe->start(convertConfig); <- <- <- <- <- <- <- <- <- <- <- <- <- <- <- <- <- <- <-
std::cout << "After record config start" << std::endl;
auto device = pipe->get_active_profile().get_device();
rs2::playback playback = device.as<rs2::playback>();
playback.set_real_time(false);
auto duration = playback.get_duration();
int progress = 0;
int frameNumber = 0ULL;

while (true) {
	std::cout << "Waiting for frames" << std::endl;
	auto frameset_c = pipe->wait_for_frames();
	std::cout << frameset_c[0].get_frame_number() << std::endl;
...
...
...
}

During Rosbag conversion, at pipe->start(convertConfig), the application will simply crash there when it fails to read the bag. Previously, without adding pipe.reset();, Visual Studio would give a runtime error.

In the mean time, I will try to find a temporary workaround.

Thank you!

@dorodnic
Copy link
Contributor

dorodnic commented Dec 11, 2018

Hi @HippoEug
After looking into it, it seems that config object also holds the device open.
Can you try this in your recording application:

{ // Note the added scope
     rs2::config convertConfig;
     convertConfig.enable_record_to_file("record.bag");
     pipe->start(convertConfig);
}

I think this might be related.

@HippoEug
Copy link
Author

Hi @dorodnic

I am still pretty confused. Firstly, what changes would the { } do? Secondly, since I am reading from the file, isn't it appropriate to use convertConfig.enable_device_from_file(); instead of convertConfig.enable_record_to_file();?

I did some modifications:

{ // Note the added scope
     rs2::config convertConfig;
     convertToCSV.push_back(std::make_shared<rs2::tools::converter::converter_csv>("abc"));
     convertToPNG.push_back(std::make_shared<rs2::tools::converter::converter_png>("abc"));
     convertConfig.enable_record_to_file("record.bag");
     pipe->start(convertConfig);
}

auto device = pipe->get_active_profile().get_device();
rs2::playback playback = device.as<rs2::playback>();
playback.set_real_time(false);
auto duration = playback.get_duration();
int progress = 0;
int frameNumber = 0ULL;

while (true) {
	std::cout << "Waiting for frames" << std::endl;
	auto frameset_c = pipe->wait_for_frames();
	std::cout << frameset_c[0].get_frame_number() << std::endl;

	if (frameset_c[0].get_frame_number() > 5) { // If end of frame, bag loops again, hence get_frame_number resets to 1 and is smaller
		std::for_each(convertToCSV.begin(), convertToCSV.end(), [&frameset_c](std::shared_ptr<rs2::tools::converter::converter_base>& converter) {
			converter->convert(frameset_c);
		});
		std::cout << "\nCONVERTING CSV" << std::endl;
		std::for_each(convertToCSV.begin(), convertToCSV.end(), [](std::shared_ptr<rs2::tools::converter::converter_base>& converter) {
			converter->wait();
		});
		std::cout << "CONVERTING PICTURES" << std::endl;

...
...
...

}

Running this code segment right after doing a ROSBAG recording with pipeline successfully closed still causes this error..

@armandok
Copy link

I am having the same issue. First, I tried to open a saved rosbag file, which is saved by a different application, and the poll_for_frames returns false and I cannot read anything from the file.
When I try to open the bag file after recording it (in the same application), I get the Bag unindexed error.

@HippoEug
Copy link
Author

HippoEug commented Jan 7, 2019

@armandok Yeap, I got to close the application after recording, then re-open again to open the recording. Have you found a workaround?

Glad I wasn't the only one experiencing this issue

@armandok
Copy link

armandok commented Jan 9, 2019

@HippoEug Unfortunately not.
I am trying to record a session, and then load it later and align and filter the recorded images, because doing the align and filtering altogether in real-time reduces the fps to almost half.
The weird thing is that I can open the rosbag file with Realsenseviewer but when I open it within my application the poll_for_frames returns false. I have no idea what to do.

@HippoEug
Copy link
Author

HippoEug commented Jan 9, 2019

I can open the rosbag file with Realsense Viewer and my own app IF I close out my app immediately after recording the rosbag file (using my app). If I attempt to open the file after rosbag recording is done without restarting my app, it will crash on my app, and Realsense Viewer would give the bag unindexed error.

What I have to do currently on my application:

  1. Open app
  2. Press ROSBAG record
  3. Close app and start app again
  4. Process that particular ROSBAG file

Seems like there is no way to skip step 3 at the moment

Hence I am still thinking there is something in the destructor that is causing this, just that I do not know what is.

@RealSenseCustomerSupport
Copy link
Collaborator


Hi HippoEug,

Wonder if there is any updates from you on this one?

Thanks!

@RealSenseCustomerSupport
Copy link
Collaborator


Hi HippoEug,

Any update from your side?

Thanks!

@realsens01
Copy link

If I'm not mistaken, this issue has the same underlying cause as our issue with the Python wrapper (i.e., the bag is not written and closed when the pipeline is stopped). That issue still exists for me, even though there are ways to work around it (see that thread).

@RealSenseCustomerSupport
Copy link
Collaborator


@realsens01 @HippoEug Bag unindexed is caused by recording being unexpectedly interrupted or not properly closed. Did you get the same issue using provided playback-record demo?

@realsens01
Copy link

Which playback-record demo? From the thread that I linked, or this thread? As discussed in this thread, it seems like an object destruction issue. If I understand correctly, something is holding the bag open past the point at which the person doing the coding expects it to be, so the index is not written. Is there a reason that the bag is not indexed when pipeline.stop() is called?

@RealSenseCustomerSupport
Copy link
Collaborator


@realsense01 Please find record-playback demo in https://github.com/IntelRealSense/librealsense/tree/master/examples/record-playback

@realsens01
Copy link

realsens01 commented Aug 29, 2019

Not really sure why this was closed. The issue remains and my question was not answered. dorodnic referred to this as an unresolved issue, and I continue to have problems with it. Maybe because the OP is not responding? I'll go ahead and create a new issue to refer to the same problem... again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants