49 static std::map<HuginBase::BaseSrcPanoImage::Projection, std::string>
lensTypeNames;
53 const int nP = panoProjectionFormatCount();
54 projectionNames.resize(nP);
55 for (
int n = 0; n < nP; ++n)
57 pano_projection_features proj;
58 if (panoProjectionFeaturesQuery(n, &proj))
76 bool CheckString(
const std::string& variable,
const std::string& operatorString,
const std::string& value)
78 if (operatorString ==
"==")
80 return variable == value;
82 if (operatorString ==
"!=" || operatorString ==
"<>")
84 return variable != value;
86 if (operatorString ==
"=~")
89 return variable.find(value) != std::string::npos;
91 if (operatorString ==
"!~")
94 return variable.find(value) == std::string::npos;
96 std::cerr <<
"Invalid operator \"" << operatorString <<
"\"" << std::endl;
101 template<
class Number>
102 bool CheckNumber(
const Number variable,
const std::string& operatorString,
const Number value)
104 if (operatorString ==
"==")
106 return variable == value;
108 if (operatorString ==
"!=" || operatorString ==
"<>")
110 return variable != value;
112 if (operatorString ==
"<")
114 return variable < value;
116 if (operatorString ==
"<=")
118 return variable <= value;
120 if (operatorString ==
">")
122 return variable > value;
124 if (operatorString ==
">=")
126 return variable >= value;
128 std::cerr <<
"Invalid operator \"" << operatorString <<
"\"" << std::endl;
133 bool CheckInt(
const int variable,
const std::string& operatorString,
const std::string& stringValue)
138 std::cerr <<
"Invalid number \"" << stringValue <<
"\"" << std::endl;
141 return CheckNumber<int>(variable, operatorString, value);
145 bool CheckDouble(
const double variable,
const std::string& operatorString,
const std::string& stringValue)
150 std::cerr <<
"Invalid number \"" << stringValue <<
"\"" << std::endl;
153 return CheckNumber<double>(variable, operatorString, value);
159 size_t pos = condition.find_first_of(
"=<>!~");
160 if (pos != std::string::npos)
163 const std::string variable = condition.substr(0, pos);
164 std::string operatorString;
166 size_t pos2 = condition.find_first_not_of(
"=<>!~", pos);
167 if (pos2 != std::string::npos)
170 operatorString = condition.substr(pos, pos2 - pos);
171 value = condition.substr(pos2);
175 std::cerr <<
"Missing value in comparison \"" << condition <<
"\"." << std::endl;
179 if (variable ==
"CameraModel")
183 if (variable ==
"CameraMaker")
187 if (variable ==
"Lens")
191 if (variable ==
"HFOV")
195 if (variable ==
"LensType")
197 if (projectionNames.empty())
204 if (variable ==
"Focallength")
208 if (variable ==
"Focallength35mm")
212 if (variable ==
"Filename")
216 if (variable ==
"Path")
220 if (variable ==
"ImageCount")
224 if (variable ==
"PanoHFOV")
228 if (variable ==
"PanoVFOV")
239 if (projectionNames.empty())
244 for (
int i = 0; i < projectionNames.size(); ++i)
246 if (projectionNames[i] == projectionString)
248 std::cout <<
"Setting projection to " << projectionString << std::endl;
249 options.
setProjection(static_cast<HuginBase::PanoramaOptions::ProjectionFormat>(i));
259 std::cout <<
"Fit panorama field of view to best size" << std::endl;
266 std::cout <<
"Setting field of view to " << options.
getHFOV() <<
" x " << options.
getVFOV() << std::endl;
270 double newHFOV = 0.0;
271 double newVFOV = 0.0;
272 const int n = sscanf(fov.c_str(),
"%lfx%lf", &newHFOV, &newVFOV);
273 if ((n == 1 || n == 2) && newHFOV > 0.0)
280 std::cout <<
"Setting field of view to " << options.
getHFOV() <<
" x " << options.
getVFOV() << std::endl;
287 if (canvas ==
"auto" || canvas.back() ==
'%')
290 if (canvas.back() ==
'%')
294 std::cout <<
"Invalid scale factor \"" << canvas <<
"\" for canvas" << std::endl;
300 std::cout <<
"Calculate optimal size of panorama" << std::endl;
305 std::cout <<
"Setting canvas size to " << options.
getWidth() <<
" x " << options.
getHeight() << std::endl;
312 int n = sscanf(canvas.c_str(),
"%dx%d", &width, &height);
313 if (n == 2 && width > 0 && height > 0)
317 std::cout <<
"Setting canvas size to " << options.
getWidth() <<
" x " << options.
getHeight() << std::endl;
321 std::cerr <<
"Could not parse canvas size \"" << canvas <<
"\"." << std::endl;
328 if (cropString ==
"auto" || cropString ==
"autohdr" || cropString ==
"autooutside")
330 std::cout <<
"Searching for best crop rectangle" << std::endl;
337 if (cropString ==
"autooutside")
346 if (cropString ==
"autohdr")
357 std::cout <<
"Set crop size to " << roi.left() <<
"," << roi.top() <<
"," << roi.right() <<
"," << roi.bottom() << std::endl;
361 std::cerr <<
"Could not find best crop rectangle" << std::endl;
366 if (cropString.back() ==
'%')
369 double left, right, top, bottom;
370 const int n = sscanf(cropString.substr(0, cropString.length() - 1).c_str(),
"%lf,%lf,%lf,%lf", &left, &right, &top, &bottom);
371 bool validCrop =
false;
372 if (n == 4 && right > left && bottom > top && left >= 0.0 && top >= 0.0 && right <= 100.0 && bottom <= 100.0)
377 std::cout <<
"Set crop size to " << options.
getROI().left() <<
"," << options.
getROI().top() <<
"," <<
378 options.
getROI().right() <<
"," << options.
getROI().bottom() << std::endl;
383 std::cerr <<
"Invalid crop area \"" << cropString <<
"\"" << std::endl;
389 int left, right, top, bottom;
390 int n = sscanf(cropString.c_str(),
"%d,%d,%d,%d", &left, &right, &top, &bottom);
391 bool validCrop =
false;
392 if (n == 4 && right > left && bottom > top && left >= 0 && top >= 0)
394 options.
setROI(vigra::Rect2D(left, top, right, bottom));
395 std::cout <<
"Set crop size to " << options.
getROI().left() <<
"," << options.
getROI().top() <<
"," <<
396 options.
getROI().right() <<
"," << options.
getROI().bottom() << std::endl;
401 std::cerr <<
"Invalid crop area \"" << cropString <<
"\"" << std::endl;
409 if (exposure ==
"auto")
412 std::cout <<
"Setting output exposure value to " << options.
outputExposureValue << std::endl;
416 if (!exposure.empty() && exposure.front() ==
'r')
418 double exposureValue;
422 std::cout <<
"Setting output exposure value to " << options.
outputExposureValue << std::endl;
426 std::cerr <<
"Value \"" << exposure <<
"\" is not a valid exposure value." << std::endl;
431 double exposureValue;
435 std::cout <<
"Setting output exposure value to " << options.
outputExposureValue << std::endl;
439 std::cerr <<
"Value \"" << exposure <<
"\" is not a valid exposure value." << std::endl;
448 if (!outputStrings.empty())
465 for (
const auto& output : outputStrings)
468 if (s ==
"NORMAL" || s ==
"N")
471 std::cout <<
"Activate output of normal panorama." << std::endl;
474 if (s ==
"STACKSFUSEDBLENDED" || s ==
"FB")
477 std::cout <<
"Activate output of LDR panorama: Exposure fused from stacks." << std::endl;
480 if (s ==
"EXPOSURELAYERSFUSED" || s ==
"BF")
483 std::cout <<
"Activate output of LDR panorama: Exposure fused from any arrangement." << std::endl;
489 std::cout <<
"Activate output of hdr panorama." << std::endl;
496 std::cout <<
"Activate output of remapped, exposure corrected images." << std::endl;
499 if (s ==
"REMAPORIG")
502 std::cout <<
"Activate output of remapped images with unmodified exposure." << std::endl;
508 std::cout <<
"Activate output of remapped hdr images." << std::endl;
512 if (s ==
"FUSEDSTACKS")
515 std::cout <<
"Activate output of exposure fused stacks." << std::endl;
518 if (s ==
"HDRSTACKS")
521 std::cout <<
"Activate output of HDR stacks." << std::endl;
525 if (s ==
"EXPOSURELAYERS")
528 std::cout <<
"Activate output of exposure layers." << std::endl;
531 std::cerr <<
"Unknown parameter \"" << s <<
"\" found in Output-type." << std::endl
532 <<
"Ignoring this parameter." << std::endl;
541 if (ldrCompression ==
"NONE" || ldrCompression ==
"PACKBITS" || ldrCompression ==
"LZW" || ldrCompression ==
"DEFLATE")
544 std::cout <<
"Setting TIF compression to \"" << ldrCompression <<
"\"." << std::endl;
549 std::cout <<
"LDR compression \"" << ldrCompression <<
"\" is not a valid compression value for TIF files." << std::endl;
557 quality = atoi(ldrCompression.c_str());
560 if (quality > 0 && quality <= 100)
563 std::cout <<
"Setting JPEG quality to " << quality <<
"." << std::endl;
567 std::cerr <<
"Given value for JPEG quality is outside the valid range 1..100." << std::endl;
572 std::cerr <<
"Could not parse \"" << ldrCompression <<
"\" as a valid JPEG quality number." << std::endl;
579 std::cerr <<
"Setting compression for PNG images is not supported." << std::endl;
584 std::cerr <<
"Unknown image format" << std::endl;
594 if (hdrCompression ==
"NONE" || hdrCompression ==
"PACKBITS" || hdrCompression ==
"LZW" || hdrCompression ==
"DEFLATE")
597 std::cout <<
"Setting HDR-TIF compression to \"" << hdrCompression <<
"\"." << std::endl;
601 std::cerr <<
"HDR compression \"" << hdrCompression <<
"\" is not a valid compression value for TIF files." << std::endl;
608 std::cerr <<
"Setting compression for EXR images is not supported." << std::endl;
613 std::cerr <<
"Unknown HDR image format" << std::endl;
621 const std::vector<std::string> keys = iniParser.
GetKeys(section);
624 bool isConditionFullfilled =
true;
625 for (
const auto& key : keys)
628 if (key.compare(0, 9,
"Condition") == 0)
630 isConditionFullfilled = isConditionFullfilled &&
CheckCondition(iniParser.
GetKey(section, key, std::string()), pano, panoProps);
631 if (!isConditionFullfilled)
638 if (isConditionFullfilled)
640 std::cout <<
"Applying settings from \"" << section <<
"\"" << std::endl;
642 if (iniParser.
HasKey(section,
"Projection"))
646 if (!projection.empty())
651 if (iniParser.
HasKey(section,
"FOV"))
657 SetFOV(fov, pano, options);
660 if (iniParser.
HasKey(section,
"Canvas"))
668 if (iniParser.
HasKey(section,
"Crop"))
671 if (!cropString.empty())
673 SetCrop(cropString, pano, options);
676 if (iniParser.
HasKey(section,
"OutputExposure"))
680 if (!exposure.empty())
685 if (iniParser.
HasKey(section,
"OutputType"))
690 if (iniParser.
HasKey(section,
"Blender"))
693 if (blender ==
"enblend")
696 std::cout <<
"Setting blender type to \"ENBLEND\"." << std::endl;
700 if (blender ==
"internal" || blender ==
"verdandi")
703 std::cout <<
"Setting blender type to \"INTERNAL\"." << std::endl;
707 std::cerr <<
"Blender \"" << blender <<
"\" is not a valid blender ." << std::endl
708 <<
"Ignoring parameter." << std::endl;
712 if (iniParser.
HasKey(section,
"BlenderArgs"))
719 std::cout <<
"Setting enblend arguments to " << blenderArgs << std::endl;
723 std::cout <<
"Setting verdandi arguments to " << blenderArgs << std::endl;
726 std::cout <<
"Unknown blender in pto file." << std::endl;
730 if (iniParser.
HasKey(section,
"LDRFileType"))
733 if (!ldrFileType.empty())
735 if (ldrFileType ==
"jpg" || ldrFileType ==
"png" || ldrFileType ==
"tif")
738 std::cout <<
"Setting ldr output to filetype \"" << ldrFileType <<
"\"." << std::endl;
742 std::cerr <<
"LDR file format \"" << ldrFileType <<
"\" is not a valid LDR output filetype." << std::endl;
746 if (iniParser.
HasKey(section,
"LDRCompression"))
751 if (iniParser.
HasKey(section,
"HDRFileType"))
754 if (!hdrFileType.empty())
756 if (hdrFileType ==
"exr" || hdrFileType ==
"tif")
759 std::cout <<
"Setting hdr output to filetype \"" << hdrFileType <<
"\"." << std::endl;
763 std::cerr <<
"HDR file format \"" << hdrFileType <<
"\" is not a valid HDR output filetype." << std::endl;
767 if (iniParser.
HasKey(section,
"HDRCompression"))
775 std::cout <<
"Ignoring settings from \"" << section <<
"\" because condition is not fulfilled." << std::endl;
788 iniParser.
Read(iniFile);
809 const std::vector<std::string> sections = iniParser.
GetSections();
810 if (!sections.empty())
812 for (
const auto& section : sections)
PanoramaOptions::ProjectionFormat getProjection() const
std::vector< UIntSet > getHDRStacks(const PanoramaData &pano, UIntSet allImgs, PanoramaOptions opts)
returns vector of set of output stacks
Dummy progress display, without output.
declaration of functions to handle stacks and layers
void SetOutputType(const std::string &outputType, HuginBase::PanoramaOptions &options)
bool CheckCondition(const std::string &condition, const HuginBase::Panorama &pano, const PanoProperties &panoProps)
check if given condition is fulfilled by given panorama and PanoProperties
void setHeight(unsigned int h)
set panorama height
bool CheckInt(const int variable, const std::string &operatorString, const std::string &stringValue)
check if given integer matches the condition (operator and value)
std::string StrTrim(const std::string &str)
remove trailing and leading white spaces and tabs
static double calcMeanExposure(const PanoramaData &pano)
bool outputLDRLayers
save remapped layers (LDR)
bool fovCalcSupported(ProjectionFormat f) const
true, if FOV calcuations are supported for projection f
bool HasKey(const std::string §ion, const std::string &key) const
Checks if given section/key exists.
std::string outputImageTypeHDRCompression
bool outputHDRLayers
save remapped layers (HDR)
void SetFOV(const std::string &fov, HuginBase::Panorama &pano, HuginBase::PanoramaOptions &options)
unsigned int getHeight() const
get panorama height
HuginBase::PanoramaOptions ReadPanoramaOptionsFromIni(const std::string &iniFile, HuginBase::Panorama &pano)
read settings from given ini file and apply wished settings if they are applicable ...
std::vector< std::string > GetKeys(const std::string §ion) const
returns a vector of all know keys in given section
virtual void run()
runs the algorithm.
std::string outputImageTypeCompression
std::string toupper(const std::string &s)
bool outputLDRExposureBlended
< save exposure fused stacks (no exposure adjustment)
reads and parse an ini file
Panorama duplicate() const
duplicate the panorama
void setStacks(std::vector< UIntSet > hdr_stacks)
sets the stack vector
static std::vector< std::string > projectionNames
const vigra::Rect2D & getROI() const
bool outputLDRBlended
save blended panorama (LDR)
std::string getPathPrefix(const std::string &filename)
Get the path to a filename.
std::string GetAbsoluteFilename(const std::string &filename)
returns the full absolute filename
std::vector< std::string > GetSections() const
returns a vector of all know sections
void ProcessSection(const IniParser &iniParser, const std::string §ion, HuginBase::Panorama &pano, HuginBase::PanoramaOptions &options, const PanoProperties &panoProps)
process the given section, check if all conditions are fulfilled and if so apply all wished settings ...
std::size_t getNrOfImages() const
number of images.
bool CheckString(const std::string &variable, const std::string &operatorString, const std::string &value)
check if given string matches the value with the corresponding operator
static double calcOptimalScale(PanoramaData &panorama)
virtual vigra::Rect2D getResultOptimalROI()
return the ROI structure?, for now area
virtual double getResultHeight()
bool outputHDRBlended
save blended panorama (HDR)
void SetProjection(const std::string &projectionString, HuginBase::PanoramaOptions &options)
bool stringToInt(const std::string &s, int &val)
convert string to integer value, returns true, if sucessful
bool stringToDouble(const STR &str_, double &dest)
convert a string to a double, ignore localisation.
void setROI(const vigra::Rect2D &val)
std::string GetKey(const std::string §ion, const std::string &key, const std::string &defaultValue) const
returns the value of the given section/key or default value if it does not exists ...
UIntSet getActiveImages() const
get active images
void SetCanvas(const std::string &canvas, HuginBase::Panorama &pano, HuginBase::PanoramaOptions &options)
std::string tiffCompression
std::string verdandiOptions
bool outputLDRExposureLayers
save blended exposure layers, do not perform fusion (no exposure adjustment)
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
unsigned int getWidth() const
std::string enblendOptions
const PanoramaOptions & getOptions() const
returns the options for this panorama
bool CheckNumber(const Number variable, const std::string &operatorString, const Number value)
general number comparison function
virtual double getResultHorizontalFOV()
virtual vigra::Rect2D getResultOptimalROI()
returns the found crop rect
void ReadProjectionNames()
bool outputLDRExposureRemapped
save remapped layers (no exposure adjustment)
void SetHDRCompression(const std::string hdrCompression, HuginBase::PanoramaOptions &options)
bool outputLDRExposureLayersFused
save blended exposure layers which are then fused (no exposure adjustment)
int Read(const std::string &file)
Reads the given ini file.
bool readEXIF()
try to fill out information about the image, by examining the exif data
static std::map< HuginBase::BaseSrcPanoImage::Projection, std::string > lensTypeNames
std::string outputImageType
std::string outputImageTypeHDR
void SetCrop(const std::string &cropString, HuginBase::Panorama &pano, HuginBase::PanoramaOptions &options)
read settings from ini file and apply only applicable values
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
void setOptions(const PanoramaOptions &opt)
set new output settings This is not used directly for optimizing/stiching, but it can be feed into ru...
void setSrcImage(unsigned int nr, const SrcPanoImage &img)
set input image parameters
std::vector< std::string > SplitString(const std::string &s, const std::string &sep)
split string s at given sep, returns vector of strings
All variables of a source image.
void setProjection(ProjectionFormat f)
set the Projection format and adjust the hfov/vfov if nessecary
bool outputHDRStacks
save image stacks (HDR)
void SetLDRCompression(const std::string ldrCompression, HuginBase::PanoramaOptions &options)
BlendingMechanism blendMode
bool CheckDouble(const double variable, const std::string &operatorString, const std::string &stringValue)
check if given double matches the condition (operator and value)
std::string tolower(const std::string &s)
convert a string to lowercase
void SetExposure(const std::string &exposure, HuginBase::Panorama &pano, HuginBase::PanoramaOptions &options)
std::string stripPath(const std::string &filename)
remove the path of a filename (mainly useful for gui display of filenames)
void setWidth(unsigned int w, bool keepView=true)
set panorama width keep the HFOV, if keepView=true
double outputExposureValue
A simple parser for ini files, it implements only some basic features.