Skip to content

Commit

Permalink
feature: Extended command line arg parsing
Browse files Browse the repository at this point in the history
Command line argumnets now support filenames for intensity and depth files
Defaults are left unchanged from the original code and so all existing code
and scripts should continue to work unchanged.
  • Loading branch information
Scoobadood committed Nov 5, 2016
1 parent 9b3950a commit 3f84e0a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 11 deletions.
102 changes: 91 additions & 11 deletions main_scene_flow_impair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,89 @@
using namespace std;


/**
* Parse arguments from the command line. Valid arguments are:
* --help (in which case other args are ignored)
* --rows r
* --i1 <filename> The first RGB image file name. Defaults to i1.png
* --i2 <filename> The second RGB image file name
* --z1 <filename> The first depth image file name
* --z2 <filename> The second depth image file name
* @param num_arg Number of arguments present
* @param argv Array of pointers to arguments
* @param args A launch_args structure which is populated by this method.
* @return true if arguments were successfully parsed, otherwise false
*/
bool parse_arguments( int num_arg, char *argv[], Launch_args& args) {
// Initialise with defaults
args.show_help = 0;
args.rows = 240;
args.intensity_filename_1 = "i1.png";
args.intensity_filename_2 = "i2.png";
args.depth_filename_1 = "z1.png";
args.depth_filename_1 = "z2.png";
args.output_filename_root = "out";

// Now check what's provided
bool parsed_ok = true;
int arg_idx = 1;
while( parsed_ok && ( arg_idx < num_arg ) ){
if( strcmp( "--help", argv[arg_idx]) == 0 ) {
// Stop parsing after seeing help
args.show_help = 1;
break;

} else if ( strcmp( "--rows", argv[arg_idx]) == 0 ) {
int rows = -1;
if( ++arg_idx < num_arg ) {
rows = stoi( argv[arg_idx]);
}
if( rows == 15 || rows == 30 || rows == 60 || rows == 120 || rows == 240 || rows == 480 ) {
args.rows = rows;
} else {
parsed_ok = false;
}
} else if ( strcmp( "--i1", argv[arg_idx]) == 0 ) {
if( ++arg_idx < num_arg ) {
args.intensity_filename_1 = argv[arg_idx];
} else {
parsed_ok = false;
}
} else if ( strcmp( "--i2", argv[arg_idx]) == 0 ) {
if( ++arg_idx < num_arg ) {
args.intensity_filename_2 = argv[arg_idx];
} else {
parsed_ok = false;
}
} else if ( strcmp( "--z1", argv[arg_idx]) == 0 ) {
if( ++arg_idx < num_arg ) {
args.depth_filename_1 = argv[arg_idx];
} else {
parsed_ok = false;
}
} else if ( strcmp( "--z2", argv[arg_idx]) == 0 ) {
if( ++arg_idx < num_arg ) {
args.depth_filename_2 = argv[arg_idx];
} else {
parsed_ok = false;
}
} else if ( strcmp( "--out", argv[arg_idx]) == 0 ) {
if( ++arg_idx < num_arg ) {
args.output_filename_root = argv[arg_idx];
} else {
parsed_ok = false;
}
} else {
parsed_ok = false;
break;
}

arg_idx++;
}

return parsed_ok;
}

// ------------------------------------------------------
// MAIN
// ------------------------------------------------------
Expand All @@ -35,30 +118,27 @@ int main(int num_arg, char *argv[])
//==============================================================================
// Read arguments
//==============================================================================
unsigned int rows = 240; //Default value

if (num_arg <= 1); //No arguments
else if ( string(argv[1]) == "--help")
{
Launch_args args;
if( !parse_arguments( num_arg, argv, args ) || args.show_help ) {
printf("\n\t Arguments of the function 'main' \n");
printf("==============================================================\n\n");
printf(" --help: Shows this menu... \n\n");
printf(" --rows r: Number of rows at the finest level of the pyramid. \n");
printf("\t Options: r=15, r=30, r=60, r=120, r=240, r=480 (if VGA)\n");
printf(" --i1 <filename> The first RGB image file name. Defaults to i1.png\n" );
printf(" --i2 <filename> The second RGB image file name. Defaults to i2.png\n" );
printf(" --z1 <filename> The first depth image file name. Defaults to z1.png\n" );
printf(" --z2 <filename> The second depth image file name. Defaults to z2.png\n" );
printf(" --out <filename> The output file name root. Omit file extension. Defaults to \n" );
getwchar();
return 1;
}
else
{
if ( string(argv[1]) == "--rows")
rows = stoi(argv[2]);
}

//==============================================================================
// Main operations
//==============================================================================

PD_flow_opencv sceneflow(rows);
PD_flow_opencv sceneflow(args.rows, args.intensity_filename_1, args.intensity_filename_2, args.depth_filename_1, args.depth_filename_2, args.output_filename_root);

//Initialize CUDA and set some internal variables
sceneflow.initializeCUDA();
Expand Down
13 changes: 13 additions & 0 deletions scene_flow_impair.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@



//==================================================================
// Arguments for running the algorithm - parsed from command line
//==================================================================
struct Launch_args {
unsigned int rows;
unsigned int show_help;
const char *intensity_filename_1;
const char *intensity_filename_2;
const char *depth_filename_1;
const char *depth_filename_2;
const char *output_filename_root;
};

//==================================================================
// PD-Flow class (using openCV)
//==================================================================
Expand Down

0 comments on commit 3f84e0a

Please sign in to comment.