Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PanoDetector.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 ; tab-width: 4 -*-
2 /*
3 * Copyright (C) 2007-2008 Anael Orlinski
4 *
5 * This file is part of Panomatic.
6 *
7 * Panomatic is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * Panomatic is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Panomatic; if not, write to the Free Software
19 * <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifndef __detectpano_panodetector_h
23 #define __detectpano_panodetector_h
24 
25 #include <hugin_config.h>
26 
27 #include "PanoDetectorDefs.h"
28 #include <memory>
29 #include <string>
30 #include <map>
31 #include <localfeatures/Image.h>
33 #include "TestCode.h"
34 
35 #include <localfeatures/KeyPoint.h>
37 
38 #include <flann/flann.hpp>
39 
40 #include <vigra_ext/ROIImage.h>
41 
42 #include <panodata/Panorama.h>
44 #include <celeste/Celeste.h>
45 
47 {
48 public:
49  typedef std::vector<std::string> FileNameList_t;
50  typedef std::vector<std::string>::iterator FileNameListIt_t;
52  typedef std::shared_ptr<KPKDTree> KPKDTreePtr;
53 
55 
58  {
63  };
64 
65  PanoDetector();
66  ~PanoDetector();
67 
68  bool checkData();
69  void printDetails();
70  void printFilenames();
71  void printHelp();
72  void run();
73  bool match(std::vector<HuginBase::UIntSet> &checkedPairs);
74  bool matchMultiRow();
84  bool matchPrealigned(HuginBase::Panorama* pano, std::vector<HuginBase::UIntSet> &connectedImages, std::vector<size_t> imgMap, bool exactOverlap=true);
85 
86 
87  // accessors
88 
90  {
91  return _panoramaInfo;
92  }
93 
94  inline void setKeyPointsIdx(std::vector<int> keyPointsIdx)
95  {
96  _keyPointsIdx = keyPointsIdx;
97  }
98  inline std::vector<int> getKeyPointsIdx() const
99  {
100  return _keyPointsIdx;
101  }
102  inline void setWriteAllKeyPoints(bool writeAllKeyPoints=true)
103  {
104  _writeAllKeyPoints = writeAllKeyPoints;
105  }
106  inline bool getWriteAllKeyPoints() const
107  {
108  return _writeAllKeyPoints;
109  }
110 
111  inline void setVerbose(int level)
112  {
113  _verbose = level;
114  }
115  inline int getVerbose() const
116  {
117  return _verbose;
118  }
119 
120  inline void setSieve1Width(int iWidth)
121  {
122  _sieve1Width = iWidth;
123  }
124  inline void setSieve1Height(int iHeight)
125  {
126  _sieve1Height = iHeight;
127  }
128  inline void setSieve1Size(int iSize)
129  {
130  _sieve1Size = iSize;
131  }
132  inline int getSieve1Width() const
133  {
134  return _sieve1Width;
135  }
136  inline int getSieve1Height() const
137  {
138  return _sieve1Height;
139  }
140  inline int getSieve1Size() const
141  {
142  return _sieve1Size;
143  }
144 
145  inline void setKDTreeSearchSteps(int iSteps)
146  {
147  _kdTreeSearchSteps = iSteps;
148  }
149  inline void setKDTreeSecondDistance(double iDist)
150  {
151  _kdTreeSecondDistance = iDist;
152  }
153  inline int getKDTreeSearchSteps() const
154  {
155  return _kdTreeSearchSteps;
156  }
157  inline double getKDTreeSecondDistance() const
158  {
159  return _kdTreeSecondDistance;
160  }
161 
162  inline void setMinimumMatches(int iMatches)
163  {
164  _minimumMatches = iMatches;
165  }
166  inline void setRansacIterations(int iIters)
167  {
168  _ransacIters = iIters;
169  }
170  inline void setRansacDistanceThreshold(int iDT)
171  {
172  _ransacDistanceThres = iDT;
173  }
175  {
176  _ransacMode = mode;
177  }
178  inline int getMinimumMatches() const
179  {
180  return _minimumMatches;
181  }
182  inline int getRansacIterations() const
183  {
184  return _ransacIters;
185  }
186  inline int getRansacDistanceThreshold() const
187  {
188  return _ransacDistanceThres;
189  }
191  {
192  return _ransacMode;
193  }
194 
195  inline void setSieve2Width(int iWidth)
196  {
197  _sieve2Width = iWidth;
198  }
199  inline void setSieve2Height(int iHeight)
200  {
201  _sieve2Height = iHeight;
202  }
203  inline void setSieve2Size(int iSize)
204  {
205  _sieve2Size = iSize;
206  }
207  inline int getSieve2Width() const
208  {
209  return _sieve2Width;
210  }
211  inline int getSieve2Height() const
212  {
213  return _sieve2Height;
214  }
215  inline int getSieve2Size() const
216  {
217  return _sieve2Size;
218  }
219 
220  inline void setLinearMatchLen(int iLen)
221  {
222  _linearMatchLen = iLen;
223  }
224  inline int getLinearMatchLen() const
225  {
226  return _linearMatchLen;
227  }
228  inline void setMatchingStrategy(MatchingStrategy iMatchStrategy)
229  {
230  _matchingStrategy = iMatchStrategy;
231  }
233  {
234  return _matchingStrategy;
235  }
236 
237  inline bool getDownscale() const
238  {
239  return _downscale;
240  }
241  inline void setDownscale(bool iDown)
242  {
243  _downscale = iDown;
244  }
245 
246  // inline void setNumberOfKeys(int iNumKeys) { _numKeys = iNumKeys; }
247  inline void setOutputFile(const std::string& outputFile)
248  {
249  _outputFile = outputFile;
250  _outputGiven=true;
251  }
252  inline void setInputFile(const std::string& inputFile)
253  {
254  _inputFile = inputFile;
255  }
256  inline void setKeyfilesPath(const std::string& keypath)
257  {
258  _keypath = keypath;
259  }
260  inline bool getCached() const
261  {
262  return _cache;
263  }
264  inline void setCached(bool iCached)
265  {
266  _cache = iCached;
267  }
268  inline bool getCleanup() const
269  {
270  return _cleanup;
271  }
272  inline void setCleanup(bool iCleanup)
273  {
274  _cleanup = iCleanup;
275  }
276  inline bool getCeleste() const
277  {
278  return _celeste;
279  };
280  inline void setCeleste(bool iCeleste)
281  {
282  _celeste = iCeleste;
283  };
284  inline double getCelesteThreshold() const
285  {
286  return _celesteThreshold;
287  };
288  inline void setCelesteThreshold(double iCelesteThreshold)
289  {
290  _celesteThreshold = iCelesteThreshold;
291  };
292  inline int getCelesteRadius() const
293  {
294  return _celesteRadius;
295  };
296  inline void setCelesteRadius(int iCelesteRadius)
297  {
298  _celesteRadius = iCelesteRadius;
299  };
300  inline void setTest(bool iTest)
301  {
302  _test = iTest;
303  }
304  inline bool getTest() const
305  {
306  return _test;
307  }
308  inline void setCores(int iCores)
309  {
310  _cores = iCores;
311  }
312 
313  // predeclaration
314  struct ImgData;
315  struct MatchData;
316 
317 private:
318  // prevent copying of class
319  PanoDetector(const PanoDetector&);
321 
322  // options
323 
325  std::vector<int> _keyPointsIdx;
326 
327  int _verbose;
328 
332 
335 
340 
344 
347 
348  bool _test;
349  int _cores;
351  bool _cache;
352  bool _cleanup;
353  bool _celeste;
356  std::string _keypath;
357  std::string _prefix;
358 
359  // bool _stereoRemap;
360 
361  // list of files
362  std::string _outputFile;
364  std::string _inputFile;
365 
366  // Store panorama information
369  std::set<std::string> _cpsHashSet;
370 
372  void buildMultiRowImageSets();
373 
377  std::vector<HuginBase::UIntVector> _image_stacks;
378 
379  bool loadProject();
380  bool checkLoadSuccess();
381  void CleanupKeyfiles();
382 
383  void writeOutput();
384  void writeKeyfile(ImgData& imgInfo);
385 
386  // internals
387 public:
388  struct ImgData
389  {
392  std::string _name;
393 
394  int _number;
397 
399  vigra::BImage _distancemap;
400 
402 
404  std::string _keyfilename;
405 
408  bool _loadFail;
409 
410  // kdtree
411  flann::Matrix<double> _flann_descriptors;
412  flann::Index<flann::L2<double> > * _flann_index;
413 
415  {
416  _loadFail = false;
417  _number = 0;
418  _detectWidth = 0;
419  _detectHeight = 0;
421  _hasakeyfile = false;
422  _descLength = 0;
423  _flann_index = NULL;
424  }
425 
427  {
428  if (_flann_index != NULL)
429  {
430  delete _flann_index;
431  };
432  if (_flann_descriptors.rows + _flann_descriptors.cols > 0)
433  {
434  delete[]_flann_descriptors.ptr();
435  };
436  }
437  void SetSizeMode(const SizeMode newSizeMode) { m_sizeMode = newSizeMode; };
438  SizeMode GetSizeMode() const { return m_sizeMode; };
439  bool IsDownscale() const { return m_sizeMode == DOWNSCALED; };
440  bool NeedsRemapping() const { return m_sizeMode == REMAPPED; };
441  private:
443  };
444 
445  typedef std::map<int, ImgData> ImgData_t;
446  typedef std::map<int, ImgData>::iterator ImgDataIt_t;
447 
448  struct MatchData
449  {
453  };
454 
455  typedef std::vector<MatchData> MatchData_t;
456  typedef std::vector<MatchData>::iterator MatchDataIt_t;
457 
458  // actions
459  static bool LoadKeypoints(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
460 
461  static bool AnalyzeImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
462  static bool FindKeyPointsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
463  static bool FilterKeyPointsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
464  static bool MakeKeyPointDescriptorsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
465  static bool RemapBackKeypoints(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
466  static bool BuildKDTreesInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
467  static bool FreeMemoryInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
468 
469  static bool FindMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
470  static bool RansacMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
471  static bool RansacMatchesInPairCam(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
472  static bool RansacMatchesInPairHomography(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
473  static bool FilterMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
474 
475 private:
476  bool LoadSVMModel();
479 };
480 
482 std::string getKeyfilenameFor(std::string keyfilesPath, std::string filename);
483 
484 // dummy panotools progress functions
485 static int ptProgress( int command, char* argument )
486 {
487  return 1;
488 }
489 static int ptinfoDlg( int command, char* argument )
490 {
491  return 1;
492 }
493 
494 #endif // __detectpano_panodetector_h
std::map< int, ImgData > ImgData_t
Definition: PanoDetector.h:445
double _celesteThreshold
Definition: PanoDetector.h:354
std::string _inputFile
Definition: PanoDetector.h:364
int getLinearMatchLen() const
Definition: PanoDetector.h:224
int getSieve2Width() const
Definition: PanoDetector.h:207
void setSieve2Height(int iHeight)
Definition: PanoDetector.h:199
std::vector< std::string > FileNameList_t
Definition: PanoDetector.h:49
int getRansacIterations() const
Definition: PanoDetector.h:182
SizeMode GetSizeMode() const
Definition: PanoDetector.h:438
int getSieve2Size() const
Definition: PanoDetector.h:215
std::vector< PointMatchPtr > PointMatchVector_t
Definition: PointMatch.h:53
MatchingStrategy _matchingStrategy
Definition: PanoDetector.h:345
bool checkLoadSuccess()
vigra::BImage _distancemap
Definition: PanoDetector.h:399
void setVerbose(int level)
Definition: PanoDetector.h:111
MatchingStrategy getMatchingStrategy() const
Definition: PanoDetector.h:232
std::vector< KeyPointPtr > KeyPointVect_t
Definition: KeyPoint.h:111
std::string _prefix
Definition: PanoDetector.h:357
HuginBase::RANSACOptimizer::Mode getRansacMode()
Definition: PanoDetector.h:190
void setMatchingStrategy(MatchingStrategy iMatchStrategy)
Definition: PanoDetector.h:228
HuginBase::Panorama * getPanoramaInfo() const
Definition: PanoDetector.h:89
void printHelp()
void setSieve1Height(int iHeight)
Definition: PanoDetector.h:124
void CleanupKeyfiles()
void setCores(int iCores)
Definition: PanoDetector.h:308
int getMinimumMatches() const
Definition: PanoDetector.h:178
void setCached(bool iCached)
Definition: PanoDetector.h:264
void SetSizeMode(const SizeMode newSizeMode)
Definition: PanoDetector.h:437
static bool LoadKeypoints(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
void setKDTreeSecondDistance(double iDist)
Definition: PanoDetector.h:149
static bool MakeKeyPointDescriptorsInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static int ptProgress(int command, char *argument)
Definition: PanoDetector.h:485
HuginBase::PanoramaOptions _projOpts
Definition: PanoDetector.h:401
bool getTest() const
Definition: PanoDetector.h:304
int _ransacDistanceThres
Definition: PanoDetector.h:339
void setCleanup(bool iCleanup)
Definition: PanoDetector.h:272
int getVerbose() const
Definition: PanoDetector.h:115
std::vector< MatchData >::iterator MatchDataIt_t
Definition: PanoDetector.h:456
KDTreeSpace::KDTree< KDElemKeyPoint, double > KPKDTree
Definition: PanoDetector.h:51
bool matchPrealigned(HuginBase::Panorama *pano, std::vector< HuginBase::UIntSet > &connectedImages, std::vector< size_t > imgMap, bool exactOverlap=true)
does only matches image pairs which overlaps and don&#39;t have control points
bool matchMultiRow()
std::vector< int > getKeyPointsIdx() const
Definition: PanoDetector.h:98
bool getWriteAllKeyPoints() const
Definition: PanoDetector.h:106
void setSieve2Width(int iWidth)
Definition: PanoDetector.h:195
void setDownscale(bool iDown)
Definition: PanoDetector.h:241
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
bool getCached() const
Definition: PanoDetector.h:260
static bool RansacMatchesInPairCam(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
static bool FilterKeyPointsInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
void setSieve1Size(int iSize)
Definition: PanoDetector.h:128
Model for a panorama.
Definition: Panorama.h:152
int getSieve1Height() const
Definition: PanoDetector.h:136
bool IsDownscale() const
Definition: PanoDetector.h:439
std::vector< HuginBase::UIntVector > _image_stacks
vector with image numbers of all stacks, contains only the unlinked stacks
Definition: PanoDetector.h:377
void setLinearMatchLen(int iLen)
Definition: PanoDetector.h:220
int getSieve1Size() const
Definition: PanoDetector.h:140
int _kdTreeSearchSteps
Definition: PanoDetector.h:333
void buildMultiRowImageSets()
search for image layer and image stacks for the multirow matching step
void setKeyPointsIdx(std::vector< int > keyPointsIdx)
Definition: PanoDetector.h:94
std::vector< std::string >::iterator FileNameListIt_t
Definition: PanoDetector.h:50
void setKDTreeSearchSteps(int iSteps)
Definition: PanoDetector.h:145
std::set< std::string > _cpsHashSet
Definition: PanoDetector.h:369
static bool FindMatchesInPair(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
void setSieve1Width(int iWidth)
Definition: PanoDetector.h:120
bool loadProject()
double _kdTreeSecondDistance
Definition: PanoDetector.h:334
ImgData_t _filesData
Definition: PanoDetector.h:477
std::shared_ptr< KPKDTree > KPKDTreePtr
Definition: PanoDetector.h:52
bool getCleanup() const
Definition: PanoDetector.h:268
static bool RansacMatchesInPair(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
HuginBase::UIntSet _image_layer
image set contains only the images with the median exposure of each stack
Definition: PanoDetector.h:375
void setTest(bool iTest)
Definition: PanoDetector.h:300
MatchingStrategy
for selecting matching strategy
Definition: PanoDetector.h:57
static bool RemapBackKeypoints(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
bool match(std::vector< HuginBase::UIntSet > &checkedPairs)
std::map< int, ImgData >::iterator ImgDataIt_t
Definition: PanoDetector.h:446
bool NeedsRemapping() const
Definition: PanoDetector.h:440
static bool FreeMemoryInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
!! from PTOptimise.h 1951
void setCelesteThreshold(double iCelesteThreshold)
Definition: PanoDetector.h:288
lfeat::PointMatchVector_t _matches
Definition: PanoDetector.h:452
SizeMode
enumeration of different detection modes
Definition: PanoDetector.h:391
flann::Matrix< double > _flann_descriptors
Definition: PanoDetector.h:411
void printFilenames()
void setOutputFile(const std::string &outputFile)
Definition: PanoDetector.h:247
void setSieve2Size(int iSize)
Definition: PanoDetector.h:203
HuginBase::Panorama _panoramaInfoCopy
Definition: PanoDetector.h:368
struct celeste::svm_model * svmModel
Definition: PanoDetector.h:478
HuginBase::RANSACOptimizer::Mode _ransacMode
Definition: PanoDetector.h:337
lfeat::KeyPointDetector KeyPointDetector
Definition: PanoDetector.h:54
int getKDTreeSearchSteps() const
Definition: PanoDetector.h:153
static bool FilterMatchesInPair(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
lfeat::KeyPointVect_t _kp
Definition: PanoDetector.h:406
std::string _keypath
Definition: PanoDetector.h:356
static bool AnalyzeImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
bool LoadSVMModel()
bool _writeAllKeyPoints
Definition: PanoDetector.h:324
std::string _keyfilename
Definition: PanoDetector.h:404
std::string _outputFile
Definition: PanoDetector.h:362
bool getDownscale() const
Definition: PanoDetector.h:237
void setRansacDistanceThreshold(int iDT)
Definition: PanoDetector.h:170
void setWriteAllKeyPoints(bool writeAllKeyPoints=true)
Definition: PanoDetector.h:102
flann::Index< flann::L2< double > > * _flann_index
Definition: PanoDetector.h:412
double getCelesteThreshold() const
Definition: PanoDetector.h:284
int getSieve2Height() const
Definition: PanoDetector.h:211
double getKDTreeSecondDistance() const
Definition: PanoDetector.h:157
void setCelesteRadius(int iCelesteRadius)
Definition: PanoDetector.h:296
bool getCeleste() const
Definition: PanoDetector.h:276
static int ptinfoDlg(int command, char *argument)
Definition: PanoDetector.h:489
HuginBase::Panorama * _panoramaInfo
Definition: PanoDetector.h:367
int getCelesteRadius() const
Definition: PanoDetector.h:292
void writeKeyfile(ImgData &imgInfo)
void setMinimumMatches(int iMatches)
Definition: PanoDetector.h:162
std::vector< int > _keyPointsIdx
Definition: PanoDetector.h:325
int getSieve1Width() const
Definition: PanoDetector.h:132
std::string getKeyfilenameFor(std::string keyfilesPath, std::string filename)
returns the filename for the keyfile for a given image
Panorama image options.
void setRansacIterations(int iIters)
Definition: PanoDetector.h:166
PanoDetector & operator=(const PanoDetector &)
void setKeyfilesPath(const std::string &keypath)
Definition: PanoDetector.h:256
void setInputFile(const std::string &inputFile)
Definition: PanoDetector.h:252
std::vector< MatchData > MatchData_t
Definition: PanoDetector.h:455
void setCeleste(bool iCeleste)
Definition: PanoDetector.h:280
static bool FindKeyPointsInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
void setRansacMode(HuginBase::RANSACOptimizer::Mode mode)
Definition: PanoDetector.h:174
static bool BuildKDTreesInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static bool RansacMatchesInPairHomography(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
void printDetails()
int getRansacDistanceThreshold() const
Definition: PanoDetector.h:186