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

Generated on 29 May 2016 for Hugintrunk by  doxygen 1.4.7