[53eab2]: src / hugin_cpfind / cpfind / PanoDetector.h Maximize Restore History

Download this file

PanoDetector.h    290 lines (229 with data), 10.3 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
// -*- c-basic-offset: 4 ; tab-width: 4 -*-
/*
* Copyright (C) 2007-2008 Anael Orlinski
*
* This file is part of Panomatic.
*
* Panomatic 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.
*
* Panomatic 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 Panomatic; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __detectpano_panodetector_h
#define __detectpano_panodetector_h
#include <hugin_config.h>
#include <hugin_version.h>
#include "PanoDetectorDefs.h"
#include <string>
#include <map>
#include <localfeatures/Image.h>
#include <localfeatures/PointMatch.h>
#include "TestCode.h"
#include <zthread/Runnable.h>
#include <zthread/PoolExecutor.h>
#include <localfeatures/KeyPoint.h>
#include <localfeatures/KeyPointDetector.h>
#include <flann/flann.hpp>
#include <vigra_ext/ROIImage.h>
#include <panodata/Panorama.h>
#include <algorithms/optimizer/PTOptimizer.h>
#include <celeste/Celeste.h>
using namespace HuginBase;
class PanoDetector
{
public:
typedef std::vector<std::string> FileNameList_t;
typedef std::vector<std::string>::iterator FileNameListIt_t;
typedef KDTreeSpace::KDTree<KDElemKeyPoint, double> KPKDTree;
typedef boost::shared_ptr<KPKDTree > KPKDTreePtr;
typedef lfeat::KeyPointDetector KeyPointDetector;
PanoDetector();
bool checkData();
void printDetails();
void printFilenames();
void printHelp();
void run();
bool match(ZThread::PoolExecutor& aExecutor);
bool matchMultiRow(ZThread::PoolExecutor& aExecutor);
// accessors
inline Panorama * getPanoramaInfo() const {return _panoramaInfo; }
inline void setKeyPointsIdx(std::vector<int> keyPointsIdx) { _keyPointsIdx = keyPointsIdx; }
inline std::vector<int> getKeyPointsIdx() const { return _keyPointsIdx; }
inline void setWriteAllKeyPoints(bool writeAllKeyPoints=true) { _writeAllKeyPoints = writeAllKeyPoints; }
inline bool getWriteAllKeyPoints() const { return _writeAllKeyPoints; }
inline void setGradientDescriptor(bool grad=true) { _gradDescriptor = grad; }
inline bool getGradientDescriptor() const { return _gradDescriptor; }
inline void setVerbose(int level) { _verbose = level; }
inline int getVerbose() const { return _verbose; }
inline void setSieve1Width(int iWidth) { _sieve1Width = iWidth; }
inline void setSieve1Height(int iHeight) { _sieve1Height = iHeight; }
inline void setSieve1Size(int iSize) { _sieve1Size = iSize; }
inline int getSieve1Width() const { return _sieve1Width; }
inline int getSieve1Height() const { return _sieve1Height; }
inline int getSieve1Size() const { return _sieve1Size; }
inline void setKDTreeSearchSteps(int iSteps) { _kdTreeSearchSteps = iSteps; }
inline void setKDTreeSecondDistance(double iDist) { _kdTreeSecondDistance = iDist; }
inline int getKDTreeSearchSteps() const { return _kdTreeSearchSteps; }
inline double getKDTreeSecondDistance() const { return _kdTreeSecondDistance; }
inline void setMinimumMatches(int iMatches) { _minimumMatches = iMatches; }
inline void setRansacIterations(int iIters) { _ransacIters = iIters; }
inline void setRansacDistanceThreshold(int iDT) { _ransacDistanceThres = iDT; }
inline void setRansacMode(RANSACOptimizer::Mode mode) { _ransacMode = mode; }
inline int getMinimumMatches() const { return _minimumMatches; }
inline int getRansacIterations() const { return _ransacIters; }
inline int getRansacDistanceThreshold() const { return _ransacDistanceThres; }
inline RANSACOptimizer::Mode setRansacMode() { return _ransacMode; }
inline void setSieve2Width(int iWidth) { _sieve2Width = iWidth; }
inline void setSieve2Height(int iHeight) { _sieve2Height = iHeight; }
inline void setSieve2Size(int iSize) { _sieve2Size = iSize; }
inline int getSieve2Width() const { return _sieve2Width; }
inline int getSieve2Height() const { return _sieve2Height; }
inline int getSieve2Size() const { return _sieve2Size; }
inline void setLinearMatch(bool iLin) { _linearMatch = iLin; }
inline void setLinearMatchLen(int iLen) { _linearMatchLen = iLen; }
inline bool getLinearMatch() const { return _linearMatch; }
inline int getLinearMatchLen() const { return _linearMatchLen; }
inline void setMultiRow(bool iMultirow) { _multirow = iMultirow; }
inline bool getMultiRow() const { return _multirow; }
inline bool getDownscale() const { return _downscale; }
inline void setDownscale(bool iDown) { _downscale = iDown; }
// inline void setNumberOfKeys(int iNumKeys) { _numKeys = iNumKeys; }
inline void setOutputFile(const std::string& outputFile) { _outputFile = outputFile; }
inline void setInputFile(const std::string& inputFile) { _inputFile = inputFile; }
inline void setKeyfilesPath(const std::string& keypath) { _keypath = keypath; }
inline bool getCached() const { return _cache; }
inline void setCached(bool iCached) { _cache = iCached; }
inline bool getCleanup() const { return _cleanup; }
inline void setCleanup(bool iCleanup) { _cleanup = iCleanup; }
inline bool getCeleste() const { return _celeste; };
inline void setCeleste(bool iCeleste) { _celeste = iCeleste; };
inline double getCelesteThreshold() const { return _celesteThreshold; };
inline void setCelesteThreshold(double iCelesteThreshold) { _celesteThreshold = iCelesteThreshold; };
inline int getCelesteRadius() const { return _celesteRadius; };
inline void setCelesteRadius(int iCelesteRadius) { _celesteRadius = iCelesteRadius; };
inline void setTest(bool iTest) { _test = iTest; }
inline bool getTest() const { return _test; }
inline void setCores(int iCores) { _cores = iCores; }
// predeclaration
struct ImgData;
struct MatchData;
private:
// options
bool _writeAllKeyPoints;
std::vector<int> _keyPointsIdx;
bool _gradDescriptor;
int _verbose;
int _sieve1Width;
int _sieve1Height;
int _sieve1Size;
int _kdTreeSearchSteps;
double _kdTreeSecondDistance;
int _minimumMatches;
RANSACOptimizer::Mode _ransacMode;
int _ransacIters;
int _ransacDistanceThres;
int _sieve2Width;
int _sieve2Height;
int _sieve2Size;
bool _linearMatch;
int _linearMatchLen;
bool _multirow;
bool _test;
int _cores;
bool _downscale;
bool _cache;
bool _cleanup;
bool _celeste;
double _celesteThreshold;
int _celesteRadius;
std::string _keypath;
std::string _prefix;
// bool _stereoRemap;
// list of files
std::string _outputFile;
std::string _inputFile;
// Store panorama information
Panorama* _panoramaInfo;
Panorama _panoramaInfoCopy;
// void prepareImages();
bool loadProject();
// void loadImages();
// void remapBackMatches();
bool checkLoadSuccess();
void CleanupKeyfiles();
void prepareMatches();
void writeOutput();
void writeKeyfile(ImgData& imgInfo);
ZThread::FastMutex aPanoMutex;
// internals
public:
struct ImgData
{
std::string _name;
int _number;
int _detectWidth;
int _detectHeight;
lfeat::Image _ii;
vigra::BImage _distancemap;
bool _needsremap;
PanoramaOptions _projOpts;
bool _hasakeyfile;
std::string _keyfilename;
lfeat::KeyPointVect_t _kp;
int _descLength;
bool _loadFail;
// kdtree
flann::Matrix<double> _flann_descriptors;
flann::Index<flann::L2<double> > * _flann_index;
};
typedef std::map<int, ImgData> ImgData_t;
typedef std::map<int, ImgData>::iterator ImgDataIt_t;
struct MatchData
{
ImgData* _i1;
ImgData* _i2;
lfeat::PointMatchVector_t _matches;
};
typedef std::vector<MatchData> MatchData_t;
typedef std::vector<MatchData>::iterator MatchDataIt_t;
// actions
static bool LoadKeypoints(ImgData & ioImgInfo, const PanoDetector& iPanoDetector);
static bool AnalyzeImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
static bool FindKeyPointsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
static bool FilterKeyPointsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
static bool MakeKeyPointDescriptorsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
static bool RemapBackKeypoints(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
static bool BuildKDTreesInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
static bool FreeMemoryInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
static bool FindMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
static bool RansacMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
static bool RansacMatchesInPairCam(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
static bool RansacMatchesInPairHomography(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
static bool FilterMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
private:
bool LoadSVMModel();
ImgData_t _filesData;
MatchData_t _matchesData;
struct celeste::svm_model* svmModel;
};
/** returns the filename for the keyfile for a given image */
std::string getKeyfilenameFor(std::string keyfilesPath, std::string filename);
// dummy panotools progress functions
static int ptProgress( int command, char* argument )
{
return 1;
}
static int ptinfoDlg( int command, char* argument )
{
return 1;
}
#endif // __detectpano_panodetector_h