一、安装一堆包
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev cmake libswscale-dev libjasper-dev
然后下载openCV的源码包并解压出来
进入解压出来的目录比如 opencv
cd opencv
mkdir build
cd build
五、Test
创建个文件夹在里面,创建源程序,test.cpp、放入lena.jpg
test.cpp
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc,char **argv) { Mat image; image = imread(argv[1],1); if(argc != 2 || !image.data) { cout << "No image data\n"; return -1; } namedWindow("Display Image",CV_WINDOW_AUTOSIZE); imshow("Display Image",image); waitKey(0); return 0; }
编译
g++ test.cpp -o test`pkg-config opencv --cflags --libs`
运行
./test lena.jpg
最终效果
参考链接:
http://opencv.willowgarage.com/wiki/InstallGuide_Linux
http://www.linuxidc.com/Linux/2012-09/70158.htm