From 966d50762dcf05e786238fb67cc90f637a49a0bf Mon Sep 17 00:00:00 2001 From: laurentBerger Date: Thu, 7 May 2015 22:48:13 +0200 Subject: [PATCH] Try to include comment from @eduardo and @berak Akaze descriptor with DESCRIPTOR_KAZE_UPRIGHT added --- samples/cpp/matchmethod_orb_akaze_brisk.cpp | 89 +++++++++++++++++------------ 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/samples/cpp/matchmethod_orb_akaze_brisk.cpp b/samples/cpp/matchmethod_orb_akaze_brisk.cpp index 500f8c4..072b1d6 100644 --- a/samples/cpp/matchmethod_orb_akaze_brisk.cpp +++ b/samples/cpp/matchmethod_orb_akaze_brisk.cpp @@ -21,8 +21,8 @@ int main(int argc, char *argv[]) vector typeAlgoMatch; vector fileName; help(); - system("cd"); // This descriptor are going to be detect and compute + typeDesc.push_back("AKAZE-DESCRIPTOR_KAZE_UPRIGHT"); // see http://docs.opencv.org/trunk/d8/d30/classcv_1_1AKAZE.html typeDesc.push_back("AKAZE"); // see http://docs.opencv.org/trunk/d8/d30/classcv_1_1AKAZE.html typeDesc.push_back("ORB"); // see http://docs.opencv.org/trunk/de/dbf/classcv_1_1BRISK.html typeDesc.push_back("BRISK"); // see http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html @@ -74,9 +74,12 @@ int main(int argc, char *argv[]) // Descriptor for img1 and img2 Mat descImg1, descImg2; vector::iterator itMatcher = typeAlgoMatch.end(); + if (*itDesc == "AKAZE-DESCRIPTOR_KAZE_UPRIGHT"){ + b = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT); + } if (*itDesc == "AKAZE"){ b = AKAZE::create(); - } + } if (*itDesc == "ORB"){ b = ORB::create(); } @@ -93,44 +96,57 @@ int main(int argc, char *argv[]) // Match method loop for (itMatcher = typeAlgoMatch.begin(); itMatcher != typeAlgoMatch.end(); itMatcher++){ descriptorMatcher = DescriptorMatcher::create(*itMatcher); - descriptorMatcher->match(descImg1, descImg2, matches, Mat()); - // Keep best matches only to have a nice drawing. - // We sort distance between descriptor matches - Mat index; - int nbMatch=int(matches.size()); - Mat tab(nbMatch, 1, CV_32F); - for (int i = 0; idescriptorType() == CV_32F || b->defaultNorm() <= NORM_L2SQR) ) { - tab.at(i, 0) = matches[i].distance; + cout << "**************************************************************************\n"; + cout << "It's strange. You should use Hamming distance only for a binary descriptor\n"; + cout << "**************************************************************************\n"; } - sortIdx(tab, index, SORT_EVERY_COLUMN + SORT_ASCENDING); - vector bestMatches; - for (int i = 0; i<30; i++) + try { - bestMatches.push_back(matches[index.at(i, 0)]); + descriptorMatcher->match(descImg1, descImg2, matches, Mat()); + // Keep best matches only to have a nice drawing. + // We sort distance between descriptor matches + Mat index; + int nbMatch=int(matches.size()); + Mat tab(nbMatch, 1, CV_32F); + for (int i = 0; i(i, 0) = matches[i].distance; + } + sortIdx(tab, index, SORT_EVERY_COLUMN + SORT_ASCENDING); + vector bestMatches; + for (int i = 0; i<30; i++) + { + bestMatches.push_back(matches[index.at(i, 0)]); + } + Mat result; + drawMatches(img1, keyImg1, img2, keyImg2, bestMatches, result); + namedWindow(*itDesc+": "+*itMatcher, WINDOW_AUTOSIZE); + imshow(*itDesc + ": " + *itMatcher, result); + // Saved result could be wrong due to bug 4308 + FileStorage fs(*itDesc + "_" + *itMatcher + ".yml", FileStorage::WRITE); + fs<<"Matches"<::iterator it; + cout<<"**********Match results**********\n"; + cout << "Index \tIndex \tdistance\n"; + cout << "in img1\tin img2\n"; + // Use to compute distance between keyPoint matches and to evaluate match algorithm + double cumSumDist2=0; + for (it = bestMatches.begin(); it != bestMatches.end(); it++) + { + cout << it->queryIdx << "\t" << it->trainIdx << "\t" << it->distance << "\n"; + Point2d p=keyImg1[it->queryIdx].pt-keyImg2[it->trainIdx].pt; + cumSumDist2=p.x*p.x+p.y*p.y; + } + desMethCmp.push_back(cumSumDist2); + waitKey(); } - Mat result; - drawMatches(img1, keyImg1, img2, keyImg2, bestMatches, result); - namedWindow(*itDesc+": "+*itMatcher, WINDOW_AUTOSIZE); - imshow(*itDesc + ": " + *itMatcher, result); - // Saved result could be wrong due to bug 4308 - FileStorage fs(*itDesc + "_" + *itMatcher + ".yml", FileStorage::WRITE); - fs<<"Matches"<::iterator it; - cout<<"**********Match results**********\n"; - cout << "Index \tIndex \tdistance\n"; - cout << "in img1\tin img2\n"; - // Use to compute distance between keyPoint matches and to evaluate match algorithm - double cumSumDist2=0; - for (it = bestMatches.begin(); it != bestMatches.end(); it++) - { - cout << it->queryIdx << "\t" << it->trainIdx << "\t" << it->distance << "\n"; - Point2d p=keyImg1[it->queryIdx].pt-keyImg2[it->trainIdx].pt; - cumSumDist2=p.x*p.x+p.y*p.y; + catch (Exception& e) + { + desMethCmp.push_back(-1); + } } - desMethCmp.push_back(cumSumDist2); - waitKey(); - } } catch (Exception& e) { @@ -139,11 +155,12 @@ int main(int argc, char *argv[]) { cout << "Matcher : " << *itMatcher << "\n"; } - cout<::iterator itMatcher = typeAlgoMatch.begin(); itMatcher != typeAlgoMatch.end(); itMatcher++) { cout<<*itMatcher<<"\t"; -- 2.7.4