[e7ef77]: src / tools / checkpto.cpp  Maximize  Restore  History

Download this file

311 lines (291 with data), 10.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// -*- c-basic-offset: 4 -*-
/** @file checkpto.cpp
*
* @brief helper program for assistant makefile
*
*
* @author Thomas Modes
*
*/
/* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <hugin_version.h>
#include <hugin_config.h>
#include <fstream>
#include <sstream>
#include <getopt.h>
#include <panodata/Panorama.h>
#include "algorithms/optimizer/ImageGraph.h"
#include "hugin_base/panotools/PanoToolsUtils.h"
#include "algorithms/basic/CalculateCPStatistics.h"
#include "algorithms/basic/LayerStacks.h"
using namespace std;
using namespace HuginBase;
using namespace AppBase;
static void usage(const char * name)
{
cout << name << ": report the number of image groups in a project" << endl
<< name << " version " << DISPLAY_VERSION << endl
<< endl
<< "Usage: " << name << " input.pto" << endl
<< endl
<< name << " examines the connections between images in a project and" << endl
<< "reports back the number of parts or image groups in that project" << endl
<< endl
<< "Further switches:" << endl
<< " --print-output-info Print more information about the output" << endl
<< " --generate-argfile=file Generate Exiftool argfile" << endl
#ifdef EXIFTOOL_GPANO_SUPPORT
<< " --no-gpano Don't include GPano tags in argfile" << endl
#endif
<< endl
<< name << " is used by the assistant and by the stitching makefiles" << endl
<< endl;
}
void printImageGroup(const std::vector<HuginBase::UIntSet> &imageGroup)
{
for (size_t i=0; i < imageGroup.size(); i++)
{
std::cout << "[";
size_t c=0;
for (HuginBase::UIntSet::const_iterator it = imageGroup[i].begin(); it != imageGroup[i].end(); ++it)
{
std::cout << (*it);
if (c+1 != imageGroup[i].size())
{
std::cout << ", ";
}
++c;
}
std::cout << "]";
if (i+1 != imageGroup.size())
{
std::cout << ", " << endl;
}
}
};
void GenerateArgfile(const std::string & filename, const Panorama &pano, bool noGPano)
{
pano_projection_features proj;
PanoramaOptions opts=pano.getOptions();
bool readProjectionName=panoProjectionFeaturesQuery(opts.getProjection(), &proj)!=0;
std::ofstream infostream(filename.c_str(), std::ofstream::out);
infostream.imbue(std::locale("C"));
infostream << fixed;
#ifdef _WIN32
std::string linebreak("&\\#xd;&\\#xa;");
#else
std::string linebreak("&\\#xa;");
#endif
infostream << "-Software=Hugin " << DISPLAY_VERSION << std::endl;
infostream << "-E" << std::endl;
infostream << "-UserComment<${UserComment}" << linebreak;
if(readProjectionName)
{
infostream << "Projection: " << proj.name << " (" << opts.getProjection() << ")" << linebreak;
};
infostream << "FOV: " << setprecision(0) << opts.getHFOV() << " x " << setprecision(0) << opts.getVFOV() << linebreak;
infostream << "Ev: " << setprecision(2) << opts.outputExposureValue << std::endl;
infostream << "-f" << std::endl;
if(!noGPano)
{
//GPano tags are only indented for equirectangular images
if(opts.getProjection()==PanoramaOptions::EQUIRECTANGULAR)
{
vigra::Rect2D roi=opts.getROI();
int left=roi.left();
int top=roi.top();
int width=roi.width();
int height=roi.height();
int fullWidth=opts.getWidth();
if(opts.getHFOV()<360)
{
fullWidth=static_cast<int>(opts.getWidth() * 360.0 / opts.getHFOV());
left += (fullWidth - opts.getWidth())/2;
};
int fullHeight=opts.getHeight();
if(opts.getVFOV()<180)
{
fullHeight=static_cast<int>(opts.getHeight() * 180.0 / opts.getVFOV());
top += (fullHeight - opts.getHeight())/2;
};
infostream << "-UsePanoramaViewer=True" << std::endl;
infostream << "-StitchingSoftware=Hugin" << std::endl;
infostream << "-ProjectionType=equirectangular" << std::endl;
infostream << "-CroppedAreaLeftPixels=" << left << std::endl;
infostream << "-CroppedAreaTopPixels=" << top << std::endl;
infostream << "-CroppedAreaImageWidthPixels=" << width << std::endl;
infostream << "-CroppedAreaImageHeightPixels=" << height << std::endl;
infostream << "-FullPanoWidthPixels=" << fullWidth << std::endl;
infostream << "-FullPanoHeightPixels=" << fullHeight << std::endl;;
infostream << "-SourcePhotosCount=" << pano.getNrOfImages() << std::endl;
};
};
infostream.close();
};
int main(int argc, char *argv[])
{
// parse arguments
const char * optstring = "h";
enum
{
PRINT_OUTPUT_INFO=1000,
GENERATE_ARGFILE=1001,
#if EXIFTOOL_GPANO_SUPPORT
GENERATE_ARGFILE_WITHOUT_GPANO=1002,
#endif
};
static struct option longOptions[] =
{
{"print-output-info", no_argument, NULL, PRINT_OUTPUT_INFO },
{"generate-argfile", required_argument, NULL, GENERATE_ARGFILE},
#ifdef EXIFTOOL_GPANO_SUPPORT
{"no-gpano", no_argument, NULL, GENERATE_ARGFILE_WITHOUT_GPANO},
#endif
{"help", no_argument, NULL, 'h' },
0
};
int c;
bool printOutputInfo=false;
#ifdef EXIFTOOL_GPANO_SUPPORT
bool withoutGPano=false;
#else
bool withoutGPano=true;
#endif
std::string argfile;
int optionIndex = 0;
while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1)
{
switch (c) {
case 'h':
usage(argv[0]);
return 0;
case PRINT_OUTPUT_INFO:
printOutputInfo=true;
break;
case GENERATE_ARGFILE:
argfile=optarg;
break;
#ifdef EXIFTOOL_GPANO_SUPPORT
case GENERATE_ARGFILE_WITHOUT_GPANO:
withoutGPano=true;
break;
#endif
case '?':
break;
default:
abort ();
}
}
if (argc - optind != 1)
{
usage(argv[0]);
return -1;
};
string input=argv[optind];
Panorama pano;
ifstream prjfile(input.c_str());
if (!prjfile.good()) {
cerr << "could not open script : " << input << endl;
return -1;
}
pano.setFilePrefix(hugin_utils::getPathPrefix(input));
DocumentData::ReadWriteError err = pano.readData(prjfile);
if (err != DocumentData::SUCCESSFUL) {
cerr << "error while parsing panos tool script: " << input << endl;
cerr << "DocumentData::ReadWriteError code: " << err << endl;
return -1;
}
if(!argfile.empty())
{
GenerateArgfile(argfile, pano, withoutGPano);
return 0;
};
std::cout << endl
<< "Opened project " << input << endl << endl
<< "Project contains" << endl
<< pano.getNrOfImages() << " images" << endl
<< pano.getNrOfCtrlPoints() << " control points" << endl << endl;
//cp statistics
if(pano.getNrOfCtrlPoints()>0)
{
double min;
double max;
double mean;
double var;
HuginBase::PTools::calcCtrlPointErrors(pano);
CalculateCPStatisticsError::calcCtrlPntsErrorStats(pano, min, max, mean, var);
if(max>0)
{
std::cout << "Control points statistics" << std::endl
<< fixed << std::setprecision(2)
<< "\tMean error : " << mean << std::endl
<< "\tStandard deviation: " << sqrt(var) << std::endl
<< "\tMinimum : " << min << std::endl
<< "\tMaximum : " << max << std::endl;
};
};
CPGraph graph;
createCPGraph(pano, graph);
CPComponents comps;
int n = findCPComponents(graph, comps);
int returnValue=0;
if(n==1)
{
std::cout << "All images are connected." << endl;
// return value must be 0, otherwise the assistant does not continue
returnValue=0;
}
else
{
std::cout << "Found unconnected images!" << endl
<< "There are " << n << " image groups." << endl;
std::cout << "Image groups: " << endl;
for (unsigned i=0; i < comps.size(); i++)
{
std::cout << "[";
CPComponents::value_type::const_iterator it;
size_t c=0;
for (it = comps[i].begin(); it != comps[i].end(); ++it)
{
std::cout << (*it);
if (c+1 != comps[i].size())
{
std::cout << ", ";
}
c++;
}
std::cout << "]";
if (i+1 != comps.size())
{
std::cout << ", " << endl;
}
}
returnValue=n;
};
if(printOutputInfo)
{
HuginBase::UIntSet outputImages=HuginBase::getImagesinROI(pano, pano.getActiveImages());
std::vector<HuginBase::UIntSet> stacks=HuginBase::getHDRStacks(pano, outputImages, pano.getOptions());
cout << endl << "Output contains" << endl
<< stacks.size() << " images stacks:" << endl;
printImageGroup(stacks);
std::vector<HuginBase::UIntSet> layers=HuginBase::getExposureLayers(pano, outputImages, pano.getOptions());
cout << endl << endl << "and " << layers.size() << " exposure layers:" << std::endl;
printImageGroup(layers);
};
return returnValue;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks