Ubuntu18.04 安裝Opencv-3.4.1

one_DS 2022-01-08 02:22:54 阅读数:223

ubuntu18.04 ubuntu opencv-3.4.1 opencv 3.4.1

剛安裝ubuntu系統時,系統可能已經裝好了Opencv,但可能不是我們需要的版本,所以我們需要自己手動裝一下需要的版本。

一.查看是否安裝了opencv

pkg-config opencv --modversion

(輸出版本號則說明安裝好了Opencv)

二.若版本不是自己需要的,則使用卸載命令(謹慎)

sudo apt-get purge libopencv*

三.下載opencv和opencv_contrib的庫(這裏安裝的是3.4.1)

contrib庫:https://github.com/opencv/opencv_contrib/releases

opencv版本:https://opencv.org/releases.html

把兩個包解壓並將opencv_contrib-3.4.1整個文件夾移到opencv-3.4.1文件裏去

unzip opencv-3.4.1.zip
unzip opencv_contrib-3.4.1.zip
cp -r opencv_contrib-3.4.1 opencv-3.4.1

然後將opencv-3.4.1移至主目錄

四.安裝依賴

 sudo apt-get install build-essential libvtk5-dev
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install build-essential qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev

五.編譯

cd opencv-3.4.1
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv-3.4.1/opencv_contrib-3.4.1/modules/ -D BUILD_TIFF=ON ..
sudo make -j4
sudo make install

六.鏈接庫共享

sudo ldconfig -v

七.配置路徑

sudo gedit /etc/ld.so.conf.d/opencv.conf

執行此命令後打開的是一個空白的文件,在文件添加:

/usr/local/lib

執行如下命令使得剛才的配置路徑生效

sudo ldconfig

打開.bashrc:

sudo gedit /etc/bash.bashrc

在最末尾添加

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

保存,使得配置生效

source /etc/bash.bashrc

更新

sudo updatedb

八.再次查看是否安裝成功

pkg-config opencv --modversion
版权声明:本文为[one_DS]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/01/202201080222544183.html