赞
踩
- # 更新源,安装软件包
- sudo apt update && sudo apt install -y cmake g++ wget unzip
-
- #安装依赖
- sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
- sudo apt-get install libgtk2.0-dev
- sudo apt-get install pkg-config
OpenCV · GitHubhttps://github.com/opencv
两个安装包放在home目录下,通过以下命令解压
- ~$ unzip opencv-3.4.8.zip
- ~$ unzip opencv_contrib-3.4.8.zip
将文件夹opencv_contrib-3.4.8移动到文件夹opencv-3.4.8中:
mv opencv_contrib-3.4.8 opencv-3.4.8
在opencv-3.4.8文件夹中新建“build”目录
- ~$ cd opencv-3.4.8
- ~/opencv-3.4.8$ mkdir build
- ~/opencv-3.4.8$ cd build
运行如下命令配置:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=/home/<yourusername>/opencv-3.4.8/opencv_contrib-3.4.8/modules ..
如果没有错误发生,运行如下命令编译工程:
make -j7
如果没有错误发生,运行如下命令安装:
sudo gedit /etc/ld.so.conf.d/opencv.conf
然后在打开文件中添加如下内容:
/usr/local/lib
之后再终端输入以下命令(安装完成某个工程后生成许多动态库,该命令是为了让这些动态链接库为系统所共享)
sudo ldconfig
使其保存并生效,再在终端输入
sudo gedit /etc/bash.bashrc
打开文件后在末尾输入:
- PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
- export PKG_CONFIG_PATH
保存退出,终端输入:
source /etc/bash.bashrc
进入opencv/samples/cpp/example_cmake目录下,终端打开,依次输入:
- cd ../samples/cpp/example_cmake
- cmake .
- make
- ./opencv_example
结束
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。