PanoDetector.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 ; tab-width: 4 -*-
00002 /*
00003 * Copyright (C) 2007-2008 Anael Orlinski
00004 *
00005 * This file is part of Panomatic.
00006 *
00007 * Panomatic is free software; you can redistribute it and/or modify
00008 * it under the terms of the GNU General Public License as published by
00009 * the Free Software Foundation; either version 2 of the License, or
00010 * (at your option) any later version.
00011 *
00012 * Panomatic is distributed in the hope that it will be useful,
00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 * GNU General Public License for more details.
00016 *
00017 * You should have received a copy of the GNU General Public License
00018 * along with Panomatic; if not, write to the Free Software
00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 #ifndef __detectpano_panodetector_h
00023 #define __detectpano_panodetector_h
00024 
00025 #include <hugin_config.h>
00026 #include <hugin_version.h>
00027 
00028 #include "PanoDetectorDefs.h"
00029 #include <string>
00030 #include <map>
00031 #include <localfeatures/Image.h>
00032 #include <localfeatures/PointMatch.h>
00033 #include "TestCode.h"
00034 #include <zthread/Runnable.h>
00035 #include <zthread/PoolExecutor.h>
00036 
00037 #include <localfeatures/KeyPoint.h>
00038 #include <localfeatures/KeyPointDetector.h>
00039 
00040 #include <flann/flann.hpp>
00041 
00042 #include <vigra_ext/ROIImage.h>
00043 
00044 #include <panodata/Panorama.h>
00045 #include <algorithms/optimizer/PTOptimizer.h>
00046 #include <celeste/Celeste.h>
00047 
00048 using namespace HuginBase;
00049 
00050 class PanoDetector
00051 {
00052 public:
00053     typedef std::vector<std::string>                                            FileNameList_t;
00054     typedef std::vector<std::string>::iterator                          FileNameListIt_t;
00055     typedef KDTreeSpace::KDTree<KDElemKeyPoint, double>         KPKDTree;
00056     typedef boost::shared_ptr<KPKDTree >                                        KPKDTreePtr;
00057 
00058     typedef lfeat::KeyPointDetector KeyPointDetector;
00059 
00061     enum MatchingStrategy
00062     {
00063         ALLPAIRS=0,
00064         LINEAR,
00065         MULTIROW,
00066         PREALIGNED
00067     };
00068 
00069     PanoDetector();
00070 
00071     bool checkData();
00072     void printDetails();
00073     void printFilenames();
00074     void printHelp();
00075     void run();
00076     bool match(ZThread::PoolExecutor& aExecutor, std::vector<HuginBase::UIntSet> &checkedPairs);
00077     bool matchMultiRow(ZThread::PoolExecutor& aExecutor);
00087     bool matchPrealigned(ZThread::PoolExecutor& aExecutor, Panorama* pano, std::vector<HuginBase::UIntSet> &connectedImages, std::vector<size_t> imgMap, bool exactOverlap=true);
00088 
00089 
00090     // accessors
00091 
00092     inline Panorama* getPanoramaInfo() const
00093     {
00094         return _panoramaInfo;
00095     }
00096 
00097     inline void setKeyPointsIdx(std::vector<int> keyPointsIdx)
00098     {
00099         _keyPointsIdx = keyPointsIdx;
00100     }
00101     inline std::vector<int> getKeyPointsIdx() const
00102     {
00103         return _keyPointsIdx;
00104     }
00105     inline void setWriteAllKeyPoints(bool writeAllKeyPoints=true)
00106     {
00107         _writeAllKeyPoints = writeAllKeyPoints;
00108     }
00109     inline bool getWriteAllKeyPoints() const
00110     {
00111         return _writeAllKeyPoints;
00112     }
00113 
00114     inline void setVerbose(int level)
00115     {
00116         _verbose = level;
00117     }
00118     inline int  getVerbose() const
00119     {
00120         return _verbose;
00121     }
00122 
00123     inline void setSieve1Width(int iWidth)
00124     {
00125         _sieve1Width = iWidth;
00126     }
00127     inline void setSieve1Height(int iHeight)
00128     {
00129         _sieve1Height = iHeight;
00130     }
00131     inline void setSieve1Size(int iSize)
00132     {
00133         _sieve1Size = iSize;
00134     }
00135     inline int  getSieve1Width() const
00136     {
00137         return _sieve1Width;
00138     }
00139     inline int  getSieve1Height() const
00140     {
00141         return _sieve1Height;
00142     }
00143     inline int  getSieve1Size() const
00144     {
00145         return _sieve1Size;
00146     }
00147 
00148     inline void setKDTreeSearchSteps(int iSteps)
00149     {
00150         _kdTreeSearchSteps = iSteps;
00151     }
00152     inline void setKDTreeSecondDistance(double iDist)
00153     {
00154         _kdTreeSecondDistance = iDist;
00155     }
00156     inline int  getKDTreeSearchSteps() const
00157     {
00158         return _kdTreeSearchSteps;
00159     }
00160     inline double  getKDTreeSecondDistance() const
00161     {
00162         return _kdTreeSecondDistance;
00163     }
00164 
00165     inline void setMinimumMatches(int iMatches)
00166     {
00167         _minimumMatches = iMatches;
00168     }
00169     inline void setRansacIterations(int iIters)
00170     {
00171         _ransacIters = iIters;
00172     }
00173     inline void setRansacDistanceThreshold(int iDT)
00174     {
00175         _ransacDistanceThres = iDT;
00176     }
00177     inline void setRansacMode(RANSACOptimizer::Mode mode)
00178     {
00179         _ransacMode = mode;
00180     }
00181     inline int  getMinimumMatches() const
00182     {
00183         return _minimumMatches;
00184     }
00185     inline int  getRansacIterations() const
00186     {
00187         return _ransacIters;
00188     }
00189     inline int  getRansacDistanceThreshold() const
00190     {
00191         return _ransacDistanceThres;
00192     }
00193     inline RANSACOptimizer::Mode getRansacMode()
00194     {
00195         return _ransacMode;
00196     }
00197 
00198     inline void setSieve2Width(int iWidth)
00199     {
00200         _sieve2Width = iWidth;
00201     }
00202     inline void setSieve2Height(int iHeight)
00203     {
00204         _sieve2Height = iHeight;
00205     }
00206     inline void setSieve2Size(int iSize)
00207     {
00208         _sieve2Size = iSize;
00209     }
00210     inline int  getSieve2Width() const
00211     {
00212         return _sieve2Width;
00213     }
00214     inline int  getSieve2Height() const
00215     {
00216         return _sieve2Height;
00217     }
00218     inline int  getSieve2Size() const
00219     {
00220         return _sieve2Size;
00221     }
00222 
00223     inline void setLinearMatchLen(int iLen)
00224     {
00225         _linearMatchLen = iLen;
00226     }
00227     inline int  getLinearMatchLen() const
00228     {
00229         return _linearMatchLen;
00230     }
00231     inline void setMatchingStrategy(MatchingStrategy iMatchStrategy)
00232     {
00233         _matchingStrategy = iMatchStrategy;
00234     }
00235     inline MatchingStrategy getMatchingStrategy() const
00236     {
00237         return _matchingStrategy;
00238     }
00239 
00240     inline bool getDownscale() const
00241     {
00242         return _downscale;
00243     }
00244     inline void setDownscale(bool iDown)
00245     {
00246         _downscale = iDown;
00247     }
00248 
00249     //  inline void setNumberOfKeys(int iNumKeys) { _numKeys = iNumKeys; }
00250     inline void setOutputFile(const std::string& outputFile)
00251     {
00252         _outputFile = outputFile;
00253         _outputGiven=true;
00254     }
00255     inline void setInputFile(const std::string& inputFile)
00256     {
00257         _inputFile = inputFile;
00258     }
00259     inline void setKeyfilesPath(const std::string& keypath)
00260     {
00261         _keypath = keypath;
00262     }
00263     inline bool getCached() const
00264     {
00265         return _cache;
00266     }
00267     inline void setCached(bool iCached)
00268     {
00269         _cache = iCached;
00270     }
00271     inline bool getCleanup() const
00272     {
00273         return _cleanup;
00274     }
00275     inline void setCleanup(bool iCleanup)
00276     {
00277         _cleanup = iCleanup;
00278     }
00279     inline bool getCeleste() const
00280     {
00281         return _celeste;
00282     };
00283     inline void setCeleste(bool iCeleste)
00284     {
00285         _celeste = iCeleste;
00286     };
00287     inline double getCelesteThreshold() const
00288     {
00289         return _celesteThreshold;
00290     };
00291     inline void setCelesteThreshold(double iCelesteThreshold)
00292     {
00293         _celesteThreshold = iCelesteThreshold;
00294     };
00295     inline int getCelesteRadius() const
00296     {
00297         return _celesteRadius;
00298     };
00299     inline void setCelesteRadius(int iCelesteRadius)
00300     {
00301         _celesteRadius = iCelesteRadius;
00302     };
00303     inline void setTest(bool iTest)
00304     {
00305         _test = iTest;
00306     }
00307     inline bool getTest() const
00308     {
00309         return _test;
00310     }
00311     inline void setCores(int iCores)
00312     {
00313         _cores = iCores;
00314     }
00315 
00316     // predeclaration
00317     struct ImgData;
00318     struct MatchData;
00319 
00320 private:
00321     // options
00322 
00323     bool                                                _writeAllKeyPoints;
00324     std::vector<int>            _keyPointsIdx;
00325 
00326     int                     _verbose;
00327 
00328     int                                         _sieve1Width;
00329     int                                         _sieve1Height;
00330     int                                         _sieve1Size;
00331 
00332     int                                         _kdTreeSearchSteps;
00333     double                                      _kdTreeSecondDistance;
00334 
00335     int                                         _minimumMatches;
00336     RANSACOptimizer::Mode       _ransacMode;
00337     int                                         _ransacIters;
00338     int                                         _ransacDistanceThres;
00339 
00340     int                                         _sieve2Width;
00341     int                                         _sieve2Height;
00342     int                                         _sieve2Size;
00343 
00344     MatchingStrategy _matchingStrategy;
00345     int                                         _linearMatchLen;
00346 
00347     bool                                                _test;
00348     int                                         _cores;
00349     bool                 _downscale;
00350     bool        _cache;
00351     bool        _cleanup;
00352     bool        _celeste;
00353     double      _celesteThreshold;
00354     int         _celesteRadius;
00355     std::string _keypath;
00356     std::string _prefix;
00357 
00358     //  bool                                            _stereoRemap;
00359 
00360     // list of files
00361     std::string                         _outputFile;
00362     bool _outputGiven;
00363     std::string                         _inputFile;
00364 
00365     // Store panorama information
00366     Panorama*                   _panoramaInfo;
00367     Panorama                            _panoramaInfoCopy;
00368 
00369     bool                                        loadProject();
00370     bool                        checkLoadSuccess();
00371     void CleanupKeyfiles();
00372 
00373     void                                        writeOutput();
00374     void                                        writeKeyfile(ImgData& imgInfo);
00375 
00376     // internals
00377 public:
00378     struct ImgData
00379     {
00380         std::string                     _name;
00381 
00382         int                                     _number;
00383         int                                     _detectWidth;
00384         int                                     _detectHeight;
00385 
00386         lfeat::Image            _ii;
00387         vigra::BImage           _distancemap;
00388 
00389         bool                            _needsremap;
00390         PanoramaOptions         _projOpts;
00391 
00392         bool                                    _hasakeyfile;
00393         std::string _keyfilename;
00394 
00395         lfeat::KeyPointVect_t   _kp;
00396         int                                     _descLength;
00397         bool               _loadFail;
00398 
00399         // kdtree
00400         flann::Matrix<double> _flann_descriptors;
00401         flann::Index<flann::L2<double> > * _flann_index;
00402 
00403     };
00404 
00405     typedef std::map<int, ImgData>                                      ImgData_t;
00406     typedef std::map<int, ImgData>::iterator            ImgDataIt_t;
00407 
00408     struct MatchData
00409     {
00410         ImgData*                                _i1;
00411         ImgData*                                _i2;
00412         lfeat::PointMatchVector_t               _matches;
00413     };
00414 
00415     typedef std::vector<MatchData>                                                              MatchData_t;
00416     typedef std::vector<MatchData>::iterator                                    MatchDataIt_t;
00417 
00418     // actions
00419     static bool                         LoadKeypoints(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00420 
00421     static bool                         AnalyzeImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00422     static bool                         FindKeyPointsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00423     static bool                         FilterKeyPointsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00424     static bool                         MakeKeyPointDescriptorsInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00425     static bool             RemapBackKeypoints(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00426     static bool                         BuildKDTreesInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00427     static bool                         FreeMemoryInImage(ImgData& ioImgInfo, const PanoDetector& iPanoDetector);
00428 
00429     static bool                         FindMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
00430     static bool                         RansacMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
00431     static bool                         RansacMatchesInPairCam(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
00432     static bool                         RansacMatchesInPairHomography(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
00433     static bool                         FilterMatchesInPair(MatchData& ioMatchData, const PanoDetector& iPanoDetector);
00434 
00435 private:
00436     bool LoadSVMModel();
00437     ImgData_t                           _filesData;
00438     MatchData_t                         _matchesData;
00439     struct celeste::svm_model* svmModel;
00440 };
00441 
00443 std::string getKeyfilenameFor(std::string keyfilesPath, std::string filename);
00444 
00445 // dummy panotools progress functions
00446 static int ptProgress( int command, char* argument )
00447 {
00448     return 1;
00449 }
00450 static int ptinfoDlg( int command, char* argument )
00451 {
00452     return 1;
00453 }
00454 
00455 #endif // __detectpano_panodetector_h

Generated on Fri Aug 29 01:25:43 2014 for Hugintrunk by  doxygen 1.3.9.1