分别执行下面三条命令
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install build-essential libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
在运行第三条时,会有Error: unable to locate libjasper-dev的报错
解决方法:分别执行下面三条命令后,再重新执行第三条
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
下载链接:https://opencv.org/releases/
选择对应的版本:opencv4.1.1
点击 sources 下载压缩包
下载链接:https://github.com/opencv/opencv_contrib/releases
选择对应的版本:opencv4.1.1
将压缩包上传到Ubuntu上后,进行解压
unzip opencv-4.1.1.zip
unzip opencv_contrib-4.1.1.zip
cd opencv-4.1.1
mkdir build
cd build
1)fatal error: features2d/test/test_detectors_regression.impl.hpp: No such file or directory
2)fatal error: boostdesc_bgm.i: No such file or directory
解决方法:
1)解决第一个fatal error: features2d/test/test_detectors_regression.impl.hpp: No such file or directory问题
将在 opencv4.1.1/modules/ 目录下的features2d文件夹复制到build目录中
2)解决第二个fatal error: boostdesc_bgm.i: No such file or directory问题
下载下面的文件
百度云网盘链接:https://pan.baidu.com/s/1l9vhv1hTjerzX-EDFJRCyA
提取码:iwsr
将文件夹里的所有文件拷贝到 opencv_contrib4.1.1/modules/xfeatures2d/src 目录下就可以了
//进入opencv4.1.1的build文件下
cd build
/*
配置命令
其中-D OPENCV_EXTRA_MODULES_PATH=/home/tao/opencv/opencv-4.1.1/opencv_contrib-4.1.1/modules
是opencv_contrib4.1.1里的modules文件的路径,根据自己的来改
*/
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/tao/opencv/opencv-4.1.1/opencv_contrib-4.1.1/modules ..
//编译命令
sudo make -j4
//安装
sudo make install
安装python和numpy
sudo apt-get install python-dev python-numpy python3-dev python3-numpy
先在/etc/ld.so.conf.d/文件夹下新建一个opencv4.conf,然后写入/usr/local/lib
sudo touch /etc/ld.so.conf.d/opencv4.conf
sudo sh -c 'echo "/usr/local/lib" > opencv4.conf'
更新pkg-config
sudo ldconfig
查看安装
pkg-config --libs opencv4
pkg-config --cflags opencv4
cd ./opencv-4.1.1/samples/cpp
g++ `pkg-config --cflags opencv4` drawing.cpp `pkg-config --libs opencv4` -o drawing.out
./drawing.out
sudo rm /etc/ld.so.conf.d/opencv4.conf
cd ./opencv-4.1.1/build //进入build文件
sudo make uninstall
参考博文
https://blog.csdn.net/weixin_41921520/article/details/97927633
https://blog.csdn.net/xiewenrui1996/article/details/108683866