OpenCV环境搭建-Ubuntu
OpenCV官方发布地址:https://opencv.org/releases/
OpenCV官方教程地址:https://docs.opencv.org/master/d9/df8/tutorial_root.html
0.下载并解压源码,并进入源码根目录
例如:解压下载后的opencv-3.4.1.tar.gz;进入opencv-3.4.1
1.安装cmake和依赖库
#sudo apt-get update
#sudo apt-get install cmake
#sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
2.创建并进入编译目录
#mkdir release && cd release
3.cmake生成Makefile
#cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
4.编译
#sudo make
5.安装
#sudo make install
以下是部分安装时的输出信息:
-- Set runtime path of "/usr/local/bin/opencv_traincascade" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_createsamples
-- Set runtime path of "/usr/local/bin/opencv_createsamples" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_annotation
-- Set runtime path of "/usr/local/bin/opencv_annotation" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_visualisation
-- Set runtime path of "/usr/local/bin/opencv_visualisation" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_interactive-calibration
-- Set runtime path of "/usr/local/bin/opencv_interactive-calibration" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_version
-- Set runtime path of "/usr/local/bin/opencv_version" to "/usr/local/lib"
6.配置OpenCV编译环境
(1)将OpenCV的库添加到系统路径
#vim /etc/ld.so.conf.d/opencv.conf
添加以下路径
/usr/local/lib
(2)使以上路径生效
sudo ldconfig
(3)配置PKG_CONFIG_PATH
#sudo vim /etc/bash.bashrc
添加以下内容
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
(4)使以上配置生效
#source /etc/bash.bashrc
7.最后进行更新
#sudo updatedb
8.检查OpenCV模块是否配置成功
#pkg-config opencv --modversion
9.测试OpenCV的sample
#cd opencv-3.4.1/samples/cpp/example_cmake
#cmake .
#make
#./opencv_example