Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[9f824a]: src / tools / nona.cpp Maximize Restore History

Download this file

nona.cpp    283 lines (250 with data), 9.6 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
// -*- c-basic-offset: 4 -*-
/** @file nona.cpp
*
* @brief a simple test stitcher
*
* @author Pablo d'Angelo <pablo.dangelo@web.de>
*
* $Id$
*
* 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_config.h>
#include <hugin_version.h>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cctype>
#include <string>
#include <vigra/error.hxx>
#include <vigra/impex.hxx>
#ifdef WIN32
#include <getopt.h>
#else
#include <unistd.h>
#endif
#include <hugin_basic.h>
#include <hugin_utils/platform.h>
#include <algorithms/nona/NonaFileStitcher.h>
#include <vigra_ext/MultiThreadOperations.h>
#include <tiffio.h>
using namespace vigra;
using namespace HuginBase;
using namespace hugin_utils;
using namespace std;
static void usage(const char * name)
{
cerr << name << ": stitch a panorama image" << std::endl
<< std::endl
<< "nona version " << PACKAGE_VERSION << std::endl
<< std::endl
<< " It uses the transform function from PanoTools, the stitching itself" << std::endl
<< " is quite simple, no seam feathering is done." << std::endl
<< " only the non-antialiasing interpolators of panotools are supported" << std::endl
<< std::endl
<< " The following output formats (n option of panotools p script line)" << std::endl
<< " are supported:"<< std::endl
<< std::endl
<< " JPG, TIFF, PNG : Single image formats without feathered blending:"<< std::endl
<< " TIFF_m : multiple tiff files"<< std::endl
<< " TIFF_multilayer : Multilayer tiff files, readable by The Gimp 2.0" << std::endl
<< std::endl
<< "Usage: " << name << " [options] -o output project_file (image files)" << std::endl
<< " Options: " << std::endl
<< " -c create coordinate images (only TIFF_m output)" << std::endl
<< " -v quiet, do not output progress indicators" << std::endl
<< " -t num number of threads to be used (default: nr of available cores)" << std::endl
<< std::endl
<< " The following options can be used to override settings in the project file:" << std::endl
<< " -i num remap only image with number num" << std::endl
<< " (can be specified multiple times)" << std::endl
<< " -m str set output file format (TIFF, TIFF_m, TIFF_multilayer, EXR, EXR_m)" << std::endl
<< " -r ldr/hdr set output mode." << std::endl
<< " ldr keep original bit depth and response" << std::endl
<< " hdr merge to hdr" << std::endl
<< " -e exposure set exposure for ldr mode" << std::endl
<< " -p TYPE pixel type of the output. Can be one of:" << std::endl
<< " UINT8 8 bit unsigned integer" << std::endl
<< " UINT16 16 bit unsigned integer" << std::endl
<< " INT16 16 bit signed integer" << std::endl
<< " UINT32 32 bit unsigned integer" << std::endl
<< " INT32 32 bit signed integer" << std::endl
<< " FLOAT 32 bit floating point" << std::endl
<< " -z set compression type." << std::endl
<< " Possible options for tiff output:" << std::endl
<< " NONE no compression" << std::endl
<< " PACKBITS packbits compression" << std::endl
<< " LZW lzw compression" << std::endl
<< " DEFLATE deflate compression" << std::endl
<< std::endl;
}
int main(int argc, char *argv[])
{
// parse arguments
const char * optstring = "z:cho:i:t:m:p:r:e:v";
int c;
opterr = 0;
int nThread = getCPUCount();
if (nThread < 0) nThread = 1;
bool doCoord = false;
UIntSet outputImages;
string basename;
string outputFormat;
bool overrideOutputMode = false;
std::string compression;
PanoramaOptions::OutputMode outputMode = PanoramaOptions::OUTPUT_LDR;
bool overrideExposure = false;
double exposure=0;
int verbose = 0;
string outputPixelType;
while ((c = getopt (argc, argv, optstring)) != -1)
{
switch (c) {
case 'o':
basename = optarg;
break;
case 'c':
doCoord = true;
break;
case 'i':
outputImages.insert(atoi(optarg));
break;
case 'm':
outputFormat = optarg;
break;
case 'p':
outputPixelType = optarg;
break;
case 'r':
if (string(optarg) == "ldr") {
overrideOutputMode = true;
outputMode = PanoramaOptions::OUTPUT_LDR;
} else if (string(optarg) == "hdr") {
overrideOutputMode = true;
outputMode = PanoramaOptions::OUTPUT_HDR;
} else {
usage(argv[0]);
return 1;
}
break;
case 'e':
overrideExposure = true;
exposure = atof(optarg);
break;
case '?':
case 'h':
usage(argv[0]);
return 1;
case 't':
nThread = atoi(optarg);
break;
case 'v':
++verbose;
break;
case 'z':
compression = optarg;
std::transform(compression.begin(), compression.end(), compression.begin(), (int(*)(int)) toupper);
break;
default:
usage(argv[0]);
abort ();
}
}
if (basename == "" || argc - optind <1) {
usage(argv[0]);
return 1;
}
unsigned nCmdLineImgs = argc -optind -1;
if (nThread == 0) nThread = 1;
vigra_ext::ThreadManager::get().setNThreads(nThread);
const char * scriptFile = argv[optind];
// suppress tiff warnings
TIFFSetWarningHandler(0);
AppBase::ProgressDisplay* pdisp = NULL;
if(verbose > 0)
pdisp = new AppBase::StreamProgressDisplay(cout);
else
pdisp = new AppBase::DummyProgressDisplay;
Panorama pano;
ifstream prjfile(scriptFile);
if (prjfile.bad()) {
cerr << "could not open script : " << scriptFile << std::endl;
exit(1);
}
pano.setFilePrefix(hugin_utils::getPathPrefix(scriptFile));
AppBase::DocumentData::ReadWriteError err = pano.readData(prjfile);
if (err != AppBase::DocumentData::SUCCESSFUL) {
cerr << "error while parsing panos tool script: " << scriptFile << std::endl;
exit(1);
}
if ( nCmdLineImgs > 0) {
if (nCmdLineImgs != pano.getNrOfImages()) {
cerr << "Incorrect number of images specified on command line\nProject required " << pano.getNrOfImages() << " but " << nCmdLineImgs << " where given" << std::endl;
exit(1);
}
for (unsigned i=0; i < pano.getNrOfImages(); i++) {
pano.setImageFilename(i, argv[optind+i+1]);
}
}
PanoramaOptions opts = pano.getOptions();
if (compression.size() > 0) {
opts.tiffCompression=compression;
}
// save coordinate images, if requested
opts.saveCoordImgs = doCoord;
if (outputFormat == "TIFF_m") {
opts.outputFormat = PanoramaOptions::TIFF_m;
} else if (outputFormat == "TIFF") {
opts.outputFormat = PanoramaOptions::TIFF;
} else if (outputFormat == "TIFF_multilayer") {
opts.outputFormat = PanoramaOptions::TIFF_multilayer;
} else if (outputFormat == "EXR_m") {
opts.outputFormat = PanoramaOptions::EXR_m;
} else if (outputFormat == "EXR") {
opts.outputFormat = PanoramaOptions::EXR;
} else if (outputFormat != "") {
cerr << "Error: unknown output format: " << outputFormat << endl;
return 1;
}
if (outputPixelType.size() > 0) {
opts.outputPixelType = outputPixelType;
}
if (overrideOutputMode) {
opts.outputMode = outputMode;
}
if (overrideExposure) {
opts.outputExposureValue = exposure;
}
DEBUG_DEBUG("output basename: " << basename);
pano.setOptions(opts);
try {
// stitch panorama
if (outputImages.size() == 0 ) {
outputImages = pano.getActiveImages();
}
NonaFileOutputStitcher(pano, pdisp, opts, outputImages, basename).run();
// add a final newline, after the last progress message
if (verbose > 0) {
cout << std::endl;
}
} catch (std::exception & e) {
cerr << "caught exception: " << e.what() << std::endl;
return 1;
}
if(pdisp != NULL)
delete pdisp;
return 0;
}