Example: added hard-coded switch to choose between BFMatcher and FLANN matching.
git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@180 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
parent
72bdae12b0
commit
39660003a2
@ -95,11 +95,22 @@ int main(int argc, char * argv[])
|
||||
////////////////////////////
|
||||
cv::Mat results;
|
||||
cv::Mat dists;
|
||||
std::vector<std::vector<cv::DMatch> > matches;
|
||||
bool isBinaryDescriptors;
|
||||
int k=2; // find the 2 nearest neighbors
|
||||
bool useBFMatcher = false; // SET TO TRUE TO USE BRUTE FORCE MATCHER (may give better results with binary descriptors)
|
||||
if(objectDescriptors.type()==CV_8U)
|
||||
{
|
||||
// Binary descriptors detected (from ORB or Brief)
|
||||
|
||||
// Binary descriptors detected (from ORB, Brief, BRISK, FREAK)
|
||||
printf("Binary descriptors detected...\n");
|
||||
isBinaryDescriptors = true;
|
||||
if(useBFMatcher)
|
||||
{
|
||||
cv::BFMatcher matcher(cv::NORM_HAMMING);
|
||||
matcher.knnMatch(objectDescriptors, sceneDescriptors, matches, k);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create Flann LSH index
|
||||
cv::flann::Index flannIndex(sceneDescriptors, cv::flann::LshIndexParams(12, 20, 2), cvflann::FLANN_DIST_HAMMING);
|
||||
printf("Time creating FLANN LSH index = %d ms\n", time.restart());
|
||||
@ -108,12 +119,20 @@ int main(int argc, char * argv[])
|
||||
|
||||
// search (nearest neighbor)
|
||||
flannIndex.knnSearch(objectDescriptors, results, dists, k, cv::flann::SearchParams() );
|
||||
printf("Time nearest neighbor search = %d ms\n", time.restart());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// assume it is CV_32F
|
||||
|
||||
printf("Float descriptors detected...\n");
|
||||
isBinaryDescriptors = false;
|
||||
if(useBFMatcher)
|
||||
{
|
||||
cv::BFMatcher matcher(cv::NORM_L2);
|
||||
matcher.knnMatch(objectDescriptors, sceneDescriptors, matches, k);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create Flann KDTree index
|
||||
cv::flann::Index flannIndex(sceneDescriptors, cv::flann::KDTreeIndexParams(), cvflann::FLANN_DIST_EUCLIDEAN);
|
||||
printf("Time creating FLANN KDTree index = %d ms\n", time.restart());
|
||||
@ -122,8 +141,9 @@ int main(int argc, char * argv[])
|
||||
|
||||
// search (nearest neighbor)
|
||||
flannIndex.knnSearch(objectDescriptors, results, dists, k, cv::flann::SearchParams() );
|
||||
printf("Time nearest neighbor search = %d ms\n", time.restart());
|
||||
}
|
||||
}
|
||||
printf("Time nearest neighbor search = %d ms\n", time.restart());
|
||||
|
||||
|
||||
|
||||
@ -141,11 +161,15 @@ int main(int argc, char * argv[])
|
||||
std::vector<cv::Point2f> mpts_1, mpts_2; // Used for homography
|
||||
std::vector<int> indexes_1, indexes_2; // Used for homography
|
||||
std::vector<uchar> outlier_mask; // Used for homography
|
||||
// Check if this descriptor matches with those of the objects
|
||||
if(!useBFMatcher)
|
||||
{
|
||||
for(int i=0; i<objectDescriptors.rows; ++i)
|
||||
{
|
||||
// Check if this descriptor matches with those of the objects
|
||||
// Apply NNDR
|
||||
if(dists.at<float>(i,0) <= nndrRatio * dists.at<float>(i,1))
|
||||
//printf("q=%d dist1=%f dist2=%f\n", i, dists.at<float>(i,0), dists.at<float>(i,1));
|
||||
if(isBinaryDescriptors || //Binary, just take the nearest
|
||||
dists.at<float>(i,0) <= nndrRatio * dists.at<float>(i,1))
|
||||
{
|
||||
mpts_1.push_back(objectKeypoints.at(i).pt);
|
||||
indexes_1.push_back(i);
|
||||
@ -154,6 +178,24 @@ int main(int argc, char * argv[])
|
||||
indexes_2.push_back(results.at<int>(i,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned int i=0; i<matches.size(); ++i)
|
||||
{
|
||||
// Apply NNDR
|
||||
//printf("q=%d dist1=%f dist2=%f\n", matches.at(i).at(0).queryIdx, matches.at(i).at(0).distance, matches.at(i).at(1).distance);
|
||||
if(isBinaryDescriptors || //Binary, just take the nearest
|
||||
matches.at(i).at(0).distance <= nndrRatio * matches.at(i).at(1).distance)
|
||||
{
|
||||
mpts_1.push_back(objectKeypoints.at(matches.at(i).at(0).queryIdx).pt);
|
||||
indexes_1.push_back(matches.at(i).at(0).queryIdx);
|
||||
|
||||
mpts_2.push_back(sceneKeypoints.at(matches.at(i).at(0).trainIdx).pt);
|
||||
indexes_2.push_back(matches.at(i).at(0).trainIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIND HOMOGRAPHY
|
||||
unsigned int minInliers = 8;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user