Hugin trunk 0.1
Loading...
Searching...
No Matches
hsi_PhotometricOptimizer.cpp
Go to the documentation of this file.
1
18
19#include <fstream>
20#include <stdexcept>
21#include <vector>
22
28
29// header-only helper shared with autooptimiser/vig_optimize, loads the
30// source images and samples point correspondences across their overlaps
31#include <tools/ExtractPoints.h>
32
33namespace HuginBase
34{
35
36namespace
37{
38// loadImgsAndExtractPoints() loads images inside a #pragma omp parallel
39// for loop; an exception (e.g. vigra::PreconditionViolation for a missing
40// file) thrown from within that loop cannot cross the OpenMP boundary and
41// aborts the process instead of propagating. Check what we can up front,
42// outside any parallel region, so the common failure (bad path) raises a
43// normal exception instead.
44void CheckImagesReadable(const Panorama& pano)
45{
46 for (size_t i = 0; i < pano.getNrOfImages(); i++)
47 {
48 const std::string filename = pano.getImage(i).getFilename();
49 std::ifstream f(filename.c_str());
50 if (!f.good())
51 {
52 throw std::runtime_error("cannot open image file: " + filename);
53 }
54 }
55}
56} // namespace
57
59{
61
63
64 const int nPoints = 200 * static_cast<int>(pano.getNrOfImages());
65 std::vector<vigra_ext::PointPairRGB> points;
66 float imageStepSize;
67 loadImgsAndExtractPoints(pano, nPoints, 3, true, progress, points, 0, imageStepSize);
68
69 if (points.empty())
70 {
71 throw std::runtime_error("no overlapping points found for photometric optimization");
72 }
73
74 // ensure vignetting and response coefficients are linked across each lens,
75 // so the optimizer treats all images from the same lens consistently
77 {
78 ImageVariableGroup::IVE_EMoRParams,
79 ImageVariableGroup::IVE_ResponseType,
80 ImageVariableGroup::IVE_VigCorrMode,
81 ImageVariableGroup::IVE_RadialVigCorrCoeff,
82 ImageVariableGroup::IVE_RadialVigCorrCenterShift
83 };
86 for (size_t i = 0; i < lenses.getNumberOfParts(); i++)
87 {
88 for (const auto var : linkedVars)
89 {
90 if (!lenses.getVarLinkedInPart(var, i))
91 {
93 }
94 }
95 }
96
97 PanoramaOptions opts = pano.getOptions();
101 variableGroups.getStacks().getNumberOfParts() < pano.getNrOfImages())
102 {
104 }
105
107 photoOpt.run();
108
110 pano.setOptions(opts);
111
112 return photoOpt.getResultError();
113}
114
115} // namespace HuginBase
helper procedure for photometric optimizer on command line
void loadImgsAndExtractPoints(HuginBase::Panorama pano, int nPoints, int pyrLevel, bool randomPoints, AppBase::ProgressDisplay &progress, std::vector< vigra_ext::PointPairRGB > &points, int verbose, float &imageStepSize)
Declare the ImageVariableGroup and ImageVariableGroupObserver classes.
Somewhere to specify what variables belong to what.
Dummy progress display, without output.
static double calcMeanExposure(const PanoramaData &pano)
Same as above, but use a non const panorama.
void linkVariablePart(ImageVariableEnum variable, unsigned int partNr)
link one of the variables across a given part
Panorama image options.
Model for a panorama.
Definition Panorama.h:153
const PanoramaOptions & getOptions() const
returns the options for this panorama
Definition Panorama.h:481
void setOptions(const PanoramaOptions &opt)
set new output settings This is not used directly for optimizing/stiching, but it can be feed into ru...
const OptimizeVector & getOptimizeVector() const
return the optimize settings stored inside panorama
Definition Panorama.h:454
std::size_t getNrOfImages() const
number of images.
Definition Panorama.h:205
PhotometricOptimizeMode
local optimize definition.
run photometric optimization on a Panorama, for the hsi Python module
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
double RunPhotometricOptimizer(Panorama &pano)
Loads pano's source images from disk, samples corresponding points across overlapping images and runs...
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41