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, see
00024  *  <http://www.gnu.org/licenses/>.
00025  *
00026  */
00027 
00028 #include <hugin_config.h>
00029 
00030 #include <fstream>
00031 #include <sstream>
00032 #include <getopt.h>
00033 
00034 #include <panodata/Panorama.h>
00035 #include "algorithms/optimizer/ImageGraph.h"
00036 #include "hugin_base/panotools/PanoToolsUtils.h"
00037 #include "hugin_base/panodata/StandardImageVariableGroups.h"
00038 #include "algorithms/basic/CalculateCPStatistics.h"
00039 #include "algorithms/basic/LayerStacks.h"
00040 
00041 using namespace std;
00042 using namespace HuginBase;
00043 using namespace AppBase;
00044 
00045 static void usage(const char* name)
00046 {
00047     cout << name << ": report the number of image groups in a project" << endl
00048          << name << " version " << hugin_utils::GetHuginVersion() << endl
00049          << endl
00050          << "Usage:  " << name << " input.pto" << endl
00051          << endl
00052          << name << " examines the connections between images in a project and" << endl
00053          << "reports back the number of parts or image groups in that project" << endl
00054          << endl
00055          << "Further switches:" << endl
00056          << "  --print-output-info     Print more information about the output" << endl
00057          << "  --print-lens-info       Print more information about lenses" << endl
00058          << "  --print-stack-info      Print more information about assigned stacks" << endl
00059          << "                          spaceholders will be replaced with real values" << endl
00060          << endl
00061          << name << " is used by the assistant and by the stitching makefiles" << endl
00062          << endl;
00063 }
00064 
00065 void printImageGroup(const std::vector<HuginBase::UIntSet>& imageGroup, const std::string& prefix=std::string())
00066 {
00067     for (size_t i=0; i < imageGroup.size(); i++)
00068     {
00069         if (!prefix.empty())
00070         {
00071             std::cout << prefix << " " << i << ": ";
00072         };
00073         std::cout << "[";
00074         size_t c=0;
00075         for (HuginBase::UIntSet::const_iterator it = imageGroup[i].begin(); it != imageGroup[i].end(); ++it)
00076         {
00077             std::cout << (*it);
00078             if (c+1 != imageGroup[i].size())
00079             {
00080                 std::cout << ", ";
00081             }
00082             ++c;
00083         }
00084         std::cout << "]";
00085         if (prefix.empty() && (i+1 != imageGroup.size()))
00086         {
00087             std::cout << ", ";
00088         }
00089         std::cout << std::endl;
00090     }
00091 };
00092 
00093 int main(int argc, char* argv[])
00094 {
00095     // parse arguments
00096     const char* optstring = "h";
00097     enum
00098     {
00099         PRINT_OUTPUT_INFO=1000,
00100         PRINT_LENS_INFO=1004,
00101         PRINT_STACK_INFO=1005,
00102     };
00103     static struct option longOptions[] =
00104     {
00105         { "print-output-info", no_argument, NULL, PRINT_OUTPUT_INFO },
00106         { "print-lens-info", no_argument, NULL, PRINT_LENS_INFO },
00107         { "print-stack-info", no_argument, NULL, PRINT_STACK_INFO },
00108         { "help", no_argument, NULL, 'h' },
00109         0
00110     };
00111 
00112     int c;
00113     bool printOutputInfo=false;
00114     bool printLensInfo = false;
00115     bool printStackInfo = false;
00116     int optionIndex = 0;
00117     while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1)
00118     {
00119         switch (c)
00120         {
00121             case 'h':
00122                 usage(hugin_utils::stripPath(argv[0]).c_str());
00123                 return 0;
00124             case PRINT_OUTPUT_INFO:
00125                 printOutputInfo=true;
00126                 break;
00127             case PRINT_LENS_INFO:
00128                 printLensInfo = true;
00129                 break;
00130             case PRINT_STACK_INFO:
00131                 printStackInfo = true;
00132                 break;
00133             case '?':
00134                 break;
00135             default:
00136                 abort ();
00137         }
00138     }
00139 
00140     if (argc - optind != 1)
00141     {
00142         usage(hugin_utils::stripPath(argv[0]).c_str());
00143         return -1;
00144     };
00145 
00146     string input=argv[optind];
00147 
00148     Panorama pano;
00149     ifstream prjfile(input.c_str());
00150     if (!prjfile.good())
00151     {
00152         cerr << "could not open script : " << input << endl;
00153         return -1;
00154     }
00155     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00156     DocumentData::ReadWriteError err = pano.readData(prjfile);
00157     if (err != DocumentData::SUCCESSFUL)
00158     {
00159         cerr << "error while parsing panos tool script: " << input << endl;
00160         cerr << "DocumentData::ReadWriteError code: " << err << endl;
00161         return -1;
00162     }
00163 
00164     HuginBase::ConstStandardImageVariableGroups variable_groups(pano);
00165     std::cout << endl
00166               << "Opened project " << input << endl << endl
00167               << "Project contains" << endl
00168               << pano.getNrOfImages() << " images" << endl
00169               << variable_groups.getLenses().getNumberOfParts() << " lenses" << endl
00170               << variable_groups.getStacks().getNumberOfParts() << " stacks" << endl
00171               << pano.getNrOfCtrlPoints() << " control points" << endl << endl;
00172     //cp statistics
00173     if(pano.getNrOfCtrlPoints()>0)
00174     {
00175         double min;
00176         double max;
00177         double mean;
00178         double var;
00179         HuginBase::PTools::calcCtrlPointErrors(pano);
00180         CalculateCPStatisticsError::calcCtrlPntsErrorStats(pano, min, max, mean, var);
00181         if(max>0)
00182         {
00183             std::cout << "Control points statistics" << std::endl
00184                       << fixed << std::setprecision(2)
00185                       << "\tMean error        : " << mean << std::endl
00186                       << "\tStandard deviation: " << sqrt(var) << std::endl
00187                       << "\tMinimum           : " << min << std::endl
00188                       << "\tMaximum           : " << max << std::endl;
00189         };
00190     };
00191     CPGraph graph;
00192     createCPGraph(pano, graph);
00193     CPComponents comps;
00194     const size_t n = findCPComponents(graph, comps);
00195     int returnValue=0;
00196     if(n==1)
00197     {
00198         std::cout << "All images are connected." << endl;
00199         // return value must be 0, otherwise the assistant does not continue
00200         returnValue=0;
00201     }
00202     else
00203     {
00204         std::cout << "Found unconnected images!" << endl
00205                   << "There are " << n << " image groups." << endl;
00206 
00207         std::cout << "Image groups: " << endl;
00208         for (size_t i=0; i < comps.size(); i++)
00209         {
00210             std::cout << "[";
00211             CPComponents::value_type::const_iterator it;
00212             size_t c=0;
00213             for (it = comps[i].begin(); it != comps[i].end(); ++it)
00214             {
00215                 std::cout << (*it);
00216                 if (c+1 != comps[i].size())
00217                 {
00218                     std::cout << ", ";
00219                 }
00220                 c++;
00221             }
00222             std::cout << "]";
00223             if (i+1 != comps.size())
00224             {
00225                 std::cout << ", " << endl;
00226             }
00227         }
00228         returnValue=n;
00229     };
00230     std::cout << std::endl;
00231     if (printLensInfo)
00232     {
00233         std::cout << std::endl << "Lenses:" << std::endl;
00234         printImageGroup(variable_groups.getLenses().getPartsSet(), "Lens");
00235     };
00236     if (printStackInfo)
00237     {
00238         std::cout << std::endl << "Stacks:" << std::endl;
00239         printImageGroup(variable_groups.getStacks().getPartsSet(), "Stack");
00240     };
00241     if (printOutputInfo)
00242     {
00243         HuginBase::UIntSet outputImages=HuginBase::getImagesinROI(pano, pano.getActiveImages());
00244         std::vector<HuginBase::UIntSet> stacks=HuginBase::getHDRStacks(pano, outputImages, pano.getOptions());
00245         cout << endl << "Output contains" << endl
00246              << stacks.size() << " images stacks:" << endl;
00247         printImageGroup(stacks);
00248         std::vector<HuginBase::UIntSet> layers=HuginBase::getExposureLayers(pano, outputImages, pano.getOptions());
00249         cout << endl << endl << "and " << layers.size() << " exposure layers:" << std::endl;
00250         printImageGroup(layers);
00251     };
00252     return returnValue;
00253 }

Generated on 31 Jul 2015 for Hugintrunk by  doxygen 1.4.7