1.安装依赖
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev
2.下载OpenCV2.4.9(https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/)
3.解压并创建编译目录
unzip opencv-2.4.9.zip
cd opencv-2.4.9/
mkdir release
3.cmake生成make文件
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=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 ..
4.编译
make
5.安装
sudo make install
6.配置
sudo sh -c ‘echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf‘
执行配置:sudo ldconfig
7.测试
通过例子测试
cd /usr/local/share/OpenCV/samples/c
sudo chmod +x build_all.sh
sudo ./build_all.sh
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
或者编写简单文件测试
(1)在某个目录下建立一个test.cpp文件
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main(int argc, char* argv[])
{
Mat image;
image = imread(argv[1], 1);
if (argc != 2 || !image.data)
{
printf("No image data\n");
return -1;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
imshow("Display Image", image);
waitKey(0);
return 0;
}
(2)写一个cmake的makefile,也叫CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(test)
find_package(OpenCV REQUIRED)
add_executable(test test)
target_link_libraries(test ${OpenCV_LIBS})
(3)接着,编译+运行
cmake .
make
得到可执行文件test
最后. 随便弄个jpg图片做个测试,注意要和上面那个可执行文件放在同一目录下面,我这里名字取的是test.jpg。
(4) ./test test.jpg 如果能看到照片,那就表示成功了。