2012-06-19 3 views
5

を失敗しました。このコードを使用して別の画像に定義されたオブジェクトを検出することである。FlannBased Matcherのアサーションは、私は私がやろうとしています何の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())未知の機能でなどなど.flann.hpp行の終わり105 "

これは、画像間の類似性がない場合(すべての場合ではなく)、両方の画像から正しく抽出された記述子です(一致する必要があります)。 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で見つけ同様の質問が、残念ながら無応答)を検索するが、私は有益な何かを見つけることができませんでした。この問題に取り組む方法を知っている人はいますか?

+0

あなたの問題を解決するかどうかはわかりませんが、記述子をCV_32Fタイプに変換しようとするとどうなりますか? – andriy

+0

ディスクリプタが空であることを確認します。 if(!descriptors.empty()){// flann babyを実行する} – madLokesh

+0

も記述子をCV_32F形式に変更します – madLokesh

答えて

0

奇妙だ、それはたぶん、あなたはCV :: DescriptorMatcherインタフェース(ドキュメントhere)を使用しようとすることができthis tutorial page ...

で同じコードを縫い目。

使用方法は次のとおりです。

cv::DescriptorMatcher matcher = cv::DescriptorMatcher::create("FlannBased"); 

そして、あなたは何も変更せずにまっすぐにあなたのコードでそれを使用することができます。

関連する問題