2014-01-22 126 views
0

最近一直在使用一些OpenCV,但是我遇到了一個有趣的問題。我有一個簡單的類來存儲數據並將數據讀寫到文件中。OpenCV未定義的參考(FileStorage與矢量<KeyPoint>)

這裏是寫功能:

cv::Mat descriptors; 
vector<cv::KeyPoint> keypoints; 

void EventType::write(cv::FileStorage outfile) { 
    outfile << "descriptorId" << descriptors; 
    outfile << "keypointId" << keypoints; 
} 

問題棱同時連接:

EventType.cpp.o: In function cv::FileStorage& cv::operator<< <std::vector<cv::KeyPoint, 
    std::allocator<cv::KeyPoint> > >(cv::FileStorage&, std::vector<cv::KeyPoint, 
    std::allocator<cv::KeyPoint> > const&)': 
EventType.cpp:(.text+0xc99): undefined reference to `cv::write(cv::FileStorage&, 
    std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, 
    std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&)' 

然而也當連接它提出了以下方案:

/opencv2/core/operations.hpp:2707: note: candidates are: void cv::write(cv::FileStorage&, const std::string&, int) 
/opencv2/core/operations.hpp:2708: note:     void cv::write(cv::FileStorage&, const std::string&, float) 
/opencv2/core/operations.hpp:2709: note:     void cv::write(cv::FileStorage&, const std::string&, double) 
/opencv2/core/operations.hpp:2710: note:     void cv::write(cv::FileStorage&, const std::string&, const std::string&) 
/opencv2/core/operations.hpp:2787: note:     void cv::write(cv::FileStorage&, const cv::Range&) 
/opencv2/core/operations.hpp:2856: note:     void cv::write(cv::FileStorage&, const std::string&, const cv::Range&) 
/opencv2/core/operations.hpp:2902: note:     void cv::write(cv::FileStorage&, const std::string&, const cv::Mat&) 
/opencv2/core/operations.hpp:2903: note:     void cv::write(cv::FileStorage&, const std::string&, const cv::SparseMat&) 
/opencv2/features2d/features2d.hpp:112: note:     void cv::write(cv::FileStorage&, const std::string&, const std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&) 

這似乎我認爲/opencv2/features2d/features2d.hpp的原型是完美的搭配。有什麼建議麼?

回答

-1

問題出在我的FindOpenCV.cmake文件中。 features2d庫沒有被鏈接。

1

如果鏈接器說「未定義引用」,編譯步驟已經完成,這意味着編譯器接受你的函數爲有效。

嘗試鏈接所有的opencv庫,看看是否改變結果。同時檢查您正在使用的標題與您嘗試鏈接到的庫的版本是否相同。

+0

謝謝,這幫助我找到了問題。 :) – Kazz