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

Generated on 8 Feb 2016 for Hugintrunk by  doxygen 1.4.7