私は Java Android 開発者ですが、C/C++ または Matlab 関数についてはあまり知りません。私のコードで行っている簡単なことは、sift/Surf 画像の詳細を作成し、詳細を .yml ファイルに保存することです。
ここに私がsiftを作成しているコードがあります
vector < KeyPoint > keypoints;
Mat descriptors;
// Create a SIFT keypoint detector.
SiftFeatureDetector detector;
detector.detect(image, keypoints);
LOGI("Detected %d keypoints\n", (int) keypoints.size());
// Compute feature description.
detector.compute(image, keypoints, descriptors);
結果の記述子を ( .yml ) ファイルに保存し、後で OpenCV の FlannBasedMatcher を使用してその yml ファイルを比較する
ここに私のコードがあります
descriptors1 & descriptors2 は、.yml ファイルから作成された 2 つのマット オブジェクトです。
FlannBasedMatcher matcher;
vector<double> ee;
vector < DMatch > good_matches;
double good_matches_sum = 0.0;
vector < vector<DMatch> > matches;
matcher.knnMatch(descriptors1, descriptors2, matches, 2);
for (int i = 0; i < matches.size(); i++) {
if (matches[i][0].distance < 0.8 * matches[i][1].distance) {
good_matches.push_back(matches[i][0]);
good_matches_sum += matches[i][0].distance;
}
}
LOGI("good_matches_sum %d s\n", good_matches_sum);
LOGI("the distance k %f s\n", good_matches_sum);
double score = (double) good_matches_sum / (double) good_matches.size();
LOGI("score %f k %d s\n", score, good_matches.size());
上記のコードの問題は、毎回異なる結果が得られることです.e
ここに私の2つの画像として
//first time run for two images
good_matches_sum 1006632960
the distance k 3054.279755
scores 254.523313 k 12 s
//Second time run for same two images
good_matches_sum -402653184
the distance k 2835.513489
score score scores 257.773954 k 11 s
//Third time run for same two images
good_matches_sum -1946157056
the distance k 2794.588959
score score scores 254.053542 k 11 s
ポジティブな結果とネガティブな結果に基づいて、画像がよりスリムまたは類似していないと想定しています。しかし、このような毎回異なる結果では、画像が似ているかどうかわかりません。
私はOpencvとcについて知らないので、誰かが何か考えを持っているなら、修正されたコードを提案してください。ありがとう。