18 #define SECONDS_TO_NANOSECONDS 1000000000 21 using namespace TCLAP;
24 int main(
int argc,
char** argv)
try 26 #ifdef BUILD_EASYLOGGINGPP 31 CmdLine cmd(
"librealsense rs-convert tool",
' ');
32 ValueArg<string> inputFilename(
"i",
"input",
"ROS-bag filename",
true,
"",
"ros-bag-file");
33 ValueArg<string> outputFilenamePng(
"p",
"output-png",
"output PNG file(s) path",
false,
"",
"png-path");
34 ValueArg<string> outputFilenameCsv(
"v",
"output-csv",
"output CSV (depth matrix) file(s) path",
false,
"",
"csv-path");
35 ValueArg<string> outputFilenameRaw(
"r",
"output-raw",
"output RAW file(s) path",
false,
"",
"raw-path");
36 ValueArg<string> outputFilenamePly(
"l",
"output-ply",
"output PLY file(s) path",
false,
"",
"ply-path");
37 ValueArg<string> outputFilenameBin(
"b",
"output-bin",
"output BIN (depth matrix) file(s) path",
false,
"",
"bin-path");
38 SwitchArg switchDepth(
"d",
"depth",
"convert depth frames (default - all supported)",
false);
39 SwitchArg switchColor(
"c",
"color",
"convert color frames (default - all supported)",
false);
40 ValueArg <string> frameNumberStart(
"f",
"first-framenumber",
"ignore frames whose frame number is less than this value",
false,
"",
"first-framenumber");
41 ValueArg <string> frameNumberEnd(
"t",
"last-framenumber",
"ignore frames whose frame number is greater than this value",
false,
"",
"last-framenumber");
42 ValueArg <string> startTime(
"s",
"start-time",
"ignore frames whose timestamp is less than this value (the first frame is at time 0)",
false,
"",
"start-time");
43 ValueArg <string> endTime(
"e",
"end-time",
"ignore frames whose timestamp is greater than this value (the first frame is at time 0)",
false,
"",
"end-time");
46 cmd.
add(inputFilename);
47 cmd.
add(frameNumberEnd);
48 cmd.
add(frameNumberStart);
51 cmd.
add(outputFilenamePng);
52 cmd.
add(outputFilenameCsv);
53 cmd.
add(outputFilenameRaw);
54 cmd.
add(outputFilenamePly);
55 cmd.
add(outputFilenameBin);
58 cmd.
parse(argc, argv);
60 vector<shared_ptr<rs2::tools::converter::converter_base>> converters;
61 shared_ptr<rs2::tools::converter::converter_ply> plyconverter;
67 if (outputFilenameCsv.
isSet())
70 make_shared<rs2::tools::converter::converter_csv>(
75 if (outputFilenamePng.
isSet())
78 make_shared<rs2::tools::converter::converter_png>(
83 if (outputFilenameRaw.
isSet())
86 make_shared<rs2::tools::converter::converter_raw>(
91 if (outputFilenameBin.
isSet())
94 make_shared<rs2::tools::converter::converter_bin>(
98 if (converters.empty() && !outputFilenamePly.
isSet())
100 throw runtime_error(
"output not defined");
103 unsigned long long first_frame = 0;
104 unsigned long long last_frame = 0;
108 if (frameNumberStart.
isSet())
112 if (frameNumberEnd.
isSet())
116 if (startTime.
isSet())
127 if (outputFilenamePly.
isSet()) {
132 auto pipe = std::shared_ptr<rs2::pipeline>(
135 plyconverter = make_shared<rs2::tools::converter::converter_ply>(
139 cfg.enable_device_from_file(inputFilename.
getValue());
142 auto device =
pipe->get_active_profile().get_device();
148 auto frameNumber = 0ULL;
155 while (
pipe->try_wait_for_frames(&frameset, 1000))
157 int posP =
static_cast<int>(posCurr * 100. / duration.count());
161 cout << posP <<
"%" <<
"\r" << flush;
166 bool process_frame =
true;
167 if (frameNumberStart.
isSet() && frameNumber < first_frame)
168 process_frame =
false;
169 else if (frameNumberEnd.
isSet() && frameNumber > last_frame)
170 process_frame =
false;
171 else if (startTime.
isSet() && posCurr < start_time)
172 process_frame =
false;
173 else if (endTime.
isSet() && posCurr > end_time)
174 process_frame =
false;
178 plyconverter->convert(frameset);
179 plyconverter->wait();
185 if (posNext < posCurr)
195 if( ! converters.empty() )
199 playback.set_real_time(
false);
200 std::vector<rs2::sensor> sensors = playback.query_sensors();
203 auto duration = playback.get_duration();
205 uint64_t posCurr = playback.get_position();
207 for (
auto sensor : sensors)
209 if (!
sensor.get_stream_profiles().size())
217 std::lock_guard<std::mutex>
lock(mutex);
221 if (frameNumberStart.
isSet() && frameNumber < first_frame)
223 if (frameNumberEnd.
isSet() && frameNumber > last_frame)
225 if (startTime.
isSet() && posCurr < start_time)
227 if (endTime.
isSet() && posCurr > end_time)
230 for_each(converters.begin(), converters.end(),
231 [&frame](shared_ptr<rs2::tools::converter::converter_base>& converter) {
232 converter->convert(frame);
235 for_each(converters.begin(), converters.end(),
236 [](shared_ptr<rs2::tools::converter::converter_base>& converter) {
249 int posP =
static_cast<int>(posCurr * 100. / duration.count());
254 cout << posP <<
"%" <<
"\r" << flush;
257 const uint64_t posNext = playback.get_position();
258 if (posNext < posCurr)
264 for (
auto sensor : sensors)
266 if (!
sensor.get_stream_profiles().size())
278 if (outputFilenamePly.
isSet()) {
279 cout << plyconverter->get_statistics() << endl;
282 for_each(converters.begin(), converters.end(),
283 [](shared_ptr<rs2::tools::converter::converter_base>& converter) {
284 cout << converter->get_statistics() << endl;
297 catch (
const exception & e)
299 cerr << e.what() << endl;
304 cerr <<
"some error" << endl;
static const textual_icon lock
playback load_device(const std::string &file)
#define SECONDS_TO_NANOSECONDS
const std::string & get_failed_args() const
unsigned __int64 uint64_t
void log_to_file(rs2_log_severity min_severity, const char *file_path=nullptr)
uint64_t get_position() const
rs2_stream
Streams are different types of data provided by RealSense devices.
void parse(int argc, const char *const *argv)
int main(int argc, char **argv)
std::chrono::nanoseconds get_duration() const
void set_real_time(bool real_time) const
int stoi(const std::string &value)
unsigned long long get_frame_number() const
const std::string & get_failed_function() const