ORB アルゴリズムを使用して画像とビデオのキーポイントを検出および計算し、BruteForce マッチャーを使用して記述子ベクトルを照合するプログラムを作成しようとしています。私が直面している問題は、Visual C++ でプログラムを実行するたびに、検出しようとしているオブジェクトが表示されないときに、アルゴリズムが検出されたキーポイント間に想定されるすべての一致する線を描画することです (すべてのキーポイント)。検出しようとしているオブジェクトが画像に表示される場合、この問題に直面することはありません。実際、不一致はほとんど発生しません。
これは、メイン テストの簡単なシーケンスです。
• 入力画像をグレースケールに変換
• 入力ビデオをグレースケールに変換
• キーポイントを検出し、入力グレースケール画像から記述子を抽出する
• キーポイントを検出し、入力グレースケール ビデオから記述子を抽出します。
• 一致記述子 (以下を参照)
BFMatcher matcher(NORM_HAMMING);
vector<DMatch> matches;
matcher.match(descriptors_1, descriptors_2, matches);
double max_dist = 0; double min_dist = 100;
////calcularea distantelor max si min distances intre keypoints
for (int i = 0; i < descriptors_1.rows; i++)
{
double dist = matches[i].distance;
if (dist < min_dist) min_dist = dist;
if (dist > max_dist) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist);
printf("-- Min dist : %f \n", min_dist);
std::vector< DMatch > good_matches;
for (int i = 0; i < descriptors_1.rows; i++)
{
if (matches[i].distance <= max(2 * min_dist, 0.02))
{
good_matches.push_back(matches[i]);
}
}
////-- Desenarea matches-urilor "bune"
Mat img_matches;
drawMatches(img1, keypoints_1, cadruProcesat, keypoints_2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
////-- Afisare matches
imshow("good matches", img_matches);
int gm = 0;
for (int i = 0; i < (int)good_matches.size(); i++)
{
printf("-- Good Match [%d] Keypoint 1: %d -- Keypoint 2: %d \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx);
gm += 1;
}
printf("%d",gm);
///////////////////////////////////////////////////////////////////
//imshow(windowName2, cadruProcesat);
switch (waitKey(10)) {
case 27:
//tasta 'esc' a fost apasata(ASCII 27)
return 0;
}
}
return 0;
問題を見つけるのを手伝ってください。