25 #include <opencv/highgui.h> 26 #include <opencv2/core/core.hpp> 27 #include <opencv2/highgui/highgui.hpp> 28 #include <opencv2/flann/flann.hpp> 29 #include <opencv2/features2d.hpp> 30 #include <opencv2/imgproc.hpp> 39 static ossimTrace traceExec (
"ossimTieMeasurementGenerator:exec");
40 static ossimTrace traceDebug (
"ossimTieMeasurementGenerator:debug");
64 m_showCvWindow(false),
70 m_detectorName(
"ORB"),
72 m_extractorName(
"ORB"),
74 m_matcherName(
"BruteForce-Hamming"),
77 m_maxCvWindowDim(500),
78 m_cvWindowName(
"Correlation Patch")
83 <<
"\nDEBUG: ...ossimTieMeasurementGenerator::constructor" << std::endl;
98 <<
"DEBUG: ...ossimTieMeasurementGenerator::init" << std::endl;
109 *
m_rep <<
"\nossimTieMeasurementGenerator Report ";
111 *
m_rep <<
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
140 <<
"DEBUG: ~ossimTieMeasurementGenerator(): returning..." << std::endl;
187 <<
"DEBUG: ...ossimTieMeasurementGenerator::run" << std::endl;
209 *
m_rep <<
"cv::Mat A creation failed..."<<std::endl;;
214 *
m_rep <<
"cv::Mat B creation failed..."<<std::endl;;
220 vector<cv::KeyPoint> keypointsA;
221 vector<cv::KeyPoint> keypointsB;
229 cv::Mat descriptorsA;
230 cv::Mat descriptorsB;
249 std::vector<cv::DMatch> matches;
250 std::vector<cv::DMatch> matchesAB;
251 m_matcher->match(descriptorsA, descriptorsB, matchesAB);
272 *
m_rep<<
" Match resulted in "<<descriptorsA.rows<<
" points..."<<std::endl;
276 double minDist = 500;
277 int maxRows = matches.size();
278 if(maxRows > descriptorsA.rows) maxRows = descriptorsA.rows;
279 for(
int i = 0; i < maxRows; i++ )
281 double dist = matches[i].distance;
282 if( dist < minDist ) minDist = dist;
283 if( dist > maxDist ) maxDist = dist;
289 std::vector<cv::DMatch> goodMatches;
290 for(
int i = 0; i < maxRows; i++ )
294 goodMatches.push_back( matches[i]);
297 *
m_rep<<
" Distance filter ("<<std::setw(1)<<
m_distEditFactor<<
"X min) resulted in "<<goodMatches.size()<<
" points..."<<std::endl;
298 *
m_rep<<
" -- Max dist : "<<maxDist<<std::endl;
299 *
m_rep<<
" -- Min dist : "<<minDist<<std::endl;
303 nth_element(goodMatches.begin(),goodMatches.begin()+
m_maxMatches,goodMatches.end());
304 goodMatches.erase(goodMatches.begin()+
m_maxMatches,goodMatches.end());
308 *
m_rep<<
"\n Selected top "<<goodMatches.size()<<
"..."<<std::endl;
309 *
m_rep<<
" n queryIdx trainIdx imgIdx distance A B"<<std::endl;
310 *
m_rep<<
"---- -------- -------- ------ -------- ------------ ------------"<<std::endl;
314 double xA = keypointsA[goodMatches[i].queryIdx].pt.x;
315 double yA = keypointsA[goodMatches[i].queryIdx].pt.y;
316 double xB = keypointsB[goodMatches[i].trainIdx].pt.x;
317 double yB = keypointsB[goodMatches[i].trainIdx].pt.y;
319 *
m_rep<<std::setw(4)<<i+1<<
" " 320 <<std::setw(8)<<goodMatches[i].queryIdx<<
" " 321 <<std::setw(8)<<goodMatches[i].trainIdx<<
" " 322 <<std::setw(6)<<goodMatches[i].imgIdx<<
" " 323 <<std::fixed<<std::setprecision(1)<<std::setw(8)
324 <<goodMatches[i].distance<<
" (" 325 <<std::fixed<<std::setprecision(0)
326 <<std::setw(4)<<xA <<
", " 327 <<std::setw(4)<<yA <<
") (" 328 <<std::setw(4)<<xB <<
", " 329 <<std::setw(4)<<yB <<
") " 360 *
m_rep <<
"An error occurred in collection trait initialization..."<<std::endl;
361 *
m_rep <<
"Measurement collection could not be executed."<<std::endl;
372 cv::Ptr<cv::Feature2D> feature2d;
374 feature2d = cv::FastFeatureDetector::create();
375 else if (name ==
"ORB")
376 feature2d = cv::ORB::create();
377 else if (name ==
"BRISK")
378 feature2d = cv::BRISK::create();
379 else if (name ==
"MSER")
380 feature2d = cv::MSER::create();
381 else if (name ==
"GFTT")
382 feature2d = cv::GFTTDetector::create();
383 else if (name ==
"HARRIS")
385 cv::Ptr<cv::GFTTDetector> d = cv::GFTTDetector::create();
386 d->setHarrisDetector(
true);
389 else if (name ==
"SimpleBlob")
390 feature2d = cv::SimpleBlobDetector::create();
391 else if (name ==
"AKAZE")
392 feature2d = cv::AKAZE::create();
393 else if (name ==
"KAZE")
394 feature2d = cv::KAZE::create();
395 else if (name ==
"AGAST")
396 feature2d = cv::AgastFeatureDetector::create();
422 bool createOK =
false;
462 bool createOK =
false;
508 bool createOK =
false;
514 m_matcher =
new cv::FlannBasedMatcher(
new cv::flann::LshIndexParams(20,10,2));
553 if (gridDimensions.
x>0 && gridDimensions.
y>0)
581 if (
m_src.size() != roi.size())
615 <<
"DEBUG: ...ossimTieMeasurementGenerator::setBox" << std::endl;
653 if ((
int)measIdx<m_numMeasurements && imgIdx<2)
658 return m_measA[measIdx];
660 return m_measB[measIdx];
665 return m_measA[measIdx];
667 return m_measB[measIdx];
685 *
m_rep<<
"\n Configuration..."<<std::endl;
695 *
m_rep <<
"\n" << ts;
696 *
m_rep <<
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
706 std::vector<cv::KeyPoint> keypointsA,
707 std::vector<cv::KeyPoint> keypointsB,
708 std::vector<cv::DMatch> goodMatches)
717 cv::drawMatches(
m_imgA, keypointsA,
m_imgB, keypointsB, goodMatches, imgMatch,
718 cv::Scalar::all(-1), cv::Scalar::all(-1), vector<char>(), cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
724 if (rRatio <= cRatio)
735 cv::resize(imgMatch, imgMatchOut, cv::Size(), sFac, sFac);
ossimString m_cvWindowName
ossimRefPtr< ossimIvtGeomXform > m_igxA
ossim_uint32 height() const
cv::Ptr< cv::DescriptorExtractor > m_extractor
virtual bool setROIs(std::vector< ossimIrect > roi)
bool setDescriptorMatcher(const ossimString &name)
ossimRefPtr< ossimIvtGeomXform > m_igxB
~ossimTieMeasurementGenerator()
ossimString m_matcherName
void showCvResultsWindow(std::vector< cv::KeyPoint > keypointsA, std::vector< cv::KeyPoint > keypointsB, std::vector< cv::DMatch > goodMatches)
bool init(std::ostream &report=cout)
void closeCvWindow(const bool waitKeyPress=false)
bool setFeatureDetector(const ossimString &name)
bool refreshCollectionTraits()
OSSIM_DLL void getFormattedTime(const std::string &format, bool gmtFlag, std::string &result)
Gets the current time.
os2<< "> n<< " > nendobj n
ossimString getFeatureDetector() const
unsigned int ossim_uint32
ossimTieMeasurementGenerator()
void summarizeRun() const
bool setDescriptorExtractor(const ossimString &name)
ossim_uint32 width() const
ossimString m_extractorName
cv::Ptr< cv::Feature2D > createFeature2D(const ossimString &name)
ossimString m_detectorName
bool setMaxMatches(const int &maxMatches)
bool setGridSize(const ossimIpt &gridDimensions)
virtual const void * getBuf() const
ossimDpt pointIndexedAt(const ossim_uint32 imgIdx, const ossim_uint32 measIdx)
cv::Ptr< cv::Feature2D > m_detector
ossim_uint32 area() const
virtual bool setImageList(std::vector< ossimImageSource *> src)
ossimString getDescriptorMatcher() const
std::vector< ossimImageSource * > m_src
ossimString getDescriptorExtractor() const
cv::Ptr< cv::DescriptorMatcher > m_matcher
float distance(double lat1, double lon1, double lat2, double lon2, int units)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
const std::string & string() const