ubuntu18.04 -安装opencv_opencv unbun18.04-CSDN博客
先安装依赖 要不一会都是错
$ 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
1 下载opencv https://opencv.org/releases.html
我安装的3.20
2 进入 opencv的目录 新建文件夹 在新建的文件夹里面构建opencv 进行编译,这样不容易出错
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
安装目录可以自己改
3 编译 sudo make -j4 可以喝茶去了
4 然后安装 sudo make install
5添加库的路径 和环境变量
sudo gedit /etc/ld.so.conf.d/opencv.conf 写入/usr/local/lib
sudo ldconfig 生效
sudo gedit /etc/profile 添加环境变量
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
进行测试
进入opecv的 samples/cpp/example_cmake 执行如下
cmake .
make
./opencv_example
如果出现了错误
Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
1
提示是安装两个库文件 然后 重新编译,建议 两个库提前安装好 省着一会重新编译 从步骤3开始 再来一遍
安装libgtk2.0-dev和pkg-config
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
————————————————
原文链接:https://blog.csdn.net/qq_30951423/article/details/80914319