forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rs-convert.cpp
156 lines (124 loc) · 4.88 KB
/
rs-convert.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2018 Intel Corporation. All Rights Reserved.
#include <iostream>
#include "librealsense2/rs.hpp"
#include "tclap/CmdLine.h"
#include "converters/converter-csv.hpp"
#include "converters/converter-png.hpp"
#include "converters/converter-raw.hpp"
#include "converters/converter-ply.hpp"
#include "converters/converter-bin.hpp"
using namespace std;
using namespace TCLAP;
int main(int argc, char** argv) try
{
rs2::log_to_file(RS2_LOG_SEVERITY_WARN);
// Parse command line arguments
CmdLine cmd("librealsense rs-convert tool", ' ');
ValueArg<string> inputFilename("i", "input", "ROS-bag filename", true, "", "ros-bag-file");
ValueArg<string> outputFilenamePng("p", "output-png", "output PNG file(s) path", false, "", "png-path");
ValueArg<string> outputFilenameCsv("v", "output-csv", "output CSV (depth matrix) file(s) path", false, "", "csv-path");
ValueArg<string> outputFilenameRaw("r", "output-raw", "output RAW file(s) path", false, "", "raw-path");
ValueArg<string> outputFilenamePly("l", "output-ply", "output PLY file(s) path", false, "", "ply-path");
ValueArg<string> outputFilenameBin("b", "output-bin", "output BIN (depth matrix) file(s) path", false, "", "bin-path");
SwitchArg switchDepth("d", "depth", "convert depth frames (default - all supported)", false);
SwitchArg switchColor("c", "color", "convert color frames (default - all supported)", false);
cmd.add(inputFilename);
cmd.add(outputFilenamePng);
cmd.add(outputFilenameCsv);
cmd.add(outputFilenameRaw);
cmd.add(outputFilenamePly);
cmd.add(outputFilenameBin);
cmd.add(switchDepth);
cmd.add(switchColor);
cmd.parse(argc, argv);
vector<shared_ptr<rs2::tools::converter::converter_base>> converters;
rs2_stream streamType = switchDepth.isSet() ? rs2_stream::RS2_STREAM_DEPTH
: switchColor.isSet() ? rs2_stream::RS2_STREAM_COLOR
: rs2_stream::RS2_STREAM_ANY;
if (outputFilenameCsv.isSet()) {
converters.push_back(
make_shared<rs2::tools::converter::converter_csv>(
outputFilenameCsv.getValue()
, streamType));
}
if (outputFilenamePng.isSet()) {
converters.push_back(
make_shared<rs2::tools::converter::converter_png>(
outputFilenamePng.getValue()
, streamType));
}
if (outputFilenameRaw.isSet()) {
converters.push_back(
make_shared<rs2::tools::converter::converter_raw>(
outputFilenameRaw.getValue()
, streamType));
}
if (outputFilenamePly.isSet()) {
converters.push_back(
make_shared<rs2::tools::converter::converter_ply>(
outputFilenamePly.getValue()));
}
if (outputFilenameBin.isSet()) {
converters.push_back(
make_shared<rs2::tools::converter::converter_bin>(
outputFilenameBin.getValue()));
}
if (converters.empty()) {
throw runtime_error("output not defined");
}
auto pipe = make_shared<rs2::pipeline>();
rs2::config cfg;
cfg.enable_device_from_file(inputFilename.getValue());
pipe->start(cfg);
auto device = pipe->get_active_profile().get_device();
rs2::playback playback = device.as<rs2::playback>();
playback.set_real_time(false);
auto duration = playback.get_duration();
int progress = 0;
auto frameNumber = 0ULL;
while (true) {
playback.resume();
auto frameset = pipe->wait_for_frames();
playback.pause();
int posP = static_cast<int>(playback.get_position() * 100. / duration.count());
if (posP > progress) {
progress = posP;
cout << posP << "%" << "\r" << flush;
}
if (frameset[0].get_frame_number() < frameNumber) {
break;
}
frameNumber = frameset[0].get_frame_number();
for_each(converters.begin(), converters.end(),
[&frameset] (shared_ptr<rs2::tools::converter::converter_base>& converter) {
converter->convert(frameset);
});
for_each(converters.begin(), converters.end(),
[] (shared_ptr<rs2::tools::converter::converter_base>& converter) {
converter->wait();
});
}
cout << endl;
for_each(converters.begin(), converters.end(),
[] (shared_ptr<rs2::tools::converter::converter_base>& converter) {
cout << converter->get_statistics() << endl;
});
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
cerr << "RealSense error calling " << e.get_failed_function()
<< "(" << e.get_failed_args() << "):\n " << e.what() << endl;
return EXIT_FAILURE;
}
catch (const exception & e)
{
cerr << e.what() << endl;
return EXIT_FAILURE;
}
catch (...)
{
cerr << "some error" << endl;
return EXIT_FAILURE;
}