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

Generated on 25 May 2016 for Hugintrunk by  doxygen 1.4.7