Created
June 12, 2013 01:25
-
-
Save masazdream/5762255 to your computer and use it in GitHub Desktop.
2つの画像のキーポイントをマッチする既存ロジック→このベクトル探索を置き換えて、低速マッチングを作成する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector<KeyPoint> keyPoint0 = keypoints_vec[0]; | |
Vector<KeyPoint> keyPoint1 = keypoints_vec[1]; | |
Mat descriptor0 = descriptors_vec[0]; | |
Mat descriptor1 = descriptors_vec[1]; | |
vector<DMatch> matches; | |
BFMatcher matcher(NORM_HAMMING, true); | |
matcher.match(descriptor0, descriptor1, matches); | |
double max_dist = 0; | |
double min_dist = DBL_MAX; | |
for (int j = 0; j < (int) matches.size(); j++) { | |
double dist = matches[j].distance; | |
if (dist < min_dist) | |
min_dist = dist; | |
if (dist > max_dist) | |
max_dist = dist; | |
} | |
// 良いペアのみ残す | |
double cutoff = 3.0 * (min_dist + 1.0); | |
std::set<int> existing_trainIdx; | |
std::vector<cv::DMatch> matches_good; | |
for (int j = 0; j < (int) matches.size(); j++) { | |
if (matches[j].trainIdx <= 0) | |
matches[j].trainIdx = matches[j].imgIdx; | |
if (matches[j].distance > 0.0 && matches[j].distance < cutoff) { | |
if (existing_trainIdx.find(matches[j].trainIdx) | |
== existing_trainIdx.end() && matches[j].trainIdx >= 0 | |
&& matches[j].trainIdx < (int) keyPoint1.size()) { | |
matches_good.push_back(matches[j]); | |
existing_trainIdx.insert(matches[j].trainIdx); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment