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

Generated on 20 Jan 2018 for Hugintrunk by  doxygen 1.4.7