@@ -41,10 +41,12 @@ class StereoDepthApp;
41
41
42
42
class StereoDepthApp : public holoscan ::Application {
43
43
private:
44
+ std::string source_;
44
45
std::string stereo_calibration_;
45
46
46
47
public:
47
- explicit StereoDepthApp (std::string file) : stereo_calibration_(file) {}
48
+ explicit StereoDepthApp (std::string source, std::string file) :
49
+ source_(source), stereo_calibration_(file) {}
48
50
void compose () override {
49
51
using namespace holoscan ;
50
52
YAML::Node calibration = YAML::LoadFile (stereo_calibration_);
@@ -57,6 +59,8 @@ class StereoDepthApp : public holoscan::Application {
57
59
int width = calibration[" width" ].as <int >();
58
60
int height = calibration[" height" ].as <int >();
59
61
62
+
63
+ std::cout << " *********** SOURCE *************" << source_ << std::endl;
60
64
auto source = make_operator<ops::V4L2VideoCaptureOp>(
61
65
" source" ,
62
66
from_config (" source" ),
@@ -194,19 +198,29 @@ void print_usage() {
194
198
std::cout << " Usage: program [--config <config-file>] [--stereo <stereo-calibration-file>]\n " ;
195
199
}
196
200
197
- void parse_arguments (int argc, char * argv[], char *& config_file, char *& stereo_file) {
201
+ void parse_arguments (int argc, char * argv[], std::string& config_file,
202
+ std::string& source, std::string& stereo_file) {
198
203
int option_index = 0 ;
199
204
static struct option long_options[] = {{" config" , required_argument, 0 , ' c' },
200
- {" stereo-calibration" , required_argument, 0 , ' s' },
205
+ {" source" , required_argument, 0 , ' s' },
206
+ {" stereo-calibration" , required_argument, 0 , ' t' },
201
207
{0 , 0 , 0 , 0 }};
202
208
203
209
int c;
204
- while ((c = getopt_long (argc, argv, " c:s:" , long_options, &option_index)) != -1 ) {
210
+ while ((c = getopt_long (argc, argv, " c:s:t: " , long_options, &option_index)) != -1 ) {
205
211
switch (c) {
206
212
case ' c' :
207
213
config_file = optarg ;
208
214
break ;
209
215
case ' s' :
216
+ if (strcmp (optarg , " replayer" ) != 0 && strcmp (optarg , " v4l2" ) != 0 ) {
217
+ std::cerr << " Error: Invalid value for --source. Allowed values: {replayer, v4l2}.\n " ;
218
+ print_usage ();
219
+ exit (1 );
220
+ }
221
+ source = optarg ;
222
+ break ;
223
+ case ' t' :
210
224
stereo_file = optarg ;
211
225
break ;
212
226
case ' ?' :
@@ -220,33 +234,34 @@ void parse_arguments(int argc, char* argv[], char*& config_file, char*& stereo_f
220
234
}
221
235
222
236
int main (int argc, char ** argv) {
223
- char * config_file = nullptr ;
224
- char * stereo_cal = nullptr ;
225
- std::string stereo_cal_string;
226
- std::string config_file_string;
227
- parse_arguments (argc, argv, config_file, stereo_cal);
228
- if (stereo_cal) {
229
- stereo_cal_string = stereo_cal;
230
- } else {
237
+ std::string config_file, source, stereo_cal;
238
+
239
+ parse_arguments (argc, argv, config_file, source, stereo_cal);
240
+
241
+ if (stereo_cal.empty ()) {
231
242
auto input_path = std::getenv (" HOLOSCAN_INPUT_PATH" );
232
243
233
244
if (input_path != nullptr && input_path[0 ] != ' \0 ' ) {
234
- stereo_cal_string = std::string (input_path) + " /stereo_vision/stereo_calibration.yaml" ;
245
+ stereo_cal = std::string (input_path) + " /stereo_vision/stereo_calibration.yaml" ;
235
246
} else {
236
- auto default_path = std::filesystem::canonical (argv[0 ]).parent_path ();
237
- default_path /= std::filesystem::path (" stereo_calibration.yaml" );
238
- stereo_cal_string = default_path.string ();
247
+ auto default_path = std::filesystem::canonical (argv[0 ]).parent_path ();
248
+ default_path /= std::filesystem::path (" stereo_calibration.yaml" );
249
+ stereo_cal = default_path.string ();
239
250
}
240
251
}
241
- if (config_file) {
242
- config_file_string = config_file;
243
- } else {
252
+
253
+ if (config_file.empty ()) {
244
254
auto default_path = std::filesystem::canonical (argv[0 ]).parent_path ();
245
255
default_path /= std::filesystem::path (" stereo_vision.yaml" );
246
- config_file_string = default_path.string ();
256
+ config_file = default_path.string ();
257
+ }
258
+
259
+ if (source.empty ()) {
260
+ source = " replayer" ;
247
261
}
248
- auto app = holoscan::make_application<StereoDepthApp>(stereo_cal_string);
249
- app->config (config_file_string);
262
+
263
+ auto app = holoscan::make_application<StereoDepthApp>(source, stereo_cal);
264
+ app->config (config_file);
250
265
app->run ();
251
266
return 0 ;
252
267
}
0 commit comments