我正在尝试运行 OpenCV 中的教程示例之一。它是关于使用基于 Flann 的关键点匹配来查找已知对象。可以在Features2D+Homography 上找到代码来查找已知对象。
我知道你会问“你链接图书馆了吗?” 或类似的问题。是的,我已经使用 OpenCV 3 周了,其中包含几乎所有库的各种示例。直到今天都没有问题。
所以我将这些库依赖项添加到 Visual Studio 的链接器输入设置中。包含目录也可以正常工作。
C:\OpenCV2.4\lib\opencv_core242d.lib
C:\OpenCV2.4\lib\opencv_highgui242d.lib
C:\OpenCV2.4\lib\opencv_video242d.lib
C:\OpenCV2.4\lib\opencv_ml242d.lib
C:\OpenCV2.4\lib\opencv_legacy242d.lib
C:\OpenCV2.4\lib\opencv_imgproc242d.lib
C:\OpenCV2.4\lib\opencv_objdetect242d.lib
C:\OpenCV2.4\lib\opencv_flann242d.lib
C:\OpenCV2.4\lib\opencv_nonfree242d.lib
C:\OpenCV2.4\lib\opencv_calib3d242d.lib
我得到的错误是链接器错误。它无法解析 Flann 的函数。
1>------ Build started: Project: flannMatch, Configuration: Debug Win32 ------
1>flannMatch.obj : error LNK2019: unresolved external symbol "void __cdecl cv::drawMatches(class cv::Mat const &,class std::vector<class cv::KeyPoint,class std::allocator<class cv::KeyPoint> > const &,class cv::Mat const &,class std::vector<class cv::KeyPoint,class std::allocator<class cv::KeyPoint> > const &,class std::vector<struct cv::DMatch,class std::allocator<struct cv::DMatch> > const &,class cv::Mat &,class cv::Scalar_<double> const &,class cv::Scalar_<double> const &,class std::vector<char,class std::allocator<char> > const &,int)" (?drawMatches@cv@@YAXABVMat@1@ABV?$vector@VKeyPoint@cv@@V?$allocator@VKeyPoint@cv@@@std@@@std@@01ABV?$vector@UDMatch@cv@@V?$allocator@UDMatch@cv@@@std@@@4@AAV21@ABV?$Scalar_@N@1@4ABV?$vector@DV?$allocator@D@std@@@4@H@Z) referenced in function _main
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::DescriptorMatcher::match(class cv::Mat const &,class cv::Mat const &,class std::vector<struct cv::DMatch,class std::allocator<struct cv::DMatch> > &,class cv::Mat const &)const " (?match@DescriptorMatcher@cv@@QBEXABVMat@2@0AAV?$vector@UDMatch@cv@@V?$allocator@UDMatch@cv@@@std@@@std@@0@Z) referenced in function_main
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::FlannBasedMatcher::FlannBasedMatcher(class cv::Ptr<struct cv::flann::IndexParams> const &,class cv::Ptr<struct cv::flann::SearchParams> const &)" (??0FlannBasedMatcher@cv@@QAE@ABV?$Ptr@UIndexParams@flann@cv@@@1@ABV?$Ptr@USearchParams@flann@cv@@@1@@Z) referenced in function _main
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::DescriptorExtractor::compute(class cv::Mat const &,class std::vector<class cv::KeyPoint,class std::allocator<class cv::KeyPoint> > &,class cv::Mat &)const " (?compute@DescriptorExtractor@cv@@QBEXABVMat@2@AAV?$vector@VKeyPoint@cv@@V?$allocator@VKeyPoint@cv@@@std@@@std@@AAV32@@Z) referenced in function _main
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::FeatureDetector::detect(class cv::Mat const &,class std::vector<class cv::KeyPoint,class std::allocator<class cv::KeyPoint> > &,class cv::Mat const &)const " (?detect@FeatureDetector@cv@@QBEXABVMat@2@AAV?$vector@VKeyPoint@cv@@V?$allocator@VKeyPoint@cv@@@std@@@std@@0@Z) referenced in function _main
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::DescriptorMatcher::~DescriptorMatcher(void)" (??1DescriptorMatcher@cv@@UAE@XZ) referenced in function "public: virtual __thiscall cv::FlannBasedMatcher::~FlannBasedMatcher(void)" (??1FlannBasedMatcher@cv@@UAE@XZ)
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::DescriptorMatcher::DescriptorCollection::~DescriptorCollection(void)" (??1DescriptorCollection@DescriptorMatcher@cv@@UAE@XZ) referenced in function "public: virtual __thiscall cv::FlannBasedMatcher::~FlannBasedMatcher(void)" (??1FlannBasedMatcher@cv@@UAE@XZ)
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::FeatureDetector::~FeatureDetector(void)" (??1FeatureDetector@cv@@UAE@XZ) referenced in function "public: virtual __thiscall cv::Feature2D::~Feature2D(void)" (??1Feature2D@cv@@UAE@XZ)
1>flannMatch.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::DescriptorExtractor::~DescriptorExtractor(void)" (??1DescriptorExtractor@cv@@UAE@XZ) referenced in function "public: virtual __thiscall cv::Feature2D::~Feature2D(void)" (??1Feature2D@cv@@UAE@XZ)
由于此处的一个问题,我也知道 surf and sift 已移至非免费。乍一看,我认为这可能是因为我有两个版本的 OpenCV(2.2 和 2.4),因此它有所作为。所以我删除了 2.2 并尝试运行另一个程序。它工作正常,但这个错误仍然没有消失。
所以我的问题是,我在这里缺少什么?是否有另一个库依赖项?什么是我看不见的?任何帮助表示赞赏。
--编辑--
我怎么看不到?我真的很抱歉发布这样一个简单的问题。我觉得自己好傻。我忘记添加此依赖项。
C:\OpenCV2.4\lib\opencv_features2d242d.lib
我不认为有人会再次错过。