18 using namespace TCLAP;
22 data_collector::data_collector(std::shared_ptr<rs2::device>
dev,
34 if (!config_file.
isSet())
36 <<
"The tool requires a profile configuration file to proceed" 37 <<
"\nRun rs-data-collect --help for details");
40 ifstream file(config_filename);
43 throw runtime_error(
stringify() <<
"Given .csv configure file " << config_filename <<
" was not found!");
53 while (getline(file, line))
57 if (std::regex_search(line, starts_with))
73 throw runtime_error(
stringify() <<
"Invalid configuration file - multiple requests for the same sensor:\n" 78 throw std::runtime_error(
stringify() <<
"Invalid configuration file - " << config_filename <<
" zero requests accepted");
94 std::cout <<
"\nThe following request(s) are not supported by the device: " << std::endl;
103 throw runtime_error(
stringify() <<
"No data collected, aborting");
106 std::vector<uint64_t> frames_per_stream;
108 frames_per_stream.emplace_back(kv.second.size());
110 std::sort(frames_per_stream.begin(), frames_per_stream.end());
111 std::cout <<
"\nData collection accomplished with [" 112 << frames_per_stream.front() <<
"-" << frames_per_stream.back()
113 <<
"] frames recorded per stream\nSerializing captured results to " 114 << out_filename << std::endl;
117 ofstream csv(out_filename);
119 throw runtime_error(
stringify() <<
"Cannot open the requested output file " << out_filename <<
", please check permissions");
121 csv <<
"Configuration:\nStream Type,Stream Name,Format,FPS,Width,Height\n";
125 for (
const auto& elem : data_collection)
127 csv <<
"\n\nStream Type,Index,F#,HW Timestamp (ms),Host Timestamp(ms)" 128 << (
val_in_range(elem.first.first, { RS2_STREAM_GYRO,RS2_STREAM_ACCEL }) ?
",3DOF_x,3DOF_y,3DOF_z" :
"")
129 << (
val_in_range(elem.first.first, { RS2_STREAM_POSE }) ?
",t_x,t_y,t_z,r_x,r_y,r_z,r_w" :
"")
132 for (
auto i = 0;
i < elem.second.size();
i++)
133 csv << elem.second[
i].to_string();
154 auto axes = motion.get_motion_data();
160 auto pose = pf.get_pose_data();
161 rec._params = {
pose.translation.x,
pose.translation.y,
pose.translation.z,
171 bool timed_out =
false;
181 bool collected_enough_frames =
true;
188 collected_enough_frames =
false;
193 return !(timed_out || collected_enough_frames);
217 std::cout <<
"Request added for " << line << std::endl;
221 std::cout <<
"Invalid syntax in configuration line " << line << std::endl;
230 bool succeed =
false;
232 std::vector<rs2::stream_profile>
matches;
247 if ((
profile.stream_type() == req._stream_type) &&
249 (
profile.stream_index() == req._stream_idx) &&
254 if ((vp.width() != req._width) || (vp.height() != req._height))
284 int main(
int argc,
char** argv)
try 287 #ifdef BUILD_EASYLOGGINGPP 292 CmdLine cmd(
"librealsense rs-data-collect example tool",
' ');
293 ValueArg<int> timeout(
"t",
"Timeout",
"Max amount of time to receive frames (in seconds)",
false, 10,
"");
294 ValueArg<int> max_frames(
"m",
"MaxFrames_Number",
"Maximum number of frames-per-stream to receive",
false, 100,
"");
295 ValueArg<string> out_file(
"f",
"FullFilePath",
"the file where the data will be saved to",
false,
"",
"");
296 ValueArg<string> config_file(
"c",
"ConfigurationFile",
"Specify file path with the requested configuration",
false,
"",
"");
301 cmd.
add(config_file);
302 cmd.
parse(argc, argv);
304 std::cout <<
"Running rs-data-collect: ";
305 for (
auto i=1;
i < argc; ++
i)
312 ofstream csv(output_file);
314 throw runtime_error(
stringify() <<
"Cannot open the requested output file " << output_file <<
", please check permissions");
317 bool succeed =
false;
327 std::cout <<
"Connect Realsense Camera to proceed" << std::endl;
328 std::this_thread::sleep_for(std::chrono::seconds(3));
332 auto dev = std::make_shared<rs2::device>(list.
front());
336 dc.parse_and_configure(config_file);
342 for (
auto&&
sensor : dc.selected_sensors())
345 dc.collect_frame_attributes(f,start_time);
348 std::cout <<
"\nData collection started.... \n" << std::endl;
350 while (dc.collecting(start_time))
352 std::this_thread::sleep_for(std::chrono::seconds(1));
355 <<
" sec" << std::endl;
359 for (
auto&&
sensor : dc.selected_sensors())
365 dc.save_data_to_file(output_file);
370 std::cout <<
"Task completed" << std::endl;
379 catch (
const exception & e)
381 cerr << e.what() << endl;
int parse_number(char const *s, int base=0)
application_stop _stop_cond
void save_data_to_file(const string &out_filename)
std::vector< std::string > tokenize(std::string line, char separator)
std::string to_lower(const std::string &s)
def axes(out, pos, rotation=np.eye(3), size=0.075, thickness=2)
std::vector< rs2::sensor > active_sensors
void collect_frame_attributes(rs2::frame f, std::chrono::time_point< std::chrono::high_resolution_clock > start_time)
stream_profile get_profile() const
device_list query_devices() const
void parse_and_configure(ValueArg< string > &config_file)
bool collecting(std::chrono::time_point< std::chrono::high_resolution_clock > start_time)
GLsizei const GLchar *const * string
std::string get_profile_description(const rs2::stream_profile &profile)
std::string stringify(const T &e)
void sort(sort_type m_sort_type, const std::string &in, const std::string &out)
::realsense_legacy_msgs::pose_< std::allocator< void > > pose
const std::string & get_failed_args() const
rs2_stream parse_stream_type(const string str)
double get_timestamp() const
std::vector< rs2::stream_profile > selected_stream_profiles
std::map< std::pair< rs2_stream, int >, std::vector< frame_record > > data_collection
GLint GLsizei GLsizei height
int parse_fps(const string str)
GLint GLint GLsizei GLint GLenum format
rs2_format
A stream's format identifies how binary data is encoded within a frame.
void log_to_file(rs2_log_severity min_severity, const char *file_path=nullptr)
rs2_format parse_format(const string str)
rs2_stream
Streams are different types of data provided by RealSense devices.
bool parse_configuration(const std::string &line, const std::vector< std::string > &tokens, rs2_stream &type, int &width, int &height, rs2_format &format, int &fps, int &index)
int main(int argc, char **argv)
void parse(int argc, const char *const *argv)
GLbitfield GLuint64 timeout
rs2_timestamp_domain get_frame_timestamp_domain() const
const std::string DEF_OUTPUT_FILE_NAME("frames_data.csv")
bool val_in_range(const T &val, const std::initializer_list< T > &list)
std::shared_ptr< rs2::device > _dev
bool starts_with(const std::string &s, const std::string &prefix)
std::vector< stream_request > user_requests
const uint64_t DEF_FRAMES_NUMBER
unsigned long long get_frame_number() const
std::vector< stream_request > requests_to_go
rs2_stream stream_type() const
const std::string & get_failed_function() const
void copy(void *dst, void const *src, size_t size)