Ubuntu18.04编译opencv3.4.10报错undefined reference to `cv::cuda::SURF_CUDA::SURF_CUDA()及解决方案

使用opencv3.4.10源码进行编译,编译时增加opencv-contrib_3.4.10,具体下载地址可参见https://www.bzblog.online/wordpress/index.php/2020/03/09/opencvdownload/

报错内容

CMakeFiles/example_gpu_surf_keypoint_matcher.dir/surf_keypoint_matcher.cpp.o: In function main': surf_keypoint_matcher.cpp:(.text.startup.main+0x234): undefined reference tocv::cuda::SURF_CUDA::SURF_CUDA()’
surf_keypoint_matcher.cpp:(.text.startup.main+0x328): undefined reference to cv::cuda::SURF_CUDA::operator()(cv::cuda::GpuMat const&, cv::cuda::GpuMat const&, cv::cuda::GpuMat&, cv::cuda::GpuMat&, bool)' surf_keypoint_matcher.cpp:(.text.startup.main+0x380): undefined reference tocv::cuda::SURF_CUDA::operator()(cv::cuda::GpuMat const&, cv::cuda::GpuMat const&, cv::cuda::GpuMat&, cv::cuda::GpuMat&, bool)’
surf_keypoint_matcher.cpp:(.text.startup.main+0x408): undefined reference to cv::cuda::SURF_CUDA::defaultNorm() const' surf_keypoint_matcher.cpp:(.text.startup.main+0x4ac): undefined reference tocv::cuda::SURF_CUDA::downloadKeypoints(cv::cuda::GpuMat const&, std::vector&)’
surf_keypoint_matcher.cpp:(.text.startup.main+0x4c4): undefined reference to cv::cuda::SURF_CUDA::downloadKeypoints(cv::cuda::GpuMat const&, std::vector >&)' surf_keypoint_matcher.cpp:(.text.startup.main+0x4d4): undefined reference tocv::cuda::SURF_CUDA::downloadDescriptors(cv::cuda::GpuMat const&, std::vector&)’
surf_keypoint_matcher.cpp:(.text.startup.main+0x4e4): undefined reference to `cv::cuda::SURF_CUDA::downloadDescriptors(cv::cuda::GpuMat const&, std::vector&)’
collect2: error: ld returned 1 exit status
samples/gpu/CMakeFiles/example_gpu_surf_keypoint_matcher.dir/build.make:118: recipe for target ‘bin/example_gpu_surf_keypoint_matcher’ failed
make[2]: *** [bin/example_gpu_surf_keypoint_matcher] Error 1
CMakeFiles/Makefile2:16681: recipe for target ‘samples/gpu/CMakeFiles/example_gpu_surf_keypoint_matcher.dir/all’ failed
make[1]: *** [samples/gpu/CMakeFiles/example_gpu_surf_keypoint_matcher.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs…
[ 98%] Linking CXX shared library …/…/lib/libopencv_xfeatures2d.so
[ 99%] Built target opencv_xfeatures2d
Makefile:162: recipe for target ‘all’ failed
make: *** [all] Error 2

解决方案

将opencv3.4.10根目录下的CMakeLists.txt第207行作以下修改:

OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" OFF)

修改为:

OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" ON)

重新编译,即可解决。

你可能感兴趣的:(基础环境,深度学习,pytorch,python)