31 #include "open3d/Open3D.h" 34 namespace tio = open3d::t::io;
41 "Open a RealSense camera and display live color and depth streams. You can set\n" 42 "frame sizes and frame rates for each stream and the depth stream can be\n" 43 "optionally aligned to the color stream. NOTE: An error of 'UNKNOWN: Couldn't\n" 44 "resolve requests' implies unsupported stream format settings.");
46 utility::LogInfo(
"Usage:");
48 "RealSenseRecorder [-h|--help] [-V] [-l|--list-devices] [--align]\n" 49 "[--record rgbd_video_file.bag] [-c|--config rs-config.json]");
52 int main(
int argc,
char **argv) {
54 if (utility::ProgramOptionExists(argc, argv,
"--help") ||
55 utility::ProgramOptionExists(argc, argv,
"-h")) {
59 if (utility::ProgramOptionExists(argc, argv,
"--list-devices") ||
60 utility::ProgramOptionExists(argc, argv,
"-l")) {
61 tio::RealSenseSensor::ListDevices();
64 if (utility::ProgramOptionExists(argc, argv,
"-V")) {
65 utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
67 utility::SetVerbosityLevel(utility::VerbosityLevel::Info);
69 bool align_streams =
false;
72 if (utility::ProgramOptionExists(argc, argv,
"-c")) {
73 config_file = utility::GetProgramOptionAsString(argc, argv,
"-c");
74 }
else if (utility::ProgramOptionExists(argc, argv,
"--config")) {
75 config_file = utility::GetProgramOptionAsString(argc, argv,
"--config");
77 utility::LogError(
"config json file required.");
81 if (utility::ProgramOptionExists(argc, argv,
"--align")) {
84 if (utility::ProgramOptionExists(argc, argv,
"--record")) {
85 bag_file = utility::GetProgramOptionAsString(argc, argv,
"--record");
89 tio::RealSenseSensorConfig rs_cfg;
90 open3d::io::ReadIJsonConvertible(config_file, rs_cfg);
93 tio::RealSenseSensor
rs;
95 rs.InitSensor(rs_cfg, 0, bag_file);
96 utility::LogInfo(
"{}", rs.GetMetadata().ToString());
99 bool flag_start =
false, flag_record = flag_start, flag_exit =
false;
100 visualization::VisualizerWithKeyCallback depth_vis, color_vis;
101 auto callback_exit = [&](visualization::Visualizer *vis) {
104 utility::LogInfo(
"Recording finished.");
106 utility::LogInfo(
"Nothing has been recorded.");
112 auto callback_toggle_record = [&](visualization::Visualizer *vis) {
117 "Press [SPACE] to continue. " 118 "Press [ESC] to save and exit.");
125 "Recording started. " 126 "Press [SPACE] to pause. " 127 "Press [ESC] to save and exit.");
131 "Recording resumed, video may be discontinuous. " 132 "Press [SPACE] to pause. " 133 "Press [ESC] to save and exit.");
138 if (!bag_file.empty()) {
139 depth_vis.RegisterKeyCallback(
GLFW_KEY_SPACE, callback_toggle_record);
140 color_vis.RegisterKeyCallback(
GLFW_KEY_SPACE, callback_toggle_record);
142 "In the visulizer window, " 143 "press [SPACE] to start recording, " 144 "press [ESC] to exit.");
146 utility::LogInfo(
"In the visulizer window, press [ESC] to exit.");
149 using legacyRGBDImage = open3d::geometry::RGBDImage;
151 std::shared_ptr<legacyImage> depth_image_ptr, color_image_ptr;
154 legacyRGBDImage im_rgbd;
155 bool is_geometry_added =
false;
157 rs.StartCapture(flag_start);
159 im_rgbd = rs.CaptureFrame(
true, align_streams).ToLegacyRGBDImage();
163 depth_image_ptr = std::shared_ptr<open3d::geometry::Image>(
165 color_image_ptr = std::shared_ptr<open3d::geometry::Image>(
168 if (!is_geometry_added) {
169 if (!depth_vis.CreateVisualizerWindow(
170 "Open3D || RealSense || Depth", depth_image_ptr->width_,
171 depth_image_ptr->height_, 15, 50) ||
172 !depth_vis.AddGeometry(depth_image_ptr) ||
173 !color_vis.CreateVisualizerWindow(
174 "Open3D || RealSense || Color", color_image_ptr->width_,
175 color_image_ptr->height_, 675, 50) ||
176 !color_vis.AddGeometry(color_image_ptr)) {
177 utility::LogError(
"Window creation failed!");
180 is_geometry_added =
true;
183 depth_vis.UpdateGeometry();
184 color_vis.UpdateGeometry();
185 depth_vis.PollEvents();
186 color_vis.PollEvents();
187 depth_vis.UpdateRender();
188 color_vis.UpdateRender();
190 if (frame_id++ % 30 == 0) {
191 utility::LogInfo(
"Time: {}s, Frame {}",
192 static_cast<double>(rs.GetTimestamp()) * 1
e-6,
195 }
while (!flag_exit);
::sensor_msgs::Image_< std::allocator< void > > Image
int main(int argc, char **argv)
GLsizei const GLchar *const * string