ubuntu14.04安装opencv3.1
1.下载opencv3.1源码http://opencv.org/releases.html
2.安装opencv3
2.1安装opencv3的依赖
sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev
2.2解压下载的源码并创建编译目录
1 unzip opencv-3.1.0.zip 2 cd opencv-3.1.0/ 3 mkdir build 4 cd build
2.3.cmake生成make文件并安装
1 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.1.0 -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. 2 make 3 sudo make install
3.opencv3.1使用
如果之前安装了opencv2的版本,需要在~/.bashrc中添加
1 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv3.1.0/lib/pkgconfig 2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/opencv3.1.0/lib
通过输入,以下命令可以查看opencv版本
1 pkg-config --modversion opencv
版本为3.1.0
此外需要在使用opencv的工程中对CMakeLists.txt 添加如下配置
1 set( CMAKE_CXX_FLAGS "-std=c++11" ) 2 set(OpenCV_DIR "/usr/local/opencv3.1.0/share/OpenCV") 3 find_package( OpenCV 3.1 REQUIRED ) 4 include_directories( ${OpenCV_INCLUDE_DIRS} "/usr/local/opencv3.1.0/include") 5 target_link_libraries( imageBasics ${OpenCV_LIBS} )