OpenCV3对OpenCV的模块进行了调整,将开发中与nonfree非免费模块放在 了OpenCV_contrib中(SURF,SIFT),因此需要在OPENCV基础上安装opencv_contrib。
简单解决办法:
sudo add-apt-repository ppa:ignaciovizzo/opencv3-nonfree
sudo apt-get update
sudo apt install libopencv-dev
参考来源:https://stackoverflow.com/questions/27418668/nonfree-module-is-missing-in-opencv-3-0
还是有错误:undefined reference to `cv::xfeatures2d::SURF::create(double, int, int, bool, bool)'
collect2: error: ld returned 1 exit status
github上下载对应版本opencv_contrib并解压缩 https://github.com/opencv/opencv_contrib/releases?after=4.0.0-beta
$ cd ~/opencv
$ mkdir build
$ cd build
$ sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.1/modules/ ..
$ sudo make -j4
$ sudo make install
$ sudo ldconfig
安装完成后LINKING错误消失。
SURF特征匹配的错误:
OpenCV Error: Assertion failed (!_img.empty() && ((imgtype) & ((1 << 3) - 1)) == 0 && (imgcn == 1 || imgcn == 3 || imgcn == 4)) in detectAndCompute, file /home/nl/opencv_contrib-3.3.1/modules/xfeatures2d/src/surf.cpp, line 892
因为是Mat类型错误,原为CV_32FC1应转为CV_8UC1
Img.convertTo(img1, CV_8UC1);