Windows 7 で OpenCV2.2 を使用しています。私がやろうとしているのは、次のコードを使用して、別のイメージで定義されたオブジェクトを検出することです。
// Read the two image files
Mat image1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat image2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
Mat finalImage = imread(argv[2]);
if( !image1.data || !image2.data ) {
std::cout << " --(!) Error reading images " << std::endl;
return -10;
}
//Construct the SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
//Extract the keypoints for each image
std::vector<KeyPoint> keypoints1, keypoints2;
detector.detect(image1,keypoints1);
detector.detect(image2,keypoints2);
//Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(image1,keypoints1,descriptors1);
extractor.compute(image2,keypoints2,descriptors2);
//Define the Matcher
FlannBasedMatcher matcher;
std::cout << "matcher constructed!" << std::endl;
std::vector<vector<DMatch >> matches;
matcher.knnMatch(descriptors1, descriptors2, matches, 2);
std::cout << "matches: " << matches.size() << std::endl;
std::vector<DMatch > good_matches;
//THIS LOOP IS SENSITIVE TO SEGFAULTS
for (int i = 0; i < min(descriptors2.rows-1,(int) matches.size()); i++)
{
if((matches[i][0].distance < 0.8*(matches[i][1].distance)) && ((int) matches[i].size()<=2 && (int) matches[i].size()>0))
{
good_matches.push_back(matches[i][0]);
}
}
std::cout << "good_matches: " << good_matches.size() << std::endl;
VS2010 は、エラーなしでコードをビルドおよびコンパイルします。私の問題は、いくつかの(すべてではない)ケースでは、実行が行に行くときです
matcher.knnMatch(descriptors1, descriptors2, matches, 2);
cmd が停止し、次のようなメッセージが返さdataset.Type() == CvType(T)::type()
れます。
これは、両方の画像から記述子 (照合に必要) が正しく抽出されているにもかかわらず、画像間に類似性がない (すべての場合ではない) 場合に発生します。BruteForce マッチャーを使用すると、コードは正常に動作します。
OpenCVのコードも試しました:
http://opencv.itseez.com/doc/tutorials/features2d/feature_homography/feature_homography.html
同じ問題がありました。Opencv サンプルのように単純なマッチャーを使用しても実行に失敗します。
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
私は解決策を探しました ( OpenCV flann.h assertion Errorで見つかった同様の質問ですが、残念ながら答えはありません) が、役に立つものは何も見つかりませんでした。この問題に対処する方法を知っている人はいますか?