Skip to content

Commit f174142

Browse files
committedJan 25, 2025
Add --source option to allow v4l2 or replayer source
Signed-off-by: Wendell Hom <whom@nvidia.com>
1 parent 5441d20 commit f174142

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed
 

‎applications/stereo_vision/cpp/main.cpp

+37-22
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ class StereoDepthApp;
4141

4242
class StereoDepthApp : public holoscan::Application {
4343
private:
44+
std::string source_;
4445
std::string stereo_calibration_;
4546

4647
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) {}
4850
void compose() override {
4951
using namespace holoscan;
5052
YAML::Node calibration = YAML::LoadFile(stereo_calibration_);
@@ -57,6 +59,8 @@ class StereoDepthApp : public holoscan::Application {
5759
int width = calibration["width"].as<int>();
5860
int height = calibration["height"].as<int>();
5961

62+
63+
std::cout << "*********** SOURCE *************" << source_ << std::endl;
6064
auto source = make_operator<ops::V4L2VideoCaptureOp>(
6165
"source",
6266
from_config("source"),
@@ -194,19 +198,29 @@ void print_usage() {
194198
std::cout << "Usage: program [--config <config-file>] [--stereo <stereo-calibration-file>]\n";
195199
}
196200

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) {
198203
int option_index = 0;
199204
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'},
201207
{0, 0, 0, 0}};
202208

203209
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) {
205211
switch (c) {
206212
case 'c':
207213
config_file = optarg;
208214
break;
209215
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':
210224
stereo_file = optarg;
211225
break;
212226
case '?':
@@ -220,33 +234,34 @@ void parse_arguments(int argc, char* argv[], char*& config_file, char*& stereo_f
220234
}
221235

222236
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()) {
231242
auto input_path = std::getenv("HOLOSCAN_INPUT_PATH");
232243

233244
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";
235246
} 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();
239250
}
240251
}
241-
if (config_file) {
242-
config_file_string = config_file;
243-
} else {
252+
253+
if (config_file.empty()) {
244254
auto default_path = std::filesystem::canonical(argv[0]).parent_path();
245255
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";
247261
}
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);
250265
app->run();
251266
return 0;
252267
}

0 commit comments

Comments
 (0)