28 #include <hugin_config.h>
48 static void usage(
const char* name)
50 std::cout << name <<
": optimize image positions" << std::endl
53 <<
"Usage: " << name <<
" [options] input.pto" << std::endl
54 <<
" To read a project from stdio, specify - as input file." << std::endl
56 <<
" Options:" << std::endl
57 <<
" -o file.pto output file. If omitted, stdout is used." << std::endl
59 <<
" Optimisation options (if not specified, no optimisation takes place)" << std::endl
60 <<
" -a auto align mode, includes various optimisation stages, depending" << std::endl
61 <<
" on the amount and distribution of the control points" << std::endl
62 <<
" -p pairwise optimisation of yaw, pitch and roll, starting from" << std::endl
63 <<
" first image" << std::endl
64 <<
" -m Optimise photometric parameters" << std::endl
65 <<
" -n Optimize parameters specified in script file (like PTOptimizer)" << std::endl
67 <<
" Postprocessing options:" << std::endl
68 <<
" -l level horizon (works best for horizontal panos)" << std::endl
69 <<
" -s automatically select a suitable output projection and size" << std::endl
70 <<
" Other options:" << std::endl
71 <<
" -q quiet operation (no progress is reported)" << std::endl
72 <<
" -v HFOV specify horizontal field of view of input images." << std::endl
73 <<
" Used if the .pto file contains invalid HFOV values" << std::endl
74 <<
" (autopano-SIFT writes .pto files with invalid HFOV)" << std::endl
76 <<
" --only-active-images take only active images into account when" << std::endl
77 <<
" optimising (only valid with -n switch)" << std::endl
79 <<
" When using -a -l -m and -s options together, a similar operation to the" << std::endl
80 <<
" \"Align\" button in hugin is performed." << std::endl
84 int main(
int argc,
char* argv[])
87 const char* optstring =
"alho:npqsv:m";
91 SWITCH_ONLY_ACTIVE=1000
93 static struct option longOptions[] =
95 {
"output", required_argument, NULL,
'o'},
96 {
"help", no_argument, NULL,
'h' },
97 {
"only-active-images", no_argument, NULL, SWITCH_ONLY_ACTIVE},
101 bool doPairwise =
false;
102 bool doAutoOpt =
false;
103 bool doNormalOpt =
false;
104 bool optOnlyActive =
false;
105 bool doLevel =
false;
106 bool chooseProj =
false;
108 bool doPhotometric =
false;
110 while ((c = getopt_long(argc, argv, optstring, longOptions,
nullptr)) != -1)
142 doPhotometric =
true;
144 case SWITCH_ONLY_ACTIVE:
145 optOnlyActive =
true;
158 if (argc - optind != 1)
160 if (argc - optind < 1)
171 const char* scriptFile = argv[optind];
181 std::cerr <<
"Panorama should consist of at least one image" << std::endl;
190 && img.getHFOV() >= 180)
193 std::cerr <<
"HFOV of image " << img.getFilename() <<
" invalid, trying to read EXIF tags" << std::endl;
204 std::cerr <<
"EXIF reading failed, please specify HFOV with -v" << std::endl;
216 std::cerr <<
"Panorama have to have control points to optimise positions" << std::endl;
219 if (doPairwise && ! doAutoOpt)
227 std::cerr <<
"*** Pairwise position optimisation" << std::endl;
235 std::cerr <<
"*** Adaptive geometric optimisation" << std::endl;
239 else if (doNormalOpt)
245 std::cerr <<
"*** Optimising parameters specified in PTO file (active images only)" << std::endl;
249 if (activeImages.empty())
251 std::cerr <<
"*** Image contains no active images. Nothing to do." << std::endl;
266 std::cerr <<
"*** Optimising parameters specified in PTO file" << std::endl;
275 std::cerr <<
"*** Geometric parameters not optimized" << std::endl;
281 bool hasVerticalLines=
false;
283 if(!allCP.empty() && (doPairwise || doAutoOpt || doNormalOpt))
285 for(
size_t i=0; i<allCP.size() && !hasVerticalLines; i++)
293 std::cout <<
"Skipping automatic leveling because of existing vertical control points." << std::endl;
315 const double vfov = opts.
getVFOV();
316 const double hfov = opts.
getHFOV();
318 const double mf = 100;
319 bool changedProjection=
false;
323 switch (pano.
getImage(0).getProjection())
330 changedProjection =
true;
340 changedProjection =
true;
349 changedProjection =
true;
365 changedProjection =
true;
373 changedProjection =
true;
383 changedProjection =
true;
389 if(changedProjection)
399 const double sizeFactor = 0.7;
412 std::vector<vigra_ext::PointPairRGB> points;
427 catch (std::exception& e)
429 std::cerr <<
"caught exception: " << e.what() << std::endl;
434 std::cout <<
"\rSelected " << points.size() <<
" points" << std::endl;
439 std::cerr <<
"Error: no overlapping points found, exiting" << std::endl;
443 progressDisplay->
setMessage(
"Photometric Optimization");
447 HuginBase::ImageVariableGroup::IVE_EMoRParams,
448 HuginBase::ImageVariableGroup::IVE_ResponseType,
449 HuginBase::ImageVariableGroup::IVE_VigCorrMode,
450 HuginBase::ImageVariableGroup::IVE_RadialVigCorrCoeff,
451 HuginBase::ImageVariableGroup::IVE_RadialVigCorrCenterShift
457 std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> links_needed;
458 links_needed.clear();
459 for (
int v = 0; v < 5; v++)
463 links_needed.insert(vars[v]);
466 if (!links_needed.empty())
468 std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator it;
469 for (it = links_needed.begin(); it != links_needed.end(); ++it)
490 delete progressDisplay;
497 std::cout <<
"Written output to " << output << std::endl;
bool getVarLinkedInPart(ImageVariableEnum variable, std::size_t part) const
Get the linked status of a particular variable for a given part number.
PanoramaOptions::ProjectionFormat getProjection() const
Dummy progress display, without output.
void updateOptimizeVector()
updates the optimize vector according to master switches
bool applyEXIFValues(bool applyEVValue=true)
apply values found in EXIF data to SrcPanoImage class, call readEXIF() before to initialize some valu...
void setHeight(unsigned int h)
set panorama height
static double calcMeanExposure(const PanoramaData &pano)
SrcPanoImage getSrcImage(unsigned imgNr) const
get a description of a source image
std::string GetOutputFilename(const std::string &out, const std::string &in, const std::string &suffix)
construct output filename, if ouput is known return this value otherwise use the input filename and a...
static void smartOptimize(PanoramaData &pano)
ImageVariableGroup & getStacks()
Get the ImageVariableGroup representing the group of stack variables.
Somewhere to specify what variables belong to what.
std::size_t getNrOfCtrlPoints() const
number of control points
PhotometricOptimizeMode
local optimize definition.
virtual void run()
runs the algorithm.
Panorama getSubset(const UIntSet &imgs) const
get a subset of the panorama
const CPVector & getCtrlPoints() const
get all control point of this Panorama
virtual void updateVariables(const VariableMapVector &vars)
Set the variables.
Declare the ImageVariableGroup and ImageVariableGroupObserver classes.
void linkVariablePart(ImageVariableEnum variable, unsigned int partNr)
link one of the variables across a given part
std::set< unsigned int > UIntSet
void taskFinished()
call when a task has finished and the status message should be cleared
std::string getPathPrefix(const std::string &filename)
Get the path to a filename.
const OptimizeVector & getOptimizeVector() const
return the optimize settings stored inside panorama
VariableMapVector getVariables() const
get variables of this panorama
std::size_t getNrOfImages() const
number of images.
static double calcOptimalScale(PanoramaData &panorama)
bool ReadPTOFile(const std::string &filename, const std::string &prefix="")
read pto file from the given filename into Panorama object it does some checks on the file and issues...
virtual double getResultHeight()
ImageVariableGroup & getLenses()
Get the ImageVariableGroup representing the group of lens variables.
void setMessage(const std::string &message, const std::string &filename="")
sets the message to given string
evaluate x, points are on a vertical line
!! from PTOptimise.h 1951
UIntSet getActiveImages() const
get active images
Same as above, but use a non const panorama.
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
unsigned int getWidth() const
const PanoramaOptions & getOptions() const
returns the options for this panorama
virtual double getResultHorizontalFOV()
bool readEXIF()
try to fill out information about the image, by examining the exif data
std::string GetHuginVersion()
return a string with version numbers
std::vector< ControlPoint > CPVector
bool WritePTOFile(const std::string &filename, const std::string &prefix="")
write data to given pto file
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::size_t getNumberOfParts() const
get the number of parts.
All variables of a source image.
void setProjection(ProjectionFormat f)
set the Projection format and adjust the hfov/vfov if nessecary
a progress display to print progress reports to a stream
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
static void autoOptimise(PanoramaData &pano, bool optRoll=true)
double outputExposureValue
int main(int argc, char *argv[])