opencv:对`cv :: cuda :: DescriptorMatcher :: createBFMatcher(int)'的未定义引用

时间:2016-06-06 11:20:22

标签: c++ opencv

我正在尝试通过以下方式编译opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_keypoint_matcher.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d

但是我收到了这个错误:

/tmp/ccQW7t3Z.o: In function `main':
/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status

为什么?

2 个答案:

答案 0 :(得分:1)

您的错误消息:

/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status

表示您对cv::cuda::DescriptorMatcher::createBFMatcher

有未定义的引用

这位于cuda libs中,因此您需要包含相应的标题并链接到以下库中,因为opencv_cudafeatures2d取决于它们:

  • opencv_cudafilters
  • opencv_cudawarping
  • opencv_features2d
  • opencv_cudaarithmn
  • opencv_flann
  • opencv_core

对于我正在使用的opencv 3.1.0版本来说确实如此

答案 1 :(得分:0)

DescriptorMatcher is in cudafeatures2d.hpp。因此,您必须在.cpp程序和link the library in the compile process中添加标头cudafeatures2d.hpp

如果您使用此-lopencv_cudafeatures2d

,程序将会运行

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_gpu_probe1.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d -lopencv_cudafeatures2d