main.cpp
Go to the documentation of this file.
00001 
00025 #include <string>
00026 #include <iostream>
00027 #include <algorithm>
00028 #include <opencv/highgui.h>
00029 #include "tclap/CmdLine.h"
00030 #include "mapstitch/mapstitch.h"
00031 
00032 using namespace TCLAP;
00033 using namespace std;
00034 using namespace cv;
00035 
00036 int main(int argc, char** argv)
00037 {
00038   bool verbose = false;
00039   string outfile = "";
00040   vector<string> infiles;
00041   float max_distance = 5.;
00042 
00043   try {
00044   CmdLine cmd(
00045       "Aligns multiple scan maps and combines into a single image. "
00046       "All images given on the command line will be aligned to the first "
00047       "supplied image and their respective rotation/translation and "
00048       "transformation matrix will be returned.",
00049       ' ', "0.1");
00050 
00051   ValueArg<float> maxDistanceOpt("d","maximum-distance", "maximum distance on matched points pairs for inclusion", false,
00052                   5., "max-distance", cmd);
00053   SwitchArg verboseOpt("v","verbose","verbose output", cmd, false);
00054   ValueArg<string> outputFOpt("o","outfile","output filename", false,
00055                   "", "string",cmd);
00056   UnlabeledMultiArg<string> multi("fileName", "input file names (first one is pivot element)", false, "file1 and file2", cmd);
00057 
00058   cmd.parse( argc, argv );
00059 
00060   // Get the value parsed by each arg.
00061   verbose = verboseOpt.getValue();
00062   infiles = multi.getValue();
00063   outfile = outputFOpt.getValue();
00064   max_distance = maxDistanceOpt.getValue();
00065 
00066   } catch (ArgException &e)  // catch any exceptions
00067   { cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
00068     exit(-1);
00069   }
00070 
00071   // now let's do the real work
00072   if (infiles.size() != 2) {
00073     cerr << "error: need exactly two input files" << endl;
00074     exit(-1);
00075   }
00076 
00077   // load the images
00078   vector<Mat> images;
00079   for (size_t i=0; i<infiles.size(); i++) {
00080     Mat image = imread(infiles[i].c_str(), 0); // 0=grayscale
00081     if (!image.data) {
00082       cerr << "error: image " << infiles[i] << " not loadable." << endl;
00083       exit(-1);
00084     }
00085     images.push_back(image);
00086   }
00087 
00088   // create the stitched map
00089   StitchedMap map(images[0],images[1], max_distance);
00090 
00091   // write to outfile if applicable
00092   if (outfile.size() != 0) {
00093     imwrite(outfile, map.get_stitch());
00094   }
00095 
00096   if (outfile.size() == 0 || verbose) { // generate some output
00097     cout << "rotation: "          << map.rotation << endl
00098          << "translation (x,y): " << map.transx << ", " << map.transy << endl
00099          << "matrix: "            << map.H << endl;
00100   }
00101 
00102   if (verbose) {
00103     namedWindow("wrap"); imshow("wrap", map.get_stitch()); imwrite("stitch.pgm", map.get_stitch());
00104     namedWindow("debug"); imshow("debug", map.get_debug()); imwrite("debug.pgm", map.get_debug());
00105 
00106     while ((waitKey(0)&255) != 10) // RETURN
00107       ;
00108   }
00109 
00110   return 0;
00111 }


mapstitch
Author(s): Philipp M. Scholl
autogenerated on Mon Oct 6 2014 02:09:53