之前写过一篇在Ubuntu18.04下安装opencv4.5的攻略,具体是参考了官方的一些文档,但是opencv中的很多应用在后来进行了删减,如果想要使用opencv训练xml文件,需要用到其他的训练器,因此安装了opencv3.4.3
opencv 3.4.3选择Source Code.zip下载;
opencv_contrib 3.4.3克隆下载软件包
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev
将刚刚下载的文件放到该文件夹下并解压:
mkdir ~/opencv_build && cd ~/opencv_build
cd ~/opencv_build/opencv
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
sudo make -j8
编译过程中可能遇见TIFFReadDirectory@LIBTIFF_4.0’未定义的引用类似的错误,需要到libtiff下载对应的tiff-4.0.4.tar.gz压缩包安装。
但,系统已经默认安装了libtiff5,需要先将这个给移除:
sudo apt-get autoremove liblept5
之后关掉这个窗口,进入到下载的文件的目录,解压之后执行:
./configure
sudo make
sudo make install
不添加sudo可能会遇见Error1的错误,所以需要注意。
sudo make install
8-1:将OpenCV的库添加到路径,从而可以让系统找到
sudo gedit /etc/ld.so.conf.d/opencv.conf
8-2:打开的是一个空白文件,在里面添加,然后保存:
/usr/local/lib
8-3:编译一下使其生效:
sudo ldconfig
8-4:配置bash
sudo gedit /etc/bash.bashrc
8-5: 文末添加内容并编译:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
8-6:执行命令使其生效
source /etc/bash.bashrc
更新:
sudo updatedb
点开opencv-3.4.3samples/cpp/example_cmake右键打开终端输入下面的代码
cmake .
make
./opencv_example
参考链接:
https://blog.csdn.net/qq_41080854/article/details/88609795
https://docs.opencv.org/3.4.0/
https://github.com/opencv/opencv/releases/tag/3.4.3
https://github.com/opencv/opencv_contrib/tree/3.4.3
https://blog.csdn.net/u011361393/article/details/83210824
http://download.osgeo.org/libtiff/
https://www.learnopencv.com/install-opencv-3-4-4-on-ubuntu-18-04/