ブルートフォースマッチャーを使用して2つの画像のいくつかの機能を一致させようとしています。完全なコードは次のとおりです。
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <vector>
#include<iostream>
int main()
{
cv::Ptr<IplImage> img = cvLoadImage("img.jpg",1);
cv::Ptr<IplImage> img1 = cvLoadImage("img1.jpg",1);
cv::Mat image(img,false);
cv::Mat image1(img1,false);
cv::resize(image,image,cv::Size(image.cols/5,image.rows/7));
cv::resize(image1,image1,cv::Size(image1.cols/5,image1.rows/7));
cv::waitKey(0);
std::vector<cv::KeyPoint> keypoints;
std::vector<cv::KeyPoint> keypoints1;
cv::SurfFeatureDetector surf(20000);
surf.detect(image,keypoints);
surf.detect(image1,keypoints1);
cv::drawKeypoints(image,keypoints,image,cv::Scalar(0,0,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
cv::drawKeypoints(image1,keypoints1,image1,cv::Scalar(0,0,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
cv::imshow("1",image);
cv::imshow("2",image1);
cv::waitKey(0);
cv::SurfDescriptorExtractor surfDesc;
cv::Mat descriptors;
cv::Mat descriptors1;
surfDesc.compute(image,keypoints,descriptors);
surfDesc.compute(image1,keypoints1,descriptors1);
std::cout<<sizeof(unsigned long);
cv::BruteForceMatcher<cv::L2<float>>matcher;
std::vector<cv::DMatch>matches;
matcher.match( descriptors, descriptors1, matches );
cv::Mat img_matches;
drawMatches( image, keypoints, image1, keypoints1,matches, img_matches, cv::Scalar::all(-1), cv::Scalar::all(-1),std::vector<char>(), cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
imshow( "Matches", img_matches );
cv::waitKey(0);
return 0;
}
プログラムは「bad alloc」通信で matcher.match で中断しますが、問題は (おそらく)キーポイントベクトルです。これは、サイズが 0 で数億の容量があることを示しているためです (したがって、悪い alloc 問題)。関数 drawKeypointsは適切に機能し、keypoints ベクトル パラメータにもかかわらず適切に見える一連のキーポイントをイメージに描画します。Linker->追加の依存関係に、「d」なしでライブラリ名を含めたことを追加する必要があります。たとえば、 opencv_highgui230dの代わりにopencv_highgui230があります。. ライブラリ名に「d」が追加されていると、起動直後に「アプリケーションを正常に実行できません...」というメッセージが表示されてプログラムが終了するため、これは変更できませんでした。私は 7 64、VS 2010 を獲得しており、デバッグ モードでプログラムを実行しています。マッチャーの助けをいただければ幸いです