###前提・実現したいこと
VisualStudio15 2017上でOpenCVを動かし、SIFT特徴量を用いた画像マッチングに取り組もうと思っています。
しかし、コンパイルで以下のエラーが発生し解決策が見つからず困っている状況です。
###発生している問題・エラーメッセージ
・エラーメッセージ namespace "cv" にメンバー "initModule_nonfree" がありません class "cv::Feature2D" にメンバー "create" がありません class "cv::Feature2D" にメンバー "create" がありません
###該当のソースコード
C++
1#include <opencv2/opencv.hpp> 2#include <opencv2/xfeatures2d/nonfree.hpp> // SIFT・SURFモジュール用 3 4void FeatureMatching( 5 const std::string& lenna, // 画像1のファイル名 6 const std::string& lenna2, // 画像2のファイル名 7 const std::string& STAR, // detectorType 8 const std::string& FREAK, // descriptorExtractorType 9 const std::string& MATCH, // descriptorMatcherType 10 bool crossCheck = true) // マッチング結果をクロスチェックするかどうか 11{ 12 // 画像の読み込み 13 cv::Mat img1 = cv::imread("C:\opencv\image\lenna.jpg"); 14 cv::Mat img2 = cv::imread("C:\opencv\image\lenna2.jpg"); 15 16 // SIFT・SURFモジュールの初期化 17 cv::initModule_nonfree(); 18 19 // 特徴点抽出 20 cv::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create("STAR"); 21 std::vector<cv::KeyPoint> keypoint1, keypoint2; 22 detector->detect(img1, keypoint1); 23 detector->detect(img2, keypoint2); 24 25 // 特徴記述 26 cv::Ptr<cv::DescriptorExtractor> extractor = cv::DescriptorExtractor::create("FREAK"); 27 cv::Mat descriptor1, descriptor2; 28 extractor->compute(img1, keypoint1, descriptor1); 29 extractor->compute(img2, keypoint2, descriptor2); 30 31 // マッチング 32 cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("MATCH"); 33 std::vector<cv::DMatch> dmatch; 34 if (crossCheck) 35 { 36 // クロスチェックする場合 37 std::vector<cv::DMatch> match12, match21; 38 matcher->match(descriptor1, descriptor2, match12); 39 matcher->match(descriptor2, descriptor1, match21); 40 for (size_t i = 0; i < match12.size(); i++) 41 { 42 cv::DMatch forward = match12[i]; 43 cv::DMatch backward = match21[forward.trainIdx]; 44 if (backward.trainIdx == forward.queryIdx) 45 dmatch.push_back(forward); 46 } 47 } 48 else 49 { 50 // クロスチェックしない場合 51 matcher->match(descriptor1, descriptor2, dmatch); 52 } 53 54 // マッチング結果の表示 55 cv::Mat out; 56 cv::drawMatches(img1, keypoint1, img2, keypoint2, dmatch, out); 57 cv::imshow("matching", out); 58 while (cv::waitKey(1) == -1); 59}
###試したこと
OpenCVのソースをCmakeでコンパイルし導入。
(参照サイト:https://qiita.com/tomochiii/items/fa26404ebc5fcd4481b9)
(contrib\moduleのパスも設定済)
さらに別サイト(http://whoopsidaisies.hatenablog.com/entry/2013/12/07/135810)を参考にソースコードを入力し、OpenCV3以降の仕様変更に合わせ
"#include <opencv2/nonfree/nonfree.hpp>"
の部分を
"#include <opencv2/xfeatures2d/nonfree.hpp>"
に変更しました。
また、元のソースコードのfilename1,filename2,featureDetectorName,descriptorExtractorName,descriptorMatcherNameに何かしらの入力が必要かと思い、それぞれ適当な文字列を入力しました。
###補足情報(言語/FW/ツール等のバージョンなど)
VisualStudio15 2017
OpenCV 3.2.0
(OpenCV 3.1.0でも試したところ同エラーにより動かず)

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/30 03:16
2017/10/30 03:58