checkpto.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00012 /*  This program is free software; you can redistribute it and/or
00013  *  modify it under the terms of the GNU General Public
00014  *  License as published by the Free Software Foundation; either
00015  *  version 2 of the License, or (at your option) any later version.
00016  *
00017  *  This software is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  *  General Public License for more details.
00021  *
00022  *  You should have received a copy of the GNU General Public
00023  *  License along with this software; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 #include <hugin_version.h>
00029 
00030 #include <fstream>
00031 #include <sstream>
00032 #ifdef WIN32
00033  #include <getopt.h>
00034 #else
00035  #include <unistd.h>
00036 #endif
00037 
00038 #include <panodata/Panorama.h>
00039 #include "algorithms/optimizer/ImageGraph.h"
00040 #include "hugin_base/panotools/PanoToolsUtils.h"
00041 #include "algorithms/basic/CalculateCPStatistics.h"
00042 
00043 using namespace std;
00044 using namespace HuginBase;
00045 using namespace AppBase;
00046 
00047 static void usage(const char * name)
00048 {
00049     cout << name << ": report the number of image groups in a project" << endl
00050          << name << " version " << DISPLAY_VERSION << endl
00051          << endl
00052          << "Usage:  " << name << " input.pto" << endl
00053          << endl
00054          << name << " examines the connections between images in a project and" << endl
00055          << "reports back the number of parts or image groups in that project" << endl
00056          << endl
00057          << name << " is used by the assistant makefile" << endl
00058          << endl;
00059 }
00060 
00061 int main(int argc, char *argv[])
00062 {
00063     // parse arguments
00064     const char * optstring = "h";
00065 
00066     int c;
00067     string output;
00068     while ((c = getopt (argc, argv, optstring)) != -1)
00069     {
00070         switch (c) {
00071         case 'h':
00072             usage(argv[0]);
00073             return 0;
00074         case '?':
00075             break;
00076         default:
00077             abort ();
00078         }
00079     }
00080 
00081     if (argc - optind != 1) 
00082     {
00083         usage(argv[0]);
00084         return -1;
00085     };
00086     
00087     string input=argv[optind];
00088 
00089     Panorama pano;
00090     ifstream prjfile(input.c_str());
00091     if (!prjfile.good()) {
00092         cerr << "could not open script : " << input << endl;
00093         return -1;
00094     }
00095     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00096     DocumentData::ReadWriteError err = pano.readData(prjfile);
00097     if (err != DocumentData::SUCCESSFUL) {
00098         cerr << "error while parsing panos tool script: " << input << endl;
00099         cerr << "DocumentData::ReadWriteError code: " << err << endl;
00100         return -1;
00101     }
00102 
00103     std::cout << endl 
00104               << "Opened project " << input << endl << endl
00105               << "Project contains" << endl
00106               << pano.getNrOfImages() << " images" << endl
00107               << pano.getNrOfCtrlPoints() << " control points" << endl << endl;
00108     //cp statistics
00109     if(pano.getNrOfCtrlPoints()>0)
00110     {
00111         double min;
00112         double max;
00113         double mean;
00114         double var;
00115         HuginBase::PTools::calcCtrlPointErrors(pano);
00116         CalculateCPStatisticsError::calcCtrlPntsErrorStats(pano, min, max, mean, var);
00117         if(max>0) 
00118         {
00119             std::cout << "Control points statistics" << std::endl
00120                 << fixed << std::setprecision(2)
00121                 << "\tMean error        : " << mean << std::endl
00122                 << "\tStandard deviation: " << sqrt(var) << std::endl
00123                 << "\tMinimum           : " << min << std::endl
00124                 << "\tMaximum           : " << max << std::endl;
00125         };
00126     };
00127     CPGraph graph;
00128     createCPGraph(pano, graph);
00129     CPComponents comps;
00130     int n = findCPComponents(graph, comps);
00131     if(n==1)
00132     {
00133         std::cout << "All images are connected." << endl;
00134         // return value must be 0, otherwise the assistant does not continue
00135         return 0;
00136     }
00137     else
00138     {
00139         std::cout << "Found unconnected images!" << endl 
00140                   << "There are " << n << " image groups." << endl;
00141 
00142         std::cout << "Image groups: " << endl;
00143         for (unsigned i=0; i < comps.size(); i++)
00144         {
00145             std::cout << "[";
00146             CPComponents::value_type::const_iterator it;
00147             size_t c=0;
00148             for (it = comps[i].begin(); it != comps[i].end(); ++it)
00149             {
00150                 std::cout << (*it);
00151                 if (c+1 != comps[i].size())
00152                 {
00153                     std::cout << ", ";
00154                 }
00155                 c++;
00156             }
00157             std::cout << "]";
00158             if (i+1 != comps.size())
00159             {
00160                 std::cout << ", " << endl;
00161             }
00162         }
00163         return n;
00164     };
00165 }

Generated on Wed Aug 20 01:25:40 2014 for Hugintrunk by  doxygen 1.3.9.1