1. 先下载OpenCV的源码 https://github.com/Itseez/opencv/tree/2.4
2. 解压到任意目录
unzip opencv-2.4.zip
3.进入源码目录
cd opencv-2.4
4. 事先安装一些软件
sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config Python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev
5. 进入cmake
cd cmake
6. cmake编译生成Makefile,
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
安装所有的lib文件都会被安装到/usr/local目录
7. 编译,并安装
make
sudo make install
-------------------------------------------------------------------------------------
补充部分:
Now you have to configure OpenCV. First, open the opencv.conf file with the following code:
sudo gedit /etc/ld.so.conf.d/opencv.conf
Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:
/usr/local/lib
Run the following code to configure the library:
sudo ldconfig
Now you have to open another file:
sudo gedit /etc/bash.bashrc
Add these two lines at the end of the file and save it:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.
--------------------------------------------------------------------------------------
8. 测试,在某个目录下建立一个test.cpp文件
9. 同目录,新建一个文件CMakeLists.txt,写入如下内容
10. 编译成可执行文件
cmake .
make
11. 随便弄个jpg图片做个测试,注意要和上面那个可执行文件放在同一目录下面,我这里名字取的是test.jpg。
12. ./test test.jpg
如果能看到照片,那就表示成功了。