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 <getopt.h>
00032 #ifndef WIN32
00033 #include <unistd.h>
00034 #endif
00035 #include <panodata/Panorama.h>
00036 #include <algorithms/nona/CenterHorizontally.h>
00037 #include <algorithms/basic/StraightenPanorama.h>
00038 #include <algorithms/basic/RotatePanorama.h>
00039 #include <algorithms/basic/TranslatePanorama.h>
00040 #include <algorithms/nona/FitPanorama.h>
00041 #include <algorithms/basic/CalculateOptimalScale.h>
00042 #include <algorithms/basic/CalculateOptimalROI.h>
00043 #include <algorithms/basic/LayerStacks.h>
00044 #include <algorithms/basic/CalculateMeanExposure.h>
00045 #include "hugin_utils/utils.h"
00046 
00047 using namespace std;
00048 using namespace HuginBase;
00049 using namespace AppBase;
00050 
00051 static void usage(const char* name)
00052 {
00053     cout << name << ": change output parameters of project file" << endl
00054          << "pano_modify version " << hugin_utils::GetHuginVersion() << endl
00055          << endl
00056          << "Usage:  " << name << " [options] input.pto" << endl
00057          << endl
00058          << "  Options:" << endl
00059          << "    -o, --output=file.pto  Output Hugin PTO file. Default: <filename>_mod.pto" << endl
00060          << "    -p, --projection=x     Sets the output projection to number x" << endl
00061          << "    --fov=AUTO|HFOV|HFOVxVFOV   Sets field of view" << endl
00062          << "                                AUTO: calculates optimal fov" << endl
00063          << "                                HFOV|HFOVxVFOV: set to given fov" << endl
00064          << "    -s, --straighten       Straightens the panorama" << endl
00065          << "    -c, --center           Centers the panorama" << endl
00066          << "    --canvas=AUTO|num%|WIDTHxHEIGHT  Sets the output canvas size" << endl
00067          << "                                AUTO: calculate optimal canvas size" << endl
00068          << "                                num%: scales the optimal size by given percent" << endl
00069          << "                                WIDTHxHEIGHT: set to given size" << endl
00070          << "    --crop=AUTO|AUTOHDR|left,right,top,bottom  Sets the crop rectangle" << endl
00071          << "                                AUTO: autocrop panorama" << endl
00072          << "                                AUTOHDR: autocrop HDR panorama" << endl
00073          << "                                left,right,top,bottom: to given size" << endl
00074          << "    --output-exposure=AUTO|num  Sets the output exposure value to mean" << endl
00075          << "                                exposure (AUTO) or to given value" << endl
00076          << "    --output-cropped-tiff    Output cropped tiffs as intermediate images" << endl
00077          << "    --output-uncropped-tiff  Output uncropped tiffs as intermediate images" << endl
00078          << "    --output-type=str       Sets the type of output" << endl
00079          << "                              Valid items are" << endl
00080          << "                                NORMAL|N: normal panorama" << endl
00081          << "                                STACKSFUSEDBLENDED|BF: LDR panorama with" << endl
00082          << "                                    blended stacks" << endl
00083          << "                                EXPOSURELAYERSFUSED|FB: LDR panorama with" << endl
00084          << "                                    fused exposure layers (any arrangement)" << endl
00085          << "                                HDR: HDR panorama" << endl
00086          << "                                REMAP: remapped images with corrected exposure" << endl
00087          << "                                REMAPORIG: remapped images with" << endl
00088          << "                                    uncorrected exposure" << endl
00089          << "                                HDRREMAP: remapped images in linear color space" << endl
00090          << "                                FUSEDSTACKS: exposure fused stacks" << endl
00091          << "                                HDRSTACKS: HDR stacks" << endl
00092          << "                                EXPOSURELAYERS: blended exposure layers" << endl
00093          << "                              and separated by a comma." << endl
00094          << "    --ldr-file=JPG|TIF|PNG  Sets the filetype for LDR panorama output" << endl
00095          << "    --ldr-compression=str   Sets the compression for LDR panorama output" << endl
00096          << "                              For TIF: NONE|PACKBITS|LZW|DEFLATE" << endl
00097          << "                              For JPEG: quality as number" << endl
00098          << "    --hdr-file=EXR|TIF      Sets the filetype for HDR panorama output" << endl
00099          << "    --hdr-compression=str   Sets the compression for HDR panorama output" << endl
00100          << "                              For TIF: NONE|PACKBITS|LZW|DEFLATE" << endl
00101          << "    --blender=ENBLEND|INTERNAL  Sets the blender to be used at stitching" << endl
00102          << "                            stage." << endl
00103          << "    --rotate=yaw,pitch,roll Rotates the whole panorama with the given angles" << endl
00104          << "    --translate=x,y,z       Translate the whole panorama with the given values" << endl
00105          << "    -h, --help             Shows this help" << endl
00106          << endl;
00107 }
00108 
00109 int main(int argc, char* argv[])
00110 {
00111     // parse arguments
00112     const char* optstring = "o:p:sch";
00113 
00114     enum
00115     {
00116         SWITCH_FOV=1000,
00117         SWITCH_CANVAS,
00118         SWITCH_CROP,
00119         SWITCH_ROTATE,
00120         SWITCH_TRANSLATE,
00121         SWITCH_EXPOSURE,
00122         SWITCH_OUTPUT_TYPE,
00123         SWITCH_BLENDER,
00124         SWITCH_LDRFILETYPE,
00125         SWITCH_LDRCOMPRESSION,
00126         SWITCH_HDRFILETYPE,
00127         SWITCH_HDRCOMPRESSION,
00128         SWITCH_CROPPED_TIFF,
00129         SWITCH_UNCROPPED_TIFF
00130     };
00131     static struct option longOptions[] =
00132     {
00133         {"output", required_argument, NULL, 'o' },
00134         {"projection", required_argument, NULL, 'p' },
00135         {"fov", required_argument, NULL, SWITCH_FOV },
00136         {"straighten", no_argument, NULL, 's' },
00137         {"center", no_argument, NULL, 'c' },
00138         {"canvas", required_argument, NULL, SWITCH_CANVAS },
00139         {"crop", required_argument, NULL, SWITCH_CROP },
00140         {"output-cropped-tiff", no_argument, NULL, SWITCH_CROPPED_TIFF },
00141         {"output-uncropped-tiff", no_argument, NULL, SWITCH_UNCROPPED_TIFF },
00142         {"output-exposure", required_argument, NULL, SWITCH_EXPOSURE },
00143         {"output-type", required_argument, NULL, SWITCH_OUTPUT_TYPE },
00144         {"blender", required_argument, NULL, SWITCH_BLENDER },
00145         {"ldr-file", required_argument,NULL, SWITCH_LDRFILETYPE },
00146         {"ldr-compression", required_argument, NULL, SWITCH_LDRCOMPRESSION },
00147         {"hdr-file", required_argument, NULL, SWITCH_HDRFILETYPE },
00148         {"hdr-compression", required_argument, NULL, SWITCH_HDRCOMPRESSION },
00149         {"rotate", required_argument, NULL, SWITCH_ROTATE },
00150         {"translate", required_argument, NULL, SWITCH_TRANSLATE },
00151         {"help", no_argument, NULL, 'h' },
00152         0
00153     };
00154 
00155     int projection=-1;
00156     double newHFOV=-1;
00157     double newVFOV=-1;
00158     int scale=100;
00159     int newWidth=-1;
00160     int newHeight=-1;
00161     int outputCroppedTiff=-1;
00162     vigra::Rect2D newROI(0,0,0,0);
00163     bool doFit=false;
00164     bool doStraighten=false;
00165     bool doCenter=false;
00166     bool doOptimalSize=false;
00167     bool doAutocrop=false;
00168     bool autocropHDR=false;
00169     int c;
00170     int optionIndex = 0;
00171     double yaw = 0;
00172     double pitch = 0;
00173     double roll = 0;
00174     double x = 0;
00175     double y = 0;
00176     double z = 0;
00177     double outputExposure = -1000;
00178     bool calcMeanExposure = false;
00179     std::string outputType;
00180     std::string ldrfiletype;
00181     std::string ldrcompression;
00182     std::string hdrfiletype;
00183     std::string hdrcompression;
00184     string output;
00185     string param;
00186     std::string blender;
00187     while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1)
00188     {
00189         switch (c)
00190         {
00191             case 'o':
00192                 output = optarg;
00193                 break;
00194             case 'h':
00195                 usage(hugin_utils::stripPath(argv[0]).c_str());
00196                 return 0;
00197             case 'p':
00198                 //projection
00199                 projection=atoi(optarg);
00200                 if((projection==0) && (strcmp(optarg,"0")!=0))
00201                 {
00202                     cerr << "Could not parse projection number.";
00203                     return 1;
00204                 };
00205                 if(projection>=panoProjectionFormatCount())
00206                 {
00207                     cerr << "projection " << projection << " is an invalid projection number.";
00208                     return 1;
00209                 };
00210                 break;
00211             case SWITCH_FOV:
00212                 //field of view
00213                 param=optarg;
00214                 param=hugin_utils::toupper(param);
00215                 if(param=="AUTO")
00216                 {
00217                     doFit=true;
00218                 }
00219                 else
00220                 {
00221                     int hfov, vfov;
00222                     int n=sscanf(optarg, "%dx%d", &hfov, &vfov);
00223                     if(n==1)
00224                     {
00225                         if(hfov>0)
00226                         {
00227                             newHFOV=hfov;
00228                         }
00229                         else
00230                         {
00231                             cerr << "Invalid field of view" << endl;
00232                             return 1;
00233                         };
00234                     }
00235                     else
00236                     {
00237                         if (n==2)
00238                         {
00239                             if(hfov>0 && vfov>0)
00240                             {
00241                                 newHFOV=hfov;
00242                                 newVFOV=vfov;
00243                             }
00244                             else
00245                             {
00246                                 cerr << "Invalid field of view" << endl;
00247                                 return 1;
00248                             };
00249                         }
00250                         else
00251                         {
00252                             cerr << "Could not parse field of view" << endl;
00253                             return 1;
00254                         };
00255                     };
00256                 };
00257                 break;
00258             case 's':
00259                 doStraighten=true;
00260                 break;
00261             case 'c':
00262                 doCenter=true;
00263                 break;
00264             case SWITCH_CANVAS:
00265                 //canvas size
00266                 param=optarg;
00267                 param=hugin_utils::toupper(param);
00268                 if(param=="AUTO")
00269                 {
00270                     doOptimalSize=true;
00271                 }
00272                 else
00273                 {
00274                     int pos=param.find("%");
00275                     if(pos!=string::npos)
00276                     {
00277                         param=param.substr(0,pos);
00278                         scale=atoi(param.c_str());
00279                         if(scale==0)
00280                         {
00281                             cerr << "No valid scale factor given." << endl;
00282                             return 1;
00283                         };
00284                         doOptimalSize=true;
00285                     }
00286                     else
00287                     {
00288                         int width, height;
00289                         int n=sscanf(optarg, "%dx%d", &width, &height);
00290                         if (n==2)
00291                         {
00292                             if(width>0 && height>0)
00293                             {
00294                                 newWidth=width;
00295                                 newHeight=height;
00296                             }
00297                             else
00298                             {
00299                                 cerr << "Invalid canvas size" << endl;
00300                                 return 1;
00301                             };
00302                         }
00303                         else
00304                         {
00305                             cerr << "Could not parse canvas size" << endl;
00306                             return 1;
00307                         };
00308                     };
00309                 };
00310                 break;
00311             case SWITCH_CROP:
00312                 //crop
00313                 param=optarg;
00314                 param=hugin_utils::toupper(param);
00315                 if(param=="AUTO" || param=="AUTOHDR")
00316                 {
00317                     doAutocrop=true;
00318                     if(param=="AUTOHDR")
00319                     {
00320                         autocropHDR=true;
00321                     };
00322                 }
00323                 else
00324                 {
00325                     int left, right, top, bottom;
00326                     int n=sscanf(optarg, "%d,%d,%d,%d", &left, &right, &top, &bottom);
00327                     if (n==4)
00328                     {
00329                         if(right>left && bottom>top && left>=0 && top>=0)
00330                         {
00331                             newROI.setUpperLeft(vigra::Point2D(left,top));
00332                             newROI.setLowerRight(vigra::Point2D(right,bottom));
00333                         }
00334                         else
00335                         {
00336                             cerr << "Invalid crop area" << endl;
00337                             return 1;
00338                         };
00339                     }
00340                     else
00341                     {
00342                         cerr << "Could not parse crop values" << endl;
00343                         return 1;
00344                     };
00345                 };
00346                 break;
00347             case SWITCH_CROPPED_TIFF:
00348                 outputCroppedTiff = 1;
00349                 break;
00350             case SWITCH_UNCROPPED_TIFF:
00351                 outputCroppedTiff = 0;
00352                 break;
00353             case SWITCH_EXPOSURE:
00354                 param = optarg;
00355                 param = hugin_utils::toupper(param);
00356                 if (param == "AUTO")
00357                 {
00358                     calcMeanExposure = true;
00359                 }
00360                 else
00361                 {
00362                     int n = sscanf(optarg, "%lf", &outputExposure);
00363                     if (n != 1)
00364                     {
00365                         cerr << "Could not parse output exposure value.";
00366                         return 1;
00367                     };
00368                 };
00369                 break;
00370             case SWITCH_OUTPUT_TYPE:
00371                 if (!outputType.empty())
00372                 {
00373                     outputType.append(",");
00374                 };
00375                 outputType.append(optarg);
00376                 break;
00377             case SWITCH_BLENDER:
00378                 blender = hugin_utils::tolower(hugin_utils::StrTrim(optarg));
00379                 break;
00380             case SWITCH_LDRFILETYPE:
00381                 ldrfiletype = hugin_utils::tolower(hugin_utils::StrTrim(optarg));
00382                 break;
00383             case SWITCH_LDRCOMPRESSION:
00384                 ldrcompression = hugin_utils::toupper(hugin_utils::StrTrim(optarg));
00385                 break;
00386             case SWITCH_HDRFILETYPE:
00387                 hdrfiletype = hugin_utils::tolower(hugin_utils::StrTrim(optarg));
00388                 break;
00389             case SWITCH_HDRCOMPRESSION:
00390                 hdrcompression = hugin_utils::toupper(hugin_utils::StrTrim(optarg));
00391                 break;
00392             case SWITCH_ROTATE:
00393                 {
00394                     int n=sscanf(optarg, "%lf,%lf,%lf", &yaw, &pitch, &roll);
00395                     if(n!=3)
00396                     {
00397                         cerr << "Could not parse rotate angles values. Given: \"" << optarg << "\"" << endl;
00398                         return 1;
00399                     };
00400                 };
00401                 break;
00402             case SWITCH_TRANSLATE:
00403                 {
00404                     int n=sscanf(optarg, "%lf,%lf,%lf", &x, &y, &z);
00405                     if(n!=3)
00406                     {
00407                         cerr << "Could not parse translation values. Given: \"" << optarg << "\"" << endl;
00408                         return 1;
00409                     };
00410                 };
00411                 break;
00412             case ':':
00413                 cerr <<"Option " << longOptions[optionIndex].name << " requires a number" << endl;
00414                 return 1;
00415                 break;
00416             case '?':
00417                 break;
00418             default:
00419                 abort ();
00420         }
00421     }
00422 
00423     if (argc - optind != 1)
00424     {
00425         cout << "Warning: pano_modify can only work on one project file at one time" << endl << endl;
00426         usage(hugin_utils::stripPath(argv[0]).c_str());
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     string input=argv[optind];
00442     // read panorama
00443     Panorama pano;
00444     ifstream prjfile(input.c_str());
00445     if (!prjfile.good())
00446     {
00447         cerr << "could not open script : " << input << endl;
00448         return 1;
00449     }
00450     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00451     DocumentData::ReadWriteError err = pano.readData(prjfile);
00452     if (err != DocumentData::SUCCESSFUL)
00453     {
00454         cerr << "error while parsing panos tool script: " << input << endl;
00455         cerr << "DocumentData::ReadWriteError code: " << err << endl;
00456         return 1;
00457     }
00458 
00459     // sets the projection
00460     if(projection!=-1)
00461     {
00462         PanoramaOptions opt=pano.getOptions();
00463         opt.setProjection((PanoramaOptions::ProjectionFormat)projection);
00464         pano_projection_features proj;
00465         if (panoProjectionFeaturesQuery(projection, &proj))
00466         {
00467             cout << "Setting projection to " << proj.name << endl;
00468         }
00469         pano.setOptions(opt);
00470     };
00471     // output exposure value
00472     if (outputExposure > -1000 || calcMeanExposure)
00473     {
00474         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         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         PanoramaOptions opt = pano.getOptions();
00608         if (blender == "enblend")
00609         {
00610             opt.blendMode = 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 = 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         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         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         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         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 (abs(yaw) + abs(pitch) + abs(roll) > 0.0)
00751     {
00752         cout << "Rotate panorama (yaw=" << yaw << ", pitch= " << pitch << ", roll=" << roll << ")" << endl;
00753         RotatePanorama(pano, yaw, pitch, roll).run();
00754     };
00755     // translate complete pano
00756     if(abs(x) + abs(y) + abs(z) > 0.0)
00757     {
00758         cout << "Translate panorama (x=" << x << ", y=" << y << ", z=" << z << ")" << endl;
00759         TranslatePanorama(pano, x, y, z).run();
00760     };
00761     // straighten
00762     if(doStraighten)
00763     {
00764         cout << "Straighten panorama" << endl;
00765         StraightenPanorama(pano).run();
00766         CenterHorizontally(pano).run();
00767     };
00768     // center
00769     if(doCenter)
00770     {
00771         cout << "Center panorama" << endl;
00772         CenterHorizontally(pano).run();
00773     }
00774     //fit fov
00775     if(doFit)
00776     {
00777         cout << "Fit panorama field of view to best size" << endl;
00778         PanoramaOptions opt=pano.getOptions();
00779         CalculateFitPanorama fitPano = CalculateFitPanorama(pano);
00780         fitPano.run();
00781         opt.setHFOV(fitPano.getResultHorizontalFOV());
00782         opt.setHeight(roundi(fitPano.getResultHeight()));
00783         cout << "Setting field of view to " << opt.getHFOV() << " x " << opt.getVFOV() << endl;
00784         pano.setOptions(opt);
00785     };
00786     //set field of view manually
00787     if(newHFOV>0)
00788     {
00789         PanoramaOptions opt=pano.getOptions();
00790         opt.setHFOV(newHFOV);
00791         if(opt.fovCalcSupported(opt.getProjection()) && newVFOV>0)
00792         {
00793             opt.setVFOV(newVFOV);
00794         }
00795         cout << "Setting field of view to " << opt.getHFOV() << " x " << opt.getVFOV() << endl;
00796         pano.setOptions(opt);
00797     };
00798     // calc optimal size
00799     if(doOptimalSize)
00800     {
00801         cout << "Calculate optimal size of panorama" << endl;
00802         double s = CalculateOptimalScale::calcOptimalScale(pano);
00803         PanoramaOptions opt=pano.getOptions();
00804         opt.setWidth(roundi(opt.getWidth()*s*scale/100), true);
00805         cout << "Setting canvas size to " << opt.getWidth() << " x " << opt.getHeight() << endl;
00806         pano.setOptions(opt);
00807     };
00808     // set canvas size
00809     if(newWidth>0 && newHeight>0)
00810     {
00811         PanoramaOptions opt=pano.getOptions();
00812         opt.setWidth(newWidth);
00813         opt.setHeight(newHeight);
00814         cout << "Setting canvas size to " << opt.getWidth() << " x " << opt.getHeight() << endl;
00815         pano.setOptions(opt);
00816     };
00817     // auto crop
00818     if(doAutocrop)
00819     {
00820         cout << "Searching for best crop rectangle" << endl;
00821         DummyProgressDisplay dummy;
00822         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         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             cout << "Set crop size to " << roi.left() << "," << roi.top() << "," << roi.right() << "," << roi.bottom() << endl;
00836             pano.setOptions(opt);
00837         }
00838         else
00839         {
00840             cout << "Could not find best crop rectangle" << endl;
00841         }
00842     };
00843     //setting crop rectangle manually
00844     if(newROI.right() != 0 && newROI.bottom() != 0)
00845     {
00846         PanoramaOptions opt = pano.getOptions();
00847         opt.setROI(newROI);
00848         cout << "Set crop size to " << newROI.left() << "," << newROI.right() << "," << newROI.top() << "," << newROI.bottom() << endl;
00849         pano.setOptions(opt);
00850     };
00851 
00852     //write output
00853     OptimizeVector optvec = pano.getOptimizeVector();
00854     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     ofstream of(output.c_str());
00862     pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, hugin_utils::getPathPrefix(input));
00863 
00864     cout << endl << "Written output to " << output << endl;
00865     return 0;
00866 }

Generated on 1 Sep 2015 for Hugintrunk by  doxygen 1.4.7