首先完全卸载刷机时自带的opencv旧版本,不同版本版本会引起冲突。
1. 先到opencv编译安装的目录build下
cd build
sudo make uninstall
cd ..
sudo rm -r build
2.也可以手动删除,总之删除干净即可。
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv
/usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv
/usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
3.检查是否删除完
pkg-config opencv –libs
pkg-config opencv –modversion
没有删除干净在用下面的命令,干净了就不用了,下面命令劲有点大,会连同依赖给删除了。
sudo apt-get purge libopencv*
sudo apt autoremove
sudo apt-get update
安装opencv 4.4
OpenCV源码下载官网地址: https://opencv.org.
点sources下载 opencv-4.4.0.zip
opencv_contrib下载地址: https://github.com/opencv/opencv_contrib
点击download zip下载opencv_contrib-4.4.0.zip
点tutorials进入官网安装教程,这才是最正宗的安装方法
解压上面下载的2个文件: opencv-4.4.0.zip opencv_contrib-4.4.0
主文件夹内新建opencv文件夹,把上面解压的2个文件夹放入opencv内
终端输入:
sudo apt update && sudo apt install -y cmake g++ wget unzip
cd opencv4.4
mkdir -p build && cd build
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules ../opencv-4.4.0
make -j4
这个报错是因为编译的时候需要下载文件,尔文件在国外,下载不了,导致编译出错,opencv官网有对这个问题的解决方法,参考官网链接:
https://github.com/opencv/opencv_contrib/issues/1301
提示缺少文件boostdesc_lbgm.i等,这些文件一共11个,在下面可以下载到,下载完解压,放入 opencv_contrib-4.4.0/modules/xfeatures2d/src 内,是最简单的解决办法。
百度网盘 请输入提取码 提取码 e1wc
我也试了其他网友提供的下载文件,没有编译成功,应该是不同版本文件有区别。
这个错误是需要导入头文件的位置不对,按下面图片改一下test_features2d.cpp 51 52行,test_rotation_and_scale_invariance.cpp 7 8行就能通过编译。
make -j4
sudo make install
至此安装完成,按照官网安装步骤会少走很多弯路。
按官方文档安装的程序一般是能正常运行的,但在运行orb_slam3却会报错
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.2.0) /home/ros2/opencv4.4/opencv-4.4.0/modules/highgui/src/window.cpp:634: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvNamedWindow’
问题出在,安装opencv时编译配置出现了问题。
如果opencv工作不正常删除build文件夹重新用下面命令编译:
cd opencv4.4
rm -rf build
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules ../opencv-4.4.0
make -j4
sudo make install
解决方法参考:
The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support_JT_BOT的博客-CSDN博客
文章出处登录后可见!