rs-record.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include <librealsense2/rs.hpp>
5 #include <iostream>
6 #include <iomanip>
7 #include <thread>
8 #include <mutex>
9 #include <stdio.h>
10 #include <memory>
11 #include <functional>
12 #include <thread>
13 #include <string.h>
14 #include <chrono>
15 #include "tclap/CmdLine.h"
16 
17 using namespace TCLAP;
18 
19 int main(int argc, char * argv[]) try
20 {
21  // Parse command line arguments
22  CmdLine cmd("librealsense rs-record example tool", ' ');
23  ValueArg<int> time("t", "Time", "Amount of time to record (in seconds)", false, 10, "");
24  ValueArg<std::string> out_file("f", "FullFilePath", "the file where the data will be saved to", false, "test.bag", "");
25 
26  cmd.add(time);
27  cmd.add(out_file);
28  cmd.parse(argc, argv);
29 
32  cfg.enable_record_to_file(out_file.getValue());
33 
34  std::mutex m;
35  auto callback = [&](const rs2::frame& frame)
36  {
37  std::lock_guard<std::mutex> lock(m);
39  static auto tk = t;
40  static auto t0 = t;
41  if (t - tk >= std::chrono::seconds(1)) {
42  std::cout << "\r" << std::setprecision(3) << std::fixed
43  << "Recording t = " << std::chrono::duration_cast<std::chrono::seconds>(t-t0).count() << "s" << std::flush;
44  tk = t;
45  }
46  };
47 
49 
51  auto t0 = t;
52  while(t - t0 <= std::chrono::seconds(time.getValue())) {
53  std::this_thread::sleep_for(std::chrono::milliseconds(10));
55  }
56  std::cout << "\nFinished" << std::endl;
57 
58  pipe.stop();
59 
60  return EXIT_SUCCESS;
61 }
62 catch (const rs2::error & e)
63 {
64  std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
65  return EXIT_FAILURE;
66 }
67 catch (const std::exception& e)
68 {
69  std::cerr << e.what() << std::endl;
70  return EXIT_FAILURE;
71 }
static const textual_icon lock
Definition: model-views.h:218
const GLfloat * m
Definition: glext.h:6814
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition: glext.h:9721
int main(int argc, char *argv[])
Definition: rs-record.cpp:19
e
Definition: rmse.py:177
GLdouble t
const std::string & get_failed_args() const
Definition: rs_types.hpp:117
std::ostream & cout()
def callback(frame)
Definition: t265_stereo.py:91
T & getValue()
Definition: ValueArg.h:322
void parse(int argc, const char *const *argv)
Definition: CmdLine.h:433
void enable_record_to_file(const std::string &file_name)
GLint GLsizei count
std::ostream & cerr()
void add(Arg &a)
Definition: CmdLine.h:413
Definition: Arg.h:57
pipeline_profile start()
const std::string & get_failed_function() const
Definition: rs_types.hpp:112


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40