34 #include "open3d/Open3D.h" 41 utility::LogInfo(
"Usage:");
43 utility::LogInfo(
"RealSenseBagReader [-V] --input input.bag [--output path]");
47 int main(
int argc,
char **argv) {
48 if (!utility::ProgramOptionExists(argc, argv,
"--input")) {
52 if (utility::ProgramOptionExists(argc, argv,
"-V")) {
53 utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
55 utility::SetVerbosityLevel(utility::VerbosityLevel::Info);
58 utility::GetProgramOptionAsString(argc, argv,
"--input");
60 bool write_image =
false;
62 if (!utility::ProgramOptionExists(argc, argv,
"--output")) {
63 utility::LogInfo(
"No output image path, only play bag.");
65 output_path = utility::GetProgramOptionAsString(argc, argv,
"--output");
66 if (output_path.empty()) {
67 utility::LogError(
"Output path {} is empty, only play bag.", output_path);
70 if (utility::filesystem::DirectoryExists(output_path)) {
71 utility::LogWarning(
"Output path {} already existing, only play bag.",
74 }
else if (!utility::filesystem::MakeDirectory(output_path)) {
75 utility::LogWarning(
"Unable to create path {}, only play bag.",
79 utility::LogInfo(
"Decompress images to {}", output_path);
80 utility::filesystem::MakeDirectoryHierarchy(output_path +
"/color");
81 utility::filesystem::MakeDirectoryHierarchy(output_path +
"/depth");
86 t::io::RSBagReader bag_reader;
87 bag_reader.Open(bag_filename);
88 if (!bag_reader.IsOpened()) {
89 utility::LogError(
"Unable to open {}", bag_filename);
93 bool flag_exit =
false;
94 bool flag_play =
true;
95 visualization::VisualizerWithKeyCallback vis;
96 visualization::SetGlobalColorMap(
97 visualization::ColorMap::ColorMapOption::Gray);
98 vis.RegisterKeyCallback(
GLFW_KEY_ESCAPE, [&](visualization::Visualizer *vis) {
102 vis.RegisterKeyCallback(
GLFW_KEY_SPACE, [&](visualization::Visualizer *vis) {
104 utility::LogInfo(
"Playback paused, press [SPACE] to continue");
106 utility::LogInfo(
"Playback resumed, press [SPACE] to pause");
108 flag_play = !flag_play;
111 vis.RegisterKeyCallback(
GLFW_KEY_LEFT, [&](visualization::Visualizer *vis) {
113 if (bag_reader.SeekTimestamp(now < 1
'000'000 ? 0 : now - 1
'000'000))
114 utility::LogInfo(
"Seek back 1s");
116 utility::LogWarning(
"Seek back 1s failed");
119 vis.RegisterKeyCallback(
GLFW_KEY_RIGHT, [&](visualization::Visualizer *vis) {
121 if (bag_reader.SeekTimestamp(now + 1
'000'000))
122 utility::LogInfo(
"Seek forward 1s");
124 utility::LogWarning(
"Seek forward 1s failed");
128 vis.CreateVisualizerWindow(
"Open3D Intel RealSense bag player", 1920, 540);
129 utility::LogInfo(
"Starting to play. Press [SPACE] to pause. Press [ESC] to " 132 bool is_geometry_added =
false;
134 const auto bag_metadata = bag_reader.GetMetadata();
135 utility::LogInfo(
"Recorded with device {}", bag_metadata.device_name_);
136 utility::LogInfo(
" Serial number: {}", bag_metadata.serial_number_);
137 utility::LogInfo(
"Video resolution: {}x{}", bag_metadata.width_,
138 bag_metadata.height_);
139 utility::LogInfo(
" frame rate: {}", bag_metadata.fps_);
140 utility::LogInfo(
" duration: {:.6f}s",
141 static_cast<double>(bag_metadata.stream_length_usec_) *
143 utility::LogInfo(
" color pixel format: {}", bag_metadata.color_format_);
144 utility::LogInfo(
" depth pixel format: {}", bag_metadata.depth_format_);
147 io::WriteIJsonConvertibleToJSON(
148 fmt::format(
"{}/intrinsic.json", output_path), bag_metadata);
150 const auto frame_interval = sc::duration<double>(1. / bag_metadata.fps_);
153 using legacyRGBDImage = open3d::geometry::RGBDImage;
154 legacyRGBDImage im_rgbd;
155 while (!bag_reader.IsEOF() && !flag_exit) {
157 std::this_thread::sleep_until(last_frame_time + frame_interval);
159 im_rgbd = bag_reader.NextFrame().ToLegacyRGBDImage();
162 std::shared_ptr<legacyRGBDImage>(&im_rgbd, [](legacyRGBDImage *) {});
165 if (ptr_im_rgbd->IsEmpty())
168 if (!is_geometry_added) {
169 vis.AddGeometry(ptr_im_rgbd);
170 is_geometry_added =
true;
175 #pragma omp parallel sections 180 fmt::format(
"{0}/color/{1:05d}.jpg", output_path, idx);
181 utility::LogInfo(
"Writing to {}", color_file);
182 io::WriteImage(color_file, im_rgbd.color_);
187 fmt::format(
"{0}/depth/{1:05d}.png", output_path, idx);
188 utility::LogInfo(
"Writing to {}", depth_file);
189 io::WriteImage(depth_file, im_rgbd.depth_);
192 vis.UpdateGeometry();
int main(int argc, char **argv)
GLsizei const GLchar *const * string
GLint GLint GLsizei GLint GLenum format
unsigned __int64 uint64_t