安裝
測試環境為centos
安裝依賴
yum install cmake gcc gcc-c++ gtk2-devel gimp-develgimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devellibpng-devel gstreamer-devel libavc1394-devel libraw1394-devel libdc1394-develjasper-devel jasper-utils swig python libtool nasm
下載opencv
http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/download,拷貝到/usr/local/路徑之下 。
命令:“unzip opencv-2.4.9.zip”解壓出opencv的源碼
命令:“cd opencv-2.4.9”進入源碼文件夾
命令:“cmake CMakeLists.txt”,生成build文件
命令:”make”,完成opencv的編譯
命令:“make install”,完成opencv的安裝
安裝完成后 Opencv的頭文件在“/usr/local/include”目錄下
Opencv的庫文件在“/usr/local/lib”目錄下
命令:“cd /etc/ld.so.conf.d/”,進入庫文件環境變量配置文件夾,命令“ls”,可以查看當前文件夾下已有的庫文件配置。
命令:“vim opencv.conf”,按下“i”,輸入opencv的庫文件目錄“/usr/local/lib”,保存退出(:wq)
命令:"ldconfig" 加載庫文件配置
環境變量配置
vim /etc/bashrc
添加:PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存之后執行
source /etc/bashrc
測試安裝是否成功
cd /usr/local/opencv-2.4.9/samples/c
命令:./build_all.sh
編譯結束之后執行:
./facedetect cascade=“/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml”--scale=1.5 lena.jpg
如果安裝成功的話,lena臉上會有一個藍色的圈:
卸載
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
