Skip to content

Commit

Permalink
feature: Add commnd line support for not displaying results
Browse files Browse the repository at this point in the history
This allows the UI to be effectively disabled so that the code can
be run in a headless fashion from a script.

The --no-show command line parameter will prevent images from being displayed
  • Loading branch information
Scoobadood committed Nov 8, 2016
1 parent 92dd5f0 commit e07ccb1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
27 changes: 20 additions & 7 deletions main_scene_flow_impair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct Launch_args {
const char *depth_filename_1;
const char *depth_filename_2;
const char *output_filename_root;
bool no_show;
};

/**
Expand All @@ -63,6 +64,7 @@ bool parse_arguments( int num_arg, char *argv[], Launch_args& args) {
args.depth_filename_1 = "z1.png";
args.depth_filename_2 = "z2.png";
args.output_filename_root = "pdflow";
args.no_show = false;

// Now check what's provided
bool parsed_ok = true;
Expand Down Expand Up @@ -113,6 +115,8 @@ bool parse_arguments( int num_arg, char *argv[], Launch_args& args) {
} else {
parsed_ok = false;
}
} else if ( strcmp( "--no-show", argv[arg_idx]) == 0 ) {
args.no_show = true;
} else {
parsed_ok = false;
break;
Expand Down Expand Up @@ -140,11 +144,12 @@ int main(int num_arg, char *argv[])
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 pdflow\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 pdflow\n" );
printf(" --no-show : Don't show the output results. Useful for batch processing\n");
getwchar();
return 1;
}
Expand All @@ -167,9 +172,17 @@ int main(int num_arg, char *argv[])

if (imloaded == 1)
{
sceneflow.showImages();
if( args.no_show == false )
{
sceneflow.showImages();
}
sceneflow.solveSceneFlowGPU();
sceneflow.showAndSaveResults();
if( args.no_show ) {
cv::Mat image = sceneflow.createImage( );
sceneflow.saveResults( image );
} else {
sceneflow.showAndSaveResults();
}
sceneflow.freeGPUMemory();
printf("\nPush any key over the scene flow image to finish\n");
}
Expand Down
30 changes: 23 additions & 7 deletions scene_flow_impair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ bool PD_flow_opencv::loadRGBDFrames()
return 1;
}

void PD_flow_opencv::showAndSaveResults( )
// Create the image
cv::Mat PD_flow_opencv::createImage() const
{
//Save scene flow as an RGB image (one colour per direction)
cv::Mat sf_image(rows, cols, CV_8UC3);
Expand All @@ -308,13 +309,14 @@ void PD_flow_opencv::showAndSaveResults( )
sf_image.at<cv::Vec3b>(v,u)[2] = static_cast<unsigned char>(255.f*fabs(dzp[v + u*rows])/maxmodz); //Red - z
}

//Show the scene flow as an RGB image
cv::namedWindow("SceneFlow", cv::WINDOW_NORMAL);
cv::moveWindow("SceneFlow",width - cols/2,height - rows/2);
cv::imshow("SceneFlow", sf_image);
cv::waitKey(100000);

return sf_image;
}

/**
* Save results without displaying them
*/
void PD_flow_opencv::saveResults( const cv::Mat& sf_image ) const
{
//Save the scene flow as a text file
char name[500];
int nFichero = 0;
Expand Down Expand Up @@ -349,3 +351,17 @@ void PD_flow_opencv::showAndSaveResults( )
printf("Saving the visual representation to file: %s \n", name);
cv::imwrite(name, sf_image);
}


void PD_flow_opencv::showAndSaveResults( )
{
cv::Mat sf_image = createImage( );

//Show the scene flow as an RGB image
cv::namedWindow("SceneFlow", cv::WINDOW_NORMAL);
cv::moveWindow("SceneFlow",width - cols/2,height - rows/2);
cv::imshow("SceneFlow", sf_image);
cv::waitKey(100000);

saveResults( sf_image );
}
2 changes: 2 additions & 0 deletions scene_flow_impair.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class PD_flow_opencv {
void freeGPUMemory();
void initializeCUDA();
void showImages();
cv::Mat createImage() const;
void saveResults( const cv::Mat& image) const;
void showAndSaveResults();

PD_flow_opencv( unsigned int rows_config,
Expand Down

0 comments on commit e07ccb1

Please sign in to comment.