卸载自己另外安装的OpenCV库
进入到最开始自己的安装opencv的build目录
sudo make uninstall
然后返回到初始目录,删除掉build目录
sudo rm -r build
删除opencv其他的相关文件
sudo rm -r /usr/local/include/opencv2
sudo rm -r /usr/local/include/opencv
sudo rm -r /usr/include/opencv
sudo rm -r /usr/include/opencv2
sudo rm -r /usr/local/share/opencv
sudo rm -r /usr/local/share/OpenCV
sudo rm -r /usr/share/opencv
sudo rm -r /usr/share/OpenCV
sudo rm -r /usr/local/bin/opencv*
sudo rm -r /usr/local/lib/libopencv*
sudo rm -r usr/bin/opencv*
sudo rm -r /usr/lib/libopencv*
前四行命令中的opencv2,有些有可能自己命名了opencv4,在相关目录下删除掉跟opencv相关的文件夹就可以。
检查是否完全删除:
pkg-config opencv4 --libs
pkg-config opencv4 --modversion
下载OpenCV
源程序下载地址 https://github.com/opencv
文件夹组织
下载好解压后,将opencv_contrib4.5.5放在opencv4.5.5文件夹下。
在opencv_contrib-4.5.0/modules/xfeatures2d/src/目录下添加如下文件:
可以到我的gitee下载https://gitee.com/teriri_0223/myopencv
boostdesc_bgm.i
boostdesc_bgm_bi.i
boostdesc_lbgm.i
boostdesc_bgm_hd.i
boostdesc_binboost_064.i
boostdesc_binboost_128.i
boostdesc_binboost_256.i
vgg_generated_120.i
vgg_generated_80.i
vgg_generated_64.i
vgg_generated_48.i
拷贝头文件
将opencv-4.5.5/modules/features2d/test/目录下的如下文件:
test_descriptors_invariance.impl.hpp
test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp
拷至opencv_contrib-4.5.5/modules/xfeatures2d/test/目录下。
修改头文件
(1)将opencv_contrib-4.5.0/modules/xfeatures2d/test/test_features2d.cpp文件中包含的头文件代码:
#include "features2d/test/test_detectors_regression.impl.hpp"
#include "features2d/test/test_descriptors_regression.impl.hpp"
修改为:
#include "test_detectors_regression.impl.hpp"
#include "test_descriptors_regression.impl.hpp"
(2)将opencv_contrib4.2.0/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp文件中包含的头文件代码:
#include "features2d/test/test_detectors_invariance.impl.hpp"
#include "features2d/test/test_descriptors_invariance.impl.hpp"
修改为:
#include "test_detectors_invariance.impl.hpp"
#include "test_descriptors_invariance.impl.hpp"
环境配置
sudo apt-get install cmake
sudo apt-get install gcc g++
sudo apt-get install python-dev python-numpy
sudo apt-get install python3-dev python3-numpy
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
sudo apt-get install libgtk-3-dev
sudo apt install build-essential
sudo apt install libopenexr-dev
sudo apt install libgtk2.0-dev
sudo apt install libjpeg-dev
sudo apt install libtiff-dev
sudo apt install libpng-dev
sudo apt install software-properties-common
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
CMAKE配置和安装
在opencv-4.5.5根目录下创建build.sh的脚本,脚本内容如下:
#!/bin/bash
if [[ ! -d build ]]; then
mkdir build
fi
cd build
rm -rf *
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON -D OPENCV_GENERATE_PKGCONFIG=ON .. #生成.pc文件
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. #安装路径
cmake -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.5/modules \ # opencv_contrib所在路径
-D OPENCV_ENABLE_NONFREE=ON \
..
make -j2 #可以为j4或j8 看你cpu核心数
make install
运行
chmod 777 build.sh
./build.sh
环境配置
修改opencv.conf文件,终端输入
sudo gedit /etc/ld.so.conf.d/opencv.conf
然后在文件中输入
/usr/local/lib
保存后终端输入
sudo ldconfig
更新共享链接库
然后配置bash,修改bash.bashrc文件
sudo gedit /etc/bash.bashrc
在文末加上
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存后退出,终端输入以下命令使配置生效
source ~/.bashrc
更新一下
sudo updatedb
可能遇到的问题
install configuration: "release" cmake error at cmake_install.cmake:41 (file): file can
make install改成sudo make install就可以解决了文章来源:https://www.toymoban.com/news/detail-773042.html
make: *** [Makefile:1316:cmake_check_build_system] 错误 1
可能是你的OPENCV_EXTRA_MODULES_PATH=…/opencv_contrib-4.5.5/modules 路径不对文章来源地址https://www.toymoban.com/news/detail-773042.html
到了这里,关于Ubuntu20.04安装OpenCV4.5.5和OpenCV_Contrib4.5.5的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!