由于要做点东西,需要用opencv3.0,搞了将近两天,总算搞定了opencv3.0
其实,关网页有一个guide,但按照那个区装,结果肯定是坑爹悲剧。
官网guide
http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html
一. 我的安装环境
1. 操作系统 VMware + centos 6.2
2. GCC4.9.1
官网上写gcc4.4.X or later,这句话太坑爹了
折腾了我一天多,总是编译过不去,爆一个错误"gcc diagnostic not allowed inside functions", 我一直不怀疑官网,
装完最新的gcc4.9.1(我能找到的最新版本)之后,错误消失了
由于centos6.2默认安装的是gcc4.4.7,必须去下载最新的版本,自己编译,安装,这里不赘述,因为,google出来的帖子很靠谱
3. Cmake2.8.10
Cmake版本太低,肯定会报错,具体error 不记得了,但一定要装2.8.7以上的;
4. git
为了下载代码,很容易, yum -y install git 搞定
5. pkg-config
6. python 3.3(官网写的python2.6,再次坑爹)
7.其他
-
yum groupinstall "Development Tools" yum install gcc yum install cmake yum install git yum install gtk2-devel yum install pkgconfig yum install numpy yum install ffmpeg
环境弄好了,安装步骤参看官方guide就可以了,下面内容摘自官网
In Linux it can be achieved with the following command in Terminal:
cd ~/<my_working _directory>
git clone https://github.com/Itseez/opencv.git
Building OpenCV from Source Using CMake, Using the Command Line
-
Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries.
-
Enter the <cmake_binary_dir> and type
cmake [<some optional parameters>] <path to the OpenCV source directory>
For example
cd ~/opencv mkdir release cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
-
Enter the created temporary directory (<cmake_binary_dir>) and proceed with:
make -j8 # -j8 runs 8 jobs in parallel. # Change 8 to number of hardware threads available. sudo make install
//环境设置
$ sudo vi /etc/ld.so.conf.d/opencv.conf
追加内容 /usr/local/lib
$ sudo ldconfig
$ sudo vi /etc/environment
追加以下内容
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
接下来可以编程了。
我的心得体会就是,千万不要迷信官方文档,否则,耽误的时间都是自己的