pano_modify.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00013 /*  This program is free software; you can redistribute it and/or
00014  *  modify it under the terms of the GNU General Public
00015  *  License as published by the Free Software Foundation; either
00016  *  version 2 of the License, or (at your option) any later version.
00017  *
00018  *  This software is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  *  General Public License for more details.
00022  *
00023  *  You should have received a copy of the GNU General Public
00024  *  License along with this software. If not, see
00025  *  <http://www.gnu.org/licenses/>.
00026  *
00027  */
00028 
00029 #include <fstream>
00030 #include <sstream>
00031 #include <cmath>
00032 #include <getopt.h>
00033 #include <panodata/Panorama.h>
00034 #include <algorithms/nona/CenterHorizontally.h>
00035 #include <algorithms/basic/StraightenPanorama.h>
00036 #include <algorithms/basic/RotatePanorama.h>
00037 #include <algorithms/basic/TranslatePanorama.h>
00038 #include <algorithms/nona/FitPanorama.h>
00039 #include <algorithms/basic/CalculateOptimalScale.h>
00040 #include <algorithms/basic/CalculateOptimalROI.h>
00041 #include <algorithms/basic/LayerStacks.h>
00042 #include <algorithms/basic/CalculateMeanExposure.h>
00043 #include "hugin_utils/utils.h"
00044 
00045 static void usage(const char* name)
00046 {
00047     std::cout << name << ": change output parameters of project file" << std::endl
00048          << "pano_modify version " << hugin_utils::GetHuginVersion() << std::endl
00049          << std::endl
00050          << "Usage:  " << name << " [options] input.pto" << std::endl
00051          << std::endl
00052          << "  Options:" << std::endl
00053          << "    -o, --output=file.pto  Output Hugin PTO file. Default: <filename>_mod.pto" << std::endl
00054          << "    -p, --projection=x     Sets the output projection to number x" << std::endl
00055          << "    --fov=AUTO|HFOV|HFOVxVFOV   Sets field of view" << std::endl
00056          << "                                AUTO: calculates optimal fov" << std::endl
00057          << "                                HFOV|HFOVxVFOV: set to given fov" << std::endl
00058          << "    -s, --straighten       Straightens the panorama" << std::endl
00059          << "    -c, --center           Centers the panorama" << std::endl
00060          << "    --canvas=AUTO|num%|WIDTHxHEIGHT  Sets the output canvas size" << std::endl
00061          << "                                AUTO: calculate optimal canvas size" << std::endl
00062          << "                                num%: scales the optimal size by given percent" << std::endl
00063          << "                                WIDTHxHEIGHT: set to given size" << std::endl
00064          << "    --crop=AUTO|AUTOHDR|left,right,top,bottom  Sets the crop rectangle" << std::endl
00065          << "                                AUTO: autocrop panorama" << std::endl
00066          << "                                AUTOHDR: autocrop HDR panorama" << std::endl
00067          << "                                left,right,top,bottom: to given size" << std::endl
00068          << "    --output-exposure=AUTO|num  Sets the output exposure value to mean" << std::endl
00069          << "                                exposure (AUTO) or to given value" << std::endl
00070          << "    --output-cropped-tiff    Output cropped tiffs as intermediate images" << std::endl
00071          << "    --output-uncropped-tiff  Output uncropped tiffs as intermediate images" << std::endl
00072          << "    --output-type=str       Sets the type of output" << std::endl
00073          << "                              Valid items are" << std::endl
00074          << "                                NORMAL|N: normal panorama" << std::endl
00075          << "                                STACKSFUSEDBLENDED|BF: LDR panorama with" << std::endl
00076          << "                                    blended stacks" << std::endl
00077          << "                                EXPOSURELAYERSFUSED|FB: LDR panorama with" << std::endl
00078          << "                                    fused exposure layers (any arrangement)" << std::endl
00079          << "                                HDR: HDR panorama" << std::endl
00080          << "                                REMAP: remapped images with corrected exposure" << std::endl
00081          << "                                REMAPORIG: remapped images with" << std::endl
00082          << "                                    uncorrected exposure" << std::endl
00083          << "                                HDRREMAP: remapped images in linear color space" << std::endl
00084          << "                                FUSEDSTACKS: exposure fused stacks" << std::endl
00085          << "                                HDRSTACKS: HDR stacks" << std::endl
00086          << "                                EXPOSURELAYERS: blended exposure layers" << std::endl
00087          << "                              and separated by a comma." << std::endl
00088          << "    --ldr-file=JPG|TIF|PNG  Sets the filetype for LDR panorama output" << std::endl
00089          << "    --ldr-compression=str   Sets the compression for LDR panorama output" << std::endl
00090          << "                              For TIF: NONE|PACKBITS|LZW|DEFLATE" << std::endl
00091          << "                              For JPEG: quality as number" << std::endl
00092          << "    --hdr-file=EXR|TIF      Sets the filetype for HDR panorama output" << std::endl
00093          << "    --hdr-compression=str   Sets the compression for HDR panorama output" << std::endl
00094          << "                              For TIF: NONE|PACKBITS|LZW|DEFLATE" << std::endl
00095          << "    --blender=ENBLEND|INTERNAL  Sets the blender to be used at stitching" << std::endl
00096          << "                            stage." << std::endl
00097          << "    --rotate=yaw,pitch,roll Rotates the whole panorama with the given angles" << std::endl
00098          << "    --translate=x,y,z       Translate the whole panorama with the given values" << std::endl
00099          << "    -h, --help             Shows this help" << std::endl
00100          << std::endl;
00101 }
00102 
00103 int main(int argc, char* argv[])
00104 {
00105     // parse arguments
00106     const char* optstring = "o:p:sch";
00107 
00108     enum
00109     {
00110         SWITCH_FOV=1000,
00111         SWITCH_CANVAS,
00112         SWITCH_CROP,
00113         SWITCH_ROTATE,
00114         SWITCH_TRANSLATE,
00115         SWITCH_EXPOSURE,
00116         SWITCH_OUTPUT_TYPE,
00117         SWITCH_BLENDER,
00118         SWITCH_LDRFILETYPE,
00119         SWITCH_LDRCOMPRESSION,
00120         SWITCH_HDRFILETYPE,
00121         SWITCH_HDRCOMPRESSION,
00122         SWITCH_CROPPED_TIFF,
00123         SWITCH_UNCROPPED_TIFF
00124     };
00125     static struct option longOptions[] =
00126     {
00127         {"output", required_argument, NULL, 'o' },
00128         {"projection", required_argument, NULL, 'p' },
00129         {"fov", required_argument, NULL, SWITCH_FOV },
00130         {"straighten", no_argument, NULL, 's' },
00131         {"center", no_argument, NULL, 'c' },
00132         {"canvas", required_argument, NULL, SWITCH_CANVAS },
00133         {"crop", required_argument, NULL, SWITCH_CROP },
00134         {"output-cropped-tiff", no_argument, NULL, SWITCH_CROPPED_TIFF },
00135         {"output-uncropped-tiff", no_argument, NULL, SWITCH_UNCROPPED_TIFF },
00136         {"output-exposure", required_argument, NULL, SWITCH_EXPOSURE },
00137         {"output-type", required_argument, NULL, SWITCH_OUTPUT_TYPE },
00138         {"blender", required_argument, NULL, SWITCH_BLENDER },
00139         {"ldr-file", required_argument,NULL, SWITCH_LDRFILETYPE },
00140         {"ldr-compression", required_argument, NULL, SWITCH_LDRCOMPRESSION },
00141         {"hdr-file", required_argument, NULL, SWITCH_HDRFILETYPE },
00142         {"hdr-compression", required_argument, NULL, SWITCH_HDRCOMPRESSION },
00143         {"rotate", required_argument, NULL, SWITCH_ROTATE },
00144         {"translate", required_argument, NULL, SWITCH_TRANSLATE },
00145         {"help", no_argument, NULL, 'h' },
00146         0
00147     };
00148 
00149     int projection=-1;
00150     double newHFOV=-1;
00151     double newVFOV=-1;
00152     int scale=100;
00153     int newWidth=-1;
00154     int newHeight=-1;
00155     int outputCroppedTiff=-1;
00156     vigra::Rect2D newROI(0,0,0,0);
00157     bool doFit=false;
00158     bool doStraighten=false;
00159     bool doCenter=false;
00160     bool doOptimalSize=false;
00161     bool doAutocrop=false;
00162     bool autocropHDR=false;
00163     int c;
00164     double yaw = 0;
00165     double pitch = 0;
00166     double roll = 0;
00167     double x = 0;
00168     double y = 0;
00169     double z = 0;
00170     double outputExposure = -1000;
00171     bool calcMeanExposure = false;
00172     std::string outputType;
00173     std::string ldrfiletype;
00174     std::string ldrcompression;
00175     std::string hdrfiletype;
00176     std::string hdrcompression;
00177     std::string output;
00178     std::string param;
00179     std::string blender;
00180     while ((c = getopt_long (argc, argv, optstring, longOptions,nullptr)) != -1)
00181     {
00182         switch (c)
00183         {
00184             case 'o':
00185                 output = optarg;
00186                 break;
00187             case 'h':
00188                 usage(hugin_utils::stripPath(argv[0]).c_str());
00189                 return 0;
00190             case 'p':
00191                 //projection
00192                 projection=atoi(optarg);
00193                 if((projection==0) && (strcmp(optarg,"0")!=0))
00194                 {
00195                     std::cerr << hugin_utils::stripPath(argv[0]) << ": Could not parse projection number." << std::endl;
00196                     return 1;
00197                 };
00198                 if(projection>=panoProjectionFormatCount())
00199                 {
00200                     std::cerr << hugin_utils::stripPath(argv[0]) << ": projection " << projection << " is an invalid projection number." << std::endl;
00201                     return 1;
00202                 };
00203                 break;
00204             case SWITCH_FOV:
00205                 //field of view
00206                 param=optarg;
00207                 param=hugin_utils::toupper(param);
00208                 if(param=="AUTO")
00209                 {
00210                     doFit=true;
00211                 }
00212                 else
00213                 {
00214                     double hfov, vfov;
00215                     int n=sscanf(optarg, "%lfx%lf", &hfov, &vfov);
00216                     if(n==1)
00217                     {
00218                         if(hfov>0)
00219                         {
00220                             newHFOV=hfov;
00221                         }
00222                         else
00223                         {
00224                             std::cerr << hugin_utils::stripPath(argv[0]) << ": Invalid field of view" << std::endl;
00225                             return 1;
00226                         };
00227                     }
00228                     else
00229                     {
00230                         if (n==2)
00231                         {
00232                             if(hfov>0 && vfov>0)
00233                             {
00234                                 newHFOV=hfov;
00235                                 newVFOV=vfov;
00236                             }
00237                             else
00238                             {
00239                                 std::cerr << hugin_utils::stripPath(argv[0]) << ": Invalid field of view" << std::endl;
00240                                 return 1;
00241                             };
00242                         }
00243                         else
00244                         {
00245                             std::cerr << hugin_utils::stripPath(argv[0]) << ": Could not parse field of view" << std::endl;
00246                             return 1;
00247                         };
00248                     };
00249                 };
00250                 break;
00251             case 's':
00252                 doStraighten=true;
00253                 break;
00254             case 'c':
00255                 doCenter=true;
00256                 break;
00257             case SWITCH_CANVAS:
00258                 //canvas size
00259                 param=optarg;
00260                 param=hugin_utils::toupper(param);
00261                 if(param=="AUTO")
00262                 {
00263                     doOptimalSize=true;
00264                 }
00265                 else
00266                 {
00267                     int pos=param.find("%");
00268                     if(pos!=std::string::npos)
00269                     {
00270                         param=param.substr(0,pos);
00271                         scale=atoi(param.c_str());
00272                         if(scale==0)
00273                         {
00274                             std::cerr << hugin_utils::stripPath(argv[0]) << ": No valid scale factor given." << std::endl;
00275                             return 1;
00276                         };
00277                         doOptimalSize=true;
00278                     }
00279                     else
00280                     {
00281                         int width, height;
00282                         int n=sscanf(optarg, "%dx%d", &width, &height);
00283                         if (n==2)
00284                         {
00285                             if(width>0 && height>0)
00286                             {
00287                                 newWidth=width;
00288                                 newHeight=height;
00289                             }
00290                             else
00291                             {
00292                                 std::cerr << hugin_utils::stripPath(argv[0]) << ": Invalid canvas size" << std::endl;
00293                                 return 1;
00294                             };
00295                         }
00296                         else
00297                         {
00298                             std::cerr << hugin_utils::stripPath(argv[0]) << ": Could not parse canvas size" << std::endl;
00299                             return 1;
00300                         };
00301                     };
00302                 };
00303                 break;
00304             case SWITCH_CROP:
00305                 //crop
00306                 param=optarg;
00307                 param=hugin_utils::toupper(param);
00308                 if(param=="AUTO" || param=="AUTOHDR")
00309                 {
00310                     doAutocrop=true;
00311                     if(param=="AUTOHDR")
00312                     {
00313                         autocropHDR=true;
00314                     };
00315                 }
00316                 else
00317                 {
00318                     int left, right, top, bottom;
00319                     int n=sscanf(optarg, "%d,%d,%d,%d", &left, &right, &top, &bottom);
00320                     if (n==4)
00321                     {
00322                         if(right>left && bottom>top && left>=0 && top>=0)
00323                         {
00324                             newROI.setUpperLeft(vigra::Point2D(left,top));
00325                             newROI.setLowerRight(vigra::Point2D(right,bottom));
00326                         }
00327                         else
00328                         {
00329                             std::cerr << hugin_utils::stripPath(argv[0]) << ": Invalid crop area" << std::endl;
00330                             return 1;
00331                         };
00332                     }
00333                     else
00334                     {
00335                         std::cerr << hugin_utils::stripPath(argv[0]) << ": Could not parse crop values" << std::endl;
00336                         return 1;
00337                     };
00338                 };
00339                 break;
00340             case SWITCH_CROPPED_TIFF:
00341                 outputCroppedTiff = 1;
00342                 break;
00343             case SWITCH_UNCROPPED_TIFF:
00344                 outputCroppedTiff = 0;
00345                 break;
00346             case SWITCH_EXPOSURE:
00347                 param = optarg;
00348                 param = hugin_utils::toupper(param);
00349                 if (param == "AUTO")
00350                 {
00351                     calcMeanExposure = true;
00352                 }
00353                 else
00354                 {
00355                     int n = sscanf(optarg, "%lf", &outputExposure);
00356                     if (n != 1)
00357                     {
00358                         std::cerr << hugin_utils::stripPath(argv[0]) << ": Could not parse output exposure value." << std::endl;
00359                         return 1;
00360                     };
00361                 };
00362                 break;
00363             case SWITCH_OUTPUT_TYPE:
00364                 if (!outputType.empty())
00365                 {
00366                     outputType.append(",");
00367                 };
00368                 outputType.append(optarg);
00369                 break;
00370             case SWITCH_BLENDER:
00371                 blender = hugin_utils::tolower(hugin_utils::StrTrim(optarg));
00372                 break;
00373             case SWITCH_LDRFILETYPE:
00374                 ldrfiletype = hugin_utils::tolower(hugin_utils::StrTrim(optarg));
00375                 break;
00376             case SWITCH_LDRCOMPRESSION:
00377                 ldrcompression = hugin_utils::toupper(hugin_utils::StrTrim(optarg));
00378                 break;
00379             case SWITCH_HDRFILETYPE:
00380                 hdrfiletype = hugin_utils::tolower(hugin_utils::StrTrim(optarg));
00381                 break;
00382             case SWITCH_HDRCOMPRESSION:
00383                 hdrcompression = hugin_utils::toupper(hugin_utils::StrTrim(optarg));
00384                 break;
00385             case SWITCH_ROTATE:
00386                 {
00387                     int n=sscanf(optarg, "%lf,%lf,%lf", &yaw, &pitch, &roll);
00388                     if(n!=3)
00389                     {
00390                         std::cerr << hugin_utils::stripPath(argv[0]) << ": Could not parse rotate angles values. Given: \"" << optarg << "\"" << std::endl;
00391                         return 1;
00392                     };
00393                 };
00394                 break;
00395             case SWITCH_TRANSLATE:
00396                 {
00397                     int n=sscanf(optarg, "%lf,%lf,%lf", &x, &y, &z);
00398                     if(n!=3)
00399                     {
00400                         std::cerr << hugin_utils::stripPath(argv[0]) << ": Could not parse translation values. Given: \"" << optarg << "\"" << std::endl;
00401                         return 1;
00402                     };
00403                 };
00404                 break;
00405             case ':':
00406             case '?':
00407                 // missing argument or invalid switch
00408                 return 1;
00409                 break;
00410             default:
00411                 // this should not happen
00412                 abort();
00413 
00414         }
00415     }
00416 
00417     if (argc - optind != 1)
00418     {
00419         if (argc - optind < 1)
00420         {
00421             std::cerr << hugin_utils::stripPath(argv[0]) << ": No project file given." << std::endl;
00422         }
00423         else
00424         {
00425             std::cerr << hugin_utils::stripPath(argv[0]) << ": Only one project file expected." << std::endl;
00426         };
00427         return 1;
00428     };
00429 
00430     // set some options which depends on each other
00431     if(doStraighten)
00432     {
00433         doCenter=false;
00434         doFit=true;
00435     };
00436     if(doCenter)
00437     {
00438         doFit=true;
00439     };
00440 
00441     std::string input=argv[optind];
00442     // read panorama
00443     HuginBase::Panorama pano;
00444     std::ifstream prjfile(input.c_str());
00445     if (!prjfile.good())
00446     {
00447         std::cerr << "could not open script : " << input << std::endl;
00448         return 1;
00449     }
00450     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00451     AppBase::DocumentData::ReadWriteError err = pano.readData(prjfile);
00452     if (err != AppBase::DocumentData::SUCCESSFUL)
00453     {
00454         std::cerr << "error while parsing panos tool script: " << input << std::endl;
00455         std::cerr << "DocumentData::ReadWriteError code: " << err << std::endl;
00456         return 1;
00457     }
00458 
00459     // sets the projection
00460     if(projection!=-1)
00461     {
00462         HuginBase::PanoramaOptions opt = pano.getOptions();
00463         opt.setProjection((HuginBase::PanoramaOptions::ProjectionFormat)projection);
00464         pano_projection_features proj;
00465         if (panoProjectionFeaturesQuery(projection, &proj))
00466         {
00467             std::cout << "Setting projection to " << proj.name << std::endl;
00468         }
00469         pano.setOptions(opt);
00470     };
00471     // output exposure value
00472     if (outputExposure > -1000 || calcMeanExposure)
00473     {
00474         HuginBase::PanoramaOptions opt = pano.getOptions();
00475         if (calcMeanExposure)
00476         {
00477             opt.outputExposureValue = HuginBase::CalculateMeanExposure::calcMeanExposure(pano);
00478         }
00479         else
00480         {
00481             opt.outputExposureValue = outputExposure;
00482         };
00483         std::cout << "Setting output exposure value to " << opt.outputExposureValue << std::endl;
00484         pano.setOptions(opt);
00485     };
00486     // output type: normal, fused, hdr pano..
00487     if (!outputType.empty())
00488     {
00489         HuginBase::PanoramaOptions opt = pano.getOptions();
00490         // reset all output
00491         // final pano
00492         opt.outputLDRBlended = false;
00493         opt.outputLDRExposureBlended = false;
00494         opt.outputLDRExposureLayersFused = false;
00495         opt.outputHDRBlended = false;
00496         // remapped images
00497         opt.outputLDRLayers = false;
00498         opt.outputLDRExposureRemapped = false;
00499         opt.outputHDRLayers = false;
00500         // stacks
00501         opt.outputLDRStacks = false;
00502         opt.outputHDRStacks = false;
00503         // exposure layers
00504         opt.outputLDRExposureLayers = false;
00505         // now parse string and set corresponding options
00506         std::vector<std::string> tokens = hugin_utils::SplitString(outputType, ",");
00507         size_t counter = 0;
00508         for (size_t i = 0; i < tokens.size(); i++)
00509         {
00510             std::string s = hugin_utils::toupper(hugin_utils::StrTrim(tokens[i]));
00511             if (s == "NORMAL" || s=="N")
00512             {
00513                 opt.outputLDRBlended = true;
00514                 std::cout << "Activate output of normal panorama." << std::endl;
00515                 counter++;
00516                 continue;
00517             };
00518             if (s == "STACKSFUSEDBLENDED" || s == "FB")
00519             {
00520                 opt.outputLDRExposureBlended = true;
00521                 std::cout << "Activate output of LDR panorama: Exposure fused from stacks." << std::endl;
00522                 counter++;
00523                 continue;
00524             };
00525             if (s == "EXPOSURELAYERSFUSED" || s == "BF")
00526             {
00527                 opt.outputLDRExposureLayersFused = true;
00528                 std::cout << "Activate output of LDR panorama: Exposure fused from any arrangement." << std::endl;
00529                 counter++;
00530                 continue;
00531             };
00532             if (s == "HDR")
00533             {
00534                 opt.outputHDRBlended = true;
00535                 std::cout << "Activate output of hdr panorama." << std::endl;
00536                 counter++;
00537                 continue;
00538             };
00539             // single remapped images
00540             if (s == "REMAP")
00541             {
00542                 opt.outputLDRLayers = true;
00543                 std::cout << "Activate output of remapped, exposure corrected images." << std::endl;
00544                 counter++;
00545                 continue;
00546             };
00547             if (s == "REMAPORIG")
00548             {
00549                 opt.outputLDRExposureRemapped = true;
00550                 std::cout << "Activate output of remapped images with unmodified exposure." << std::endl;
00551                 counter++;
00552                 continue;
00553             };
00554             if (s == "HDRREMAP")
00555             {
00556                 opt.outputHDRLayers = true;
00557                 std::cout << "Activate output of remapped hdr images." << std::endl;
00558                 counter++;
00559                 continue;
00560             };
00561             //stacks
00562             if (s == "FUSEDSTACKS")
00563             {
00564                 opt.outputLDRStacks = true;
00565                 std::cout << "Activate output of exposure fused stacks." << std::endl;
00566                 counter++;
00567                 continue;
00568             };
00569             if (s == "HDRSTACKS")
00570             {
00571                 opt.outputHDRStacks = true;
00572                 std::cout << "Activate output of HDR stacks." << std::endl;
00573                 counter++;
00574                 continue;
00575             };
00576             //exposure layers
00577             if (s == "EXPOSURELAYERS")
00578             {
00579                 opt.outputLDRExposureLayers = true;
00580                 std::cout << "Activate output of exposure layers." << std::endl;
00581                 counter++;
00582                 continue;
00583             };
00584             std::cout << "Unknown parameter \"" << s << "\" found in --output-type." << std::endl
00585                 << "Ignoring this parameter." << std::endl;
00586         }
00587         if (counter > 0)
00588         {
00589             pano.setOptions(opt);
00590         }
00591         else
00592         {
00593             std::cout << "No matching output type given. The whole output-type is ignored." << std::endl;
00594         };
00595     };
00596     // cropped or uncropped tiff output
00597     if (outputCroppedTiff != -1)
00598     {
00599         HuginBase::PanoramaOptions opts = pano.getOptions();
00600         opts.tiff_saveROI = (outputCroppedTiff == 1);
00601         std::cout << "Setting support for cropped images: " << ((outputCroppedTiff == 1) ? "yes" : "no") << std::endl;
00602         pano.setOptions(opts);
00603     }
00604     // blender type
00605     if (!blender.empty())
00606     {
00607         HuginBase::PanoramaOptions opt = pano.getOptions();
00608         if (blender == "enblend")
00609         {
00610             opt.blendMode = HuginBase::PanoramaOptions::ENBLEND_BLEND;
00611             std::cout << "Setting blender type to \"ENBLEND\"." << std::endl;
00612         }
00613         else
00614         {
00615             if (blender == "internal" || blender == "verdandi")
00616             {
00617                 opt.blendMode = HuginBase::PanoramaOptions::INTERNAL_BLEND;
00618                 std::cout << "Setting blender type to \"INTERNAL\"." << std::endl;
00619             }
00620             else
00621             {
00622                 std::cout << "Blender \"" << blender << "\" is not a valid blender ." << std::endl
00623                     << "Ignoring parameter." << std::endl;
00624             };
00625         };
00626         pano.setOptions(opt);
00627     }
00628     // ldr output file type
00629     if (!ldrfiletype.empty())
00630     {
00631         HuginBase::PanoramaOptions opt = pano.getOptions();
00632         if (ldrfiletype == "jpg" || ldrfiletype == "png" || ldrfiletype == "tif")
00633         {
00634             opt.outputImageType = ldrfiletype;
00635             std::cout << "Setting ldr output to filetype \"" << ldrfiletype << "\"." << std::endl;
00636             pano.setOptions(opt);
00637         }
00638         else
00639         {
00640             std::cout << "LDR file format \"" << ldrfiletype << "\" is not a valid LDR output filetype." << std::endl
00641                 << "Ignoring parameter." << std::endl;
00642         };
00643     };
00644     // ldr compression
00645     if (!ldrcompression.empty())
00646     {
00647         HuginBase::PanoramaOptions opt = pano.getOptions();
00648         if (opt.outputImageType == "tif")
00649         {
00650             if (ldrcompression == "NONE" || ldrcompression == "PACKBITS" || ldrcompression == "LZW" || ldrcompression == "DEFLATE")
00651             {
00652                 opt.outputImageTypeCompression = ldrcompression;
00653                 std::cout << "Setting TIF compression to \"" << ldrcompression << "\"." << std::endl;
00654                 opt.tiffCompression = ldrcompression;
00655             }
00656             else
00657             {
00658                 std::cout << "LDR compression \"" << ldrcompression << "\" is not a valid compression value for TIF files." << std::endl
00659                     << "Ignoring compression." << std::endl;
00660             }
00661         }
00662         else
00663         {
00664             if (opt.outputImageType == "jpg")
00665             {
00666                 int quality = 0;
00667                 quality = atoi(ldrcompression.c_str());
00668                 if (quality != 0)
00669                 {
00670                     if (quality>0 && quality <=100)
00671                     { 
00672                         opt.quality = quality;
00673                         std::cout << "Setting JPEG quality to " << quality << "." << std::endl;
00674                     }
00675                     else
00676                     {
00677                         std::cout << "Given value for JPEG quality is outside the valid range 1..100." << std::endl
00678                             << "Ignoring value." << std::endl;
00679                     };
00680                 }
00681                 else
00682                 {
00683                     std::cout << "Could not parse \"" << ldrcompression << "\" as a valid JPEG quality number." << std::endl
00684                         << "Ignoring value." << std::endl;
00685                 };
00686             }
00687             else
00688             {
00689                 if (opt.outputImageType == "png")
00690                 {
00691                     std::cout << "Setting compression for PNG images is not supported." << std::endl;
00692                 }
00693                 else
00694                 {
00695                     // this should never happen
00696                     std::cout << "Unknown image format" << std::endl;
00697                 };
00698             };
00699         };
00700         pano.setOptions(opt);
00701     };
00702     // hdr output file type
00703     if (!hdrfiletype.empty())
00704     {
00705         HuginBase::PanoramaOptions opt = pano.getOptions();
00706         if (hdrfiletype == "exr" || hdrfiletype == "tif")
00707         {
00708             opt.outputImageTypeHDR = hdrfiletype;
00709             std::cout << "Setting hdr output to filetype \"" << ldrfiletype << "\"." << std::endl;
00710             pano.setOptions(opt);
00711         }
00712         else
00713         {
00714             std::cout << "HDR file format \"" << ldrfiletype << "\" is not a valid HDR output filetype." << std::endl
00715                 << "Ignoring parameter." << std::endl;
00716         };
00717     };
00718     // hdr compression
00719     if (!hdrcompression.empty())
00720     {
00721         HuginBase::PanoramaOptions opt = pano.getOptions();
00722         if (opt.outputImageTypeHDR == "tif")
00723         {
00724             if (hdrcompression == "NONE" || hdrcompression == "PACKBITS" || hdrcompression == "LZW" || hdrcompression == "DEFLATE")
00725             {
00726                 opt.outputImageTypeHDRCompression = hdrcompression;
00727                 std::cout << "Setting HDR-TIF compression to \"" << hdrcompression << "\"." << std::endl;
00728             }
00729             else
00730             {
00731                 std::cout << "HDR compression \"" << ldrcompression << "\" is not a valid compression value for TIF files." << std::endl
00732                     << "Ignoring compression." << std::endl;
00733             }
00734         }
00735         else
00736         {
00737             if (opt.outputImageTypeHDR == "exr")
00738             {
00739                 std::cout << "Setting compression for EXR images is not supported." << std::endl;
00740             }
00741             else
00742             {
00743                 // this should never happen
00744                 std::cout << "Unknown HDR image format" << std::endl;
00745             };
00746         };
00747         pano.setOptions(opt);
00748     };
00749     // rotate complete pano
00750     if (std::abs(yaw) + std::abs(pitch) + std::abs(roll) > 0.0)
00751     {
00752         std::cout << "Rotate panorama (yaw=" << yaw << ", pitch= " << pitch << ", roll=" << roll << ")" << std::endl;
00753         HuginBase::RotatePanorama(pano, yaw, pitch, roll).run();
00754     };
00755     // translate complete pano
00756     if(std::abs(x) + std::abs(y) + std::abs(z) > 0.0)
00757     {
00758         std::cout << "Translate panorama (x=" << x << ", y=" << y << ", z=" << z << ")" << std::endl;
00759         HuginBase::TranslatePanorama(pano, x, y, z).run();
00760     };
00761     // straighten
00762     if(doStraighten)
00763     {
00764         std::cout << "Straighten panorama" << std::endl;
00765         HuginBase::StraightenPanorama(pano).run();
00766         HuginBase::CenterHorizontally(pano).run();
00767     };
00768     // center
00769     if(doCenter)
00770     {
00771         std::cout << "Center panorama" << std::endl;
00772         HuginBase::CenterHorizontally(pano).run();
00773     }
00774     //fit fov
00775     if(doFit)
00776     {
00777         std::cout << "Fit panorama field of view to best size" << std::endl;
00778         HuginBase::PanoramaOptions opt = pano.getOptions();
00779         HuginBase::CalculateFitPanorama fitPano(pano);
00780         fitPano.run();
00781         opt.setHFOV(fitPano.getResultHorizontalFOV());
00782         opt.setHeight(hugin_utils::roundi(fitPano.getResultHeight()));
00783         std::cout << "Setting field of view to " << opt.getHFOV() << " x " << opt.getVFOV() << std::endl;
00784         pano.setOptions(opt);
00785     };
00786     //set field of view manually
00787     if(newHFOV>0)
00788     {
00789         HuginBase::PanoramaOptions opt = pano.getOptions();
00790         opt.setHFOV(newHFOV);
00791         if(opt.fovCalcSupported(opt.getProjection()) && newVFOV>0)
00792         {
00793             opt.setVFOV(newVFOV);
00794         }
00795         std::cout << "Setting field of view to " << opt.getHFOV() << " x " << opt.getVFOV() << std::endl;
00796         pano.setOptions(opt);
00797     };
00798     // calc optimal size
00799     if(doOptimalSize)
00800     {
00801         std::cout << "Calculate optimal size of panorama" << std::endl;
00802         double s = HuginBase::CalculateOptimalScale::calcOptimalScale(pano);
00803         HuginBase::PanoramaOptions opt = pano.getOptions();
00804         opt.setWidth(hugin_utils::roundi(opt.getWidth()*s*scale/100), true);
00805         std::cout << "Setting canvas size to " << opt.getWidth() << " x " << opt.getHeight() << std::endl;
00806         pano.setOptions(opt);
00807     };
00808     // set canvas size
00809     if(newWidth>0 && newHeight>0)
00810     {
00811         HuginBase::PanoramaOptions opt = pano.getOptions();
00812         opt.setWidth(newWidth);
00813         opt.setHeight(newHeight);
00814         std::cout << "Setting canvas size to " << opt.getWidth() << " x " << opt.getHeight() << std::endl;
00815         pano.setOptions(opt);
00816     };
00817     // auto crop
00818     if(doAutocrop)
00819     {
00820         std::cout << "Searching for best crop rectangle" << std::endl;
00821         AppBase::DummyProgressDisplay dummy;
00822         HuginBase::CalculateOptimalROI cropPano(pano, &dummy);
00823         if(autocropHDR)
00824         {
00825             cropPano.setStacks(getHDRStacks(pano,pano.getActiveImages(), pano.getOptions()));
00826         }
00827         cropPano.run();
00828 
00829         vigra::Rect2D roi=cropPano.getResultOptimalROI();
00830         HuginBase::PanoramaOptions opt = pano.getOptions();
00831         //set the ROI - fail if the right/bottom is zero, meaning all zero
00832         if(!roi.isEmpty())
00833         {
00834             opt.setROI(roi);
00835             std::cout << "Set crop size to " << roi.left() << "," << roi.top() << "," << roi.right() << "," << roi.bottom() << std::endl;
00836             pano.setOptions(opt);
00837         }
00838         else
00839         {
00840             std::cout << "Could not find best crop rectangle" << std::endl;
00841         }
00842     };
00843     //setting crop rectangle manually
00844     if(newROI.right() != 0 && newROI.bottom() != 0)
00845     {
00846         HuginBase::PanoramaOptions opt = pano.getOptions();
00847         opt.setROI(newROI);
00848         std::cout << "Set crop size to " << newROI.left() << "," << newROI.right() << "," << newROI.top() << "," << newROI.bottom() << std::endl;
00849         pano.setOptions(opt);
00850     };
00851 
00852     //write output
00853     HuginBase::OptimizeVector optvec = pano.getOptimizeVector();
00854     HuginBase::UIntSet imgs;
00855     fill_set(imgs,0, pano.getNrOfImages()-1);
00856     // Set output .pto filename if not given
00857     if (output=="")
00858     {
00859         output=input.substr(0,input.length()-4).append("_mod.pto");
00860     }
00861     std::ofstream of(output.c_str());
00862     pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, hugin_utils::getPathPrefix(input));
00863 
00864     std::cout << std::endl << "Written output to " << output << std::endl;
00865     return 0;
00866 }

Generated on 8 Dec 2016 for Hugintrunk by  doxygen 1.4.7