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,nullptr)) != -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             case ':':
00131                 // missing argument or invalid switch
00132                 return 1;
00133                 break;
00134             default:
00135                 // this should not happen
00136                 abort ();
00137         }
00138     }
00139 
00140     if (argc - optind != 1)
00141     {
00142         if (argc - optind < 1)
00143         {
00144             std::cerr << hugin_utils::stripPath(argv[0]) << ": No project file given." << std::endl;
00145         }
00146         else
00147         {
00148             std::cerr << hugin_utils::stripPath(argv[0]) << ": Only one project file expected." << std::endl;
00149         };
00150         return -1;
00151     }
00152 
00153 
00154     std::string input=argv[optind];
00155 
00156     HuginBase::Panorama pano;
00157     std::ifstream prjfile(input.c_str());
00158     if (!prjfile.good())
00159     {
00160         std::cerr << "could not open script : " << input << std::endl;
00161         return -1;
00162     }
00163     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00164     AppBase::DocumentData::ReadWriteError err = pano.readData(prjfile);
00165     if (err != AppBase::DocumentData::SUCCESSFUL)
00166     {
00167         std::cerr << "error while parsing panos tool script: " << input << std::endl
00168             << "DocumentData::ReadWriteError code: " << err << std::endl;
00169         return -1;
00170     }
00171 
00172     HuginBase::ConstStandardImageVariableGroups variable_groups(pano);
00173     std::cout << std::endl
00174               << "Opened project " << input << std::endl << std::endl
00175               << "Project contains" << std::endl
00176               << pano.getNrOfImages() << " images" << std::endl
00177               << variable_groups.getLenses().getNumberOfParts() << " lenses" << std::endl
00178               << variable_groups.getStacks().getNumberOfParts() << " stacks" << std::endl
00179               << pano.getNrOfCtrlPoints() << " control points" << std::endl << std::endl;
00180     //cp statistics
00181     if(pano.getNrOfCtrlPoints()>0)
00182     {
00183         double min;
00184         double max;
00185         double mean;
00186         double var;
00187         HuginBase::PTools::calcCtrlPointErrors(pano);
00188         HuginBase::CalculateCPStatisticsError::calcCtrlPntsErrorStats(pano, min, max, mean, var);
00189         if(max>0)
00190         {
00191             std::cout << "Control points statistics" << std::endl
00192                       << std::fixed << std::setprecision(2)
00193                       << "\tMean error        : " << mean << std::endl
00194                       << "\tStandard deviation: " << sqrt(var) << std::endl
00195                       << "\tMinimum           : " << min << std::endl
00196                       << "\tMaximum           : " << max << std::endl;
00197         };
00198     };
00199     HuginGraph::ImageGraph graph(pano);
00200     const HuginGraph::ImageGraph::Components comps = graph.GetComponents();
00201     int returnValue=0;
00202     if(comps.size()==1)
00203     {
00204         std::cout << "All images are connected." << std::endl;
00205         // return value must be 0, otherwise the assistant does not continue
00206         returnValue=0;
00207     }
00208     else
00209     {
00210         std::cout << "Found unconnected images!" << std::endl
00211                   << "There are " << comps.size() << " image groups." << std::endl;
00212 
00213         std::cout << "Image groups: " << std::endl;
00214         for (size_t i=0; i < comps.size(); i++)
00215         {
00216             std::cout << "[";
00217             HuginGraph::ImageGraph::Components::value_type::const_iterator it;
00218             size_t c=0;
00219             for (it = comps[i].begin(); it != comps[i].end(); ++it)
00220             {
00221                 std::cout << (*it);
00222                 if (c+1 != comps[i].size())
00223                 {
00224                     std::cout << ", ";
00225                 }
00226                 c++;
00227             }
00228             std::cout << "]";
00229             if (i+1 != comps.size())
00230             {
00231                 std::cout << ", " << std::endl;
00232             }
00233         }
00234         returnValue=comps.size();
00235     };
00236     std::cout << std::endl;
00237     if (printLensInfo)
00238     {
00239         std::cout << std::endl << "Lenses:" << std::endl;
00240         printImageGroup(variable_groups.getLenses().getPartsSet(), "Lens");
00241     };
00242     if (printStackInfo)
00243     {
00244         std::cout << std::endl << "Stacks:" << std::endl;
00245         printImageGroup(variable_groups.getStacks().getPartsSet(), "Stack");
00246     };
00247     if (printOutputInfo)
00248     {
00249         HuginBase::UIntSet outputImages=HuginBase::getImagesinROI(pano, pano.getActiveImages());
00250         std::vector<HuginBase::UIntSet> stacks=HuginBase::getHDRStacks(pano, outputImages, pano.getOptions());
00251         std::cout << std::endl << "Output contains" << std::endl
00252              << stacks.size() << " images stacks:" << std::endl;
00253         printImageGroup(stacks);
00254         std::vector<HuginBase::UIntSet> layers=HuginBase::getExposureLayers(pano, outputImages, pano.getOptions());
00255         std::cout << std::endl << std::endl << "and " << layers.size() << " exposure layers:" << std::endl;
00256         printImageGroup(layers);
00257     };
00258     return returnValue;
00259 }

Generated on 10 Dec 2016 for Hugintrunk by  doxygen 1.4.7