ubuntu18.04 安装 opencv(版本4.5.5) cmake(版本3.25)
参考链接🔗:安装cmake https://blog.csdn.net/Man_1man/article/details/126467371
安装 opencv https://blog.csdn.net/weixin_42888638/article/details/123316818
https://blog.csdn.net/wer4567/article/details/127033885
安装 libtorch https://blog.csdn.net/weixin_43742643/article/details/114156298 不是最新版本 新版本可到官网下载
报错解决方案:https://blog.csdn.net/PecoHe/article/details/97476135
1.安装依赖包
sudo apt-get update
sudo apt-get upgrade
sudo apt install ccache
sudo apt install libjasper1 libjasper-dev # 安装不了 解决方法:【sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"】
【sudo apt-get update】
【sudo apt-get install libjasper1 libjasper-dev】
sudo apt-get install libavresample-dev
sudo apt-get install libgphoto2-dev
sudo apt install libopenblas-base libopenblas-dev
sudo apt install libatlas-base-dev
sudo apt install doxygen
sudo apt install openjdk-8-jdk
sudo apt install libvtk6-dev
sudo apt-get install libgstreamer-plugins-base1.0-dev
sudo apt-get install libgtk-3-dev
sudo apt install libhdf5-dev
sudo apt install libgflags-dev
sudo apt install libgoogle-glog-dev
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
sudo apt-get install libvtk6-dev python-vtk6
sudo update-alternatives --install /usr/bin/vtk vtk /usr/bin/vtk6 10 # 暂时安装不了
2.cmake
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/cml/environment/opencv-4.5.5/opencv_contrib-4.5.5/modules BUILD_EXAMPLES=ON ..
cxf:
安装cmake
输入命令【wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -】
【sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'】
【sudo apt-get update】
【sudo apt install cmake】
查看cmkae版本【cmake --version】 版本号: 3.25
查看cmake路径【which cmake】
安装下载好的opencv-4.5.5
解压(源码放在/home/cxf/environment/opencv-4.5.5)
输入命令解压 【unzip opencv-4.5.5】(【tar -zxvf cmake-3.24.1.tar.gz】)
进入解压后的目录opencv-4.5.5,创建编译目录build并进入
输入命令【cd opencv-4.5.5/】
【mkdir build && cd build】
编译选择配置
先配置编译选项:(在build目录下操作)
输入命令【cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4 ../】
CMAKE_BUILD_TYPE ---指定编译发布版本
OPENCV_GENERATE_PKGCONFIG ---生成opencv4.pc文件,支持pkg-config功能
CMAKE_INSTALL_PREFIX---指定安装路径为/usr/lib/opencv4(若不指定则默认/usr/local)
../---指定根CMakeList.txt文件路径,在opencv-4.2.0根目录(../表示上一级)
输入命令【make】编译
4. make -j20
5. sudo make install
6. sudo gedit /etc/ld.so.conf
打开后在文件夹下添加一行
/usr/loacal/lib
运行下方命令
sudo ldconfig
7. 修改bash.bashrc文件
打开bash.bashrc
sudo gedit /etc/bash.bashrc
在末尾添加代码
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
然后输入命令
source /etc/bash.bashrc
8. 输入下方命令
pkg-config opencv --modversion
显示OpenCV版本则安装成功
libtorch 安装 https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.8.1%2Bcu102.zip