简体   繁体   English

OpenCv 2.4.3:找不到读取和SurfFeatureDetector :: detect

[英]OpenCv 2.4.3: can't find imread and SurfFeatureDetector::detect

on Mac OSX 10.8, XCode 4.6, in C++ 在Mac OSX 10.8,XCode 4.6和C ++中

I'm following the tutorial in opencv_tutorials.pdf , located in /opt/local/share/OpenCV/doc on my system. 我正在遵循系统中/opt/local/share/OpenCV/docopencv_tutorials.pdf的教程。 On page 311, we get this sample (slightly edited): 在第311页,我们获得了此样本(略作编辑):

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv; 
int main( int argc, char** argv ) {
  Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
  int minHessian = 400;
  SurfFeatureDetector detector( minHessian );
  std::vector<KeyPoint> keypoints_1;
  detector.detect( img_1, keypoints_1 );
}

I had to modify the code above to #include "opencv2/nonFree/features2d.hpp" , a file that I found by running 我必须将上面的代码修改为#include "opencv2/nonFree/features2d.hpp" ,这是我通过运行找到的文件

find /opt/local/include -name "*.hpp" -exec grep SurfFeatureDetector "{}" ';' -print

The code compiles, meaning that the symbol detector.detect is found in the hpp file and passes type-checking by the C++ compiler. 该代码将进行编译,这意味着在hpp文件中可以找到符号detector.detect ,并通过C ++编译器进行类型检查。 Next is to try to find the libraries that contain the symbols. 接下来是尝试查找包含符号的库。

Now, I have these libraries in my distribution, in /opt/local/lib : 现在,我在/opt/local/lib有这些库:

libopencv_calib3d.2.4.3.dylib
libopencv_contrib.2.4.3.dylib
libopencv_core.2.4.3.dylib
libopencv_features2d.2.4.3.dylib
libopencv_flann.2.4.3.dylib
libopencv_gpu.2.4.3.dylib
libopencv_highgui.2.4.3.dylib
libopencv_imgproc.2.4.3.dylib
libopencv_legacy.2.4.3.dylib
libopencv_ml.2.4.3.dylib
libopencv_nonfree.2.4.3.dylib
libopencv_objdetect.2.4.3.dylib
libopencv_photo.2.4.3.dylib
libopencv_stitching.2.4.3.dylib
libopencv_ts.2.4.3.dylib
libopencv_video.2.4.3.dylib
libopencv_videostab.2.4.3.dylib

I found it uninformative to nm search these for the required symbols because name mangling is difficult to decompile in my head. 我发现nm搜索这些必需的符号没有任何意义,因为名称修饰很难在我的脑海中反编译。 I just brute-force included all the libraries, but still get linker errors: 我只是蛮力地包括了所有库,但仍然出现链接器错误:

Undefined symbols for architecture x86_64:
  "cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
      _main in main.o
  "cv::FeatureDetector::detect(cv::Mat const&, std::__1::vector<cv::KeyPoint, std::__1::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64

I've done some spot-checking of the OpenCv reference documents and the wiki pages, starting from here 从这里开始,我已经对OpenCv参考文档和Wiki页面进行了一些抽查。

http://opencv.willowgarage.com/documentation/cpp/features2d__feature_detection_and_descriptor_extraction.html

but without success. 但没有成功。

I'd be grateful for 我会很感激

  1. specific help in finding these OpenCv APIs 查找这些OpenCv API的特定帮助
  2. general strategies for this kind of query: "what library contains the symbol I need to link against". 这种查询的一般策略是:“哪个库包含我需要链接的符号”。 This kind of problem makes me hate C++, since 5 minutes of coding always seems to lead to hours of hit-and-miss library searching, possibly because I just don't know the professional secret for doing this. 这种问题使我讨厌C ++,因为5分钟的编码似乎总是导致数小时的搜索库丢失,这可能是因为我不知道这样做的专业秘密。

在Linux上并使用OpenCV 3.0.0,我必须链接到opencv_imgcodecs共享库。

My toolchain utilizes CMake to keep track of these sorts of things. 我的工具链利用CMake来跟踪这些事情。 For most new libraries I use, there are usually google searchable accompanying Find*.cmake files that are written by others. 对于我使用的大多数新库,通常都会有google可搜索的伴随着其他人编写的Find * .cmake文件。 If you wanted more information about my specific set-up, feel free to ask. 如果您想了解有关我的特定设置的更多信息,请随时询问。 I have seen this specific problem (Undefined symbols for architecture x86_64) a few times for things in the nonfree libraries. 对于非自由库中的内容,我已经多次看到此特定问题(体系结构x86_64的未定义符号)。 I'm not sure why you are getting that error for the imread, though. 不过,我不确定为什么您会收到该错误。 The first place I would look is the matcher_simple.cpp example in the samples/cpp folder. 我首先要看的是samples / cpp文件夹中的matcher_simple.cpp示例。 If you can compile and run this (using this ) and the other examples, your set-up should be ok. 如果您可以编译并运行此代码(使用this )和其他示例,则设置应该可以。 If you can't, can you please post the errors of that example? 如果不能,请张贴该示例的错误信息吗? I'm not familiar with XCode but someone else suggested going to Build Settings>Build Options> Compiler for C/C++/Objective-C and change it from Apple LLVM Compiler to LLVM GCC 4.2. 我不熟悉XCode,但是其他人建议转到Build Settings> Build Options> C / C ++ / Objective-C的编译器,并将其从Apple LLVM编译器更改为LLVM GCC 4.2。 And there are a few other guesses here too. 还有一些其他的猜测在这里了。

Try including -lopencv_features2d and -lopencv_nonfree in your list of Other Linker Flags in the Build Settings. 尝试在构建设置中的其他链接器标志列表中包括-lopencv_features2d-lopencv_nonfree I was getting the same problems and it worked for me 我遇到了同样的问题,对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM