1. 安装依赖包
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 python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev # 处理图像所需的包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
sudo apt-get install ffmpeg
出现下面错误
errorE: unable to locate libjasper-dev
就运行下面命令
sudo apt-get install software-properties-common
sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe"
sudo apt update
sudo apt install libjasper1 libjasper-dev
然后继续安装依赖包
2. 下载并解压opencv安装包
从官网下载opencv的Sources, 并解压: https://opencv.org/releases/
3. 安装OpenCV
打开终端, cd到opencv解压位置
sudo mv opencv-4.1.1 /usr/local
cd /usr/local/opencv-4.1.1
sudo mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D CMAKE_PREFIX_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5
-D WITH_TBB=ON
-D WITH_V4L=ON
-D WITH_QT=ON
-D WITH_GTK=ON
-D WITH_OPENGL=ON
-D WITH_VTK=ON
-D OPENCV_GENERATE_PKGCONFIG=YES ..
sudo make -j4
sudo make install
/opt/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5
是我Qt的Qt5Config.cmake所在路径, 需要改成你自己的, 如果不需要opencv支持Qt用户界面, 可以把-D WITH_QT=ON
和-D CMAKE_PREFIX_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5
两行删掉.
另外, 不指定"Qt5Config.cmake"所在路径, 在cmake编译的时候可能会报如下错误:
CMake Error at cmake/OpenCVFindLibsGUI.cmake:18 (find_package):
Could not find a package configuration file provided by "Qt5" with any of
the following names:Qt5Config.cmake qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
4. 配置OpenCV环境
sudo gedit /etc/ld.so.conf.d/opencv.conf
在文件最后添加
/usr/local/lib
生效配置:
sudo ldconfig
此文原创禁止转载,转载文章请联系博主并注明来源和出处,谢谢!
作者: Raina_RLN https://www.cnblogs.com/raina/