簡體   English   中英

OpenCV上的簡單SIFT檢測器問題

[英]Simple SIFT Detector ISSUE on OpenCV

我實現這個簡單的示例只是為了熟悉OpenCv和SIFT。

1  #include <opencv2/core/core.hpp>
2  #include <opencv2/features2d/features2d.hpp>
3  #include <opencv2/highgui/highgui.hpp>
4
5  using namespace std;
6 
7  int main(int argc, char** argv) {
8
9     const cv::Mat input = cv::imread("/tmp/image.jpg", 0); //Load as grayscale
10
11    cv::SiftFeatureDetector detector;
12    std::vector<cv::KeyPoint> keypoints;
13    detector.detect(input, keypoints);
14
15    // Add results to image and save.
16    cv::Mat output;
17    cv::drawKeypoints(input, keypoints, output);
18    cv::imwrite("/tmp/SIFT_RESULT.jpg", output);
19
20    return 0;
21
22 }

我原以為它很簡單,但是會引發以下錯誤:

  • 在第11行undefined reference to 'cv::SIFT::CommonParams::CommonParams()'
  • undefined reference to 'cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const' 13行
  • undefined reference to 'cv::drawKeypoints(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat&, cv::Scalar_<double> const&, int)'在第17行

你能告訴我出什么事了嗎? 這是代碼中的問題,還是我缺少一些headers


完整的構建輸出:

make all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: BioInfo
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "BioInfo"  ./imageProcessingClass.o ./main.o   -lopencv_core -lopencv_highgui
./main.o: In function `main':
/.../Debug/../main.cpp:38: undefined reference to `cv::SIFT::CommonParams::CommonParams()'
/.../Debug/../main.cpp:38: undefined reference to `cv::SIFT::DetectorParams::DetectorParams()'
/.../Debug/../main.cpp:38: undefined reference to `cv::SiftFeatureDetector::SiftFeatureDetector(cv::SIFT::DetectorParams const&, cv::SIFT::CommonParams const&)'
/.../Debug/../main.cpp:40: undefined reference to `cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const'
/.../Debug/../main.cpp:44: undefined reference to `cv::drawKeypoints(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat&, cv::Scalar_<double> const&, int)'
./main.o: In function `~SiftFeatureDetector':
/usr/local/include/opencv2/features2d/features2d.hpp:1502: undefined reference to `vtable for cv::SiftFeatureDetector'
/usr/local/include/opencv2/features2d/features2d.hpp:1502: undefined reference to `cv::FeatureDetector::~FeatureDetector()'
collect2: ld returned 1 exit status
make: *** [BioInfo] Error 1

Build Finished

似乎您忘記了與OpenCV庫的鏈接。 還請記住,如果要針對OpenCV 2.4進行鏈接,則有一個名為opencv_nonfree的“非自由”算法新庫,您需要針對該庫進行SIFT鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM