2012-06-05 4 views
2

OpenCv 및 SIFT에 익숙해지기 위해이 간단한 예제를 구현하고 있습니다.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::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)'에서 라인에서

    • undefined reference to 'cv::SIFT::CommonParams::CommonParams()' 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 
    
  • +0

    은 당신이 features2d – silent

    답변

    5

    당신이 OpenCV의 라이브러리와 링크 잊어 버린 것 같다. 또한 OpenCV 2.4에 연결하는 경우 opencv_nonfree라는 이름의 "non-free"알고리즘을위한 새로운 라이브러리가 있습니다.이 라이브러리는 SIFT를 위해 링크해야합니다.

    +1

    '호출하기에 연결되지했습니다 GCC C++ 링커 g ++ -L/usr/지방/lib에 -o "BioInfo"./imageProcessingClass.o ./main.o -lopencv_core -lopencv_highgui' 그 밖의 무엇을해야 내가 링크 -lopencv_features2d? – Matteo

    +0

    옙 ... 퍽! 얼마나 어리석은 ... – Matteo