Skip to content

Commit

Permalink
Merge pull request #4 from Scoobadood/master
Browse files Browse the repository at this point in the history
Enable running in batch mode.
  • Loading branch information
MarianoJT88 authored Nov 16, 2016
2 parents 24cc5d1 + c1c4135 commit b28ff8a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
3 changes: 2 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Both apps can read command line arguments. By adding the argument "--help" you w

The coarsest level of the pyramid is always 15 x 20, so the total number of coarse-to-fine levels will depend on the parameter "rows". By default, rows = 240.


The images that "Scene-Flow-Impair" reads can be specified on the command line

--i1 <filename> : The file name of the first intensity image. Defaults to i1.png
Expand Down Expand Up @@ -72,6 +71,8 @@ Scene-Flow_Impair writes outputs to two files, a text version containing the ful
The results will be written to <root>_resultsNN.txt and root_representationNN.png
where NN is a two digit number.

--no-show : Supresses display of images so that the code can be run in batch mode. Output files are still generated


The algorithm convergence is set to a fixed number of iterations at each level of the coarse-to-fine scheme, and depends on the amount of levels and the level itself. If necessary, it can be changed by modifying the variable num_max_iter[].

Expand Down
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
35 changes: 24 additions & 11 deletions scene_flow_impair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,8 @@ void PD_flow_opencv::freeGPUMemory()

void PD_flow_opencv::initializeCUDA()
{
char name[100];

//Read one image to know the image resolution
sprintf(name, "i1.png");
intensity1 = cv::imread(name, CV_LOAD_IMAGE_GRAYSCALE);
intensity1 = cv::imread(intensity_filename_1, CV_LOAD_IMAGE_GRAYSCALE);

width = intensity1.cols;
height = intensity1.rows;
Expand Down Expand Up @@ -281,7 +278,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 +306,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 +348,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 b28ff8a

Please sign in to comment.