注意;要退出conda的虚拟环境
依赖
1.更新系统
sudo apt-get update
sudo apt-get upgrade
2.安装相关的依赖
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libatlas-base-dev gfortran
这里可能遇到报错
debug
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
然后继续
OpenCV
3.下载OpenCV
git clone https://github.com/opencv/opencv.git
4.进入到OpenCV所在的路径
cd opencv
mkdir build
编译
5.编译安装
依次输入如下命令:
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
这里的make报错
跟conda的虚拟环境有关,需要退出(删除之前的build文件夹重新cmake和make)
linux下安装opencv(c++)的一些踩坑问题_维维诺诺x的博客-CSDN博客
然后继续
这里编译成功
sudo make install
然后就安装依赖成功了
sudo nano /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
g++ -o test_opencv test_opencv.cpp `pkg-config opencv --cflags --libs`
./test_opencv