// -*- 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 #include #include "PanoDetectorDefs.h" #include #include #include #include #include "TestCode.h" #include #include #include #include #include #include #include #include #include using namespace HuginBase; class PanoDetector { public: typedef std::vector FileNameList_t; typedef std::vector::iterator FileNameListIt_t; typedef KDTreeSpace::KDTree KPKDTree; typedef boost::shared_ptr 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 keyPointsIdx) { _keyPointsIdx = keyPointsIdx; } inline std::vector 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; _outputGiven=true; } 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 _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; bool _outputGiven; 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 _flann_descriptors; flann::Index > * _flann_index; }; typedef std::map ImgData_t; typedef std::map::iterator ImgDataIt_t; struct MatchData { ImgData* _i1; ImgData* _i2; lfeat::PointMatchVector_t _matches; }; typedef std::vector MatchData_t; typedef std::vector::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