#使用epel
wget -O /etc/yum.repos.d/epel.repo mirrors.aliyun.com/repo/epel-5.repo

yum install python-devel gcc gcc-c++ gtk2-devel libdc1394-devel libv4l-devel ffmpeg-devel gstreamer-plugins-base-devel libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel gcc44 gcc44-c++ gtk+-devel.x86_64  gimp-devel.x86_64 gimp-devel-tools.x86_64  gimp-help-browser.x86_64 zlib-devel.x86_64 libtiff-devel.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 gstreamer-devel.x86_64 libavc1394-devel.x86_64 libraw1394-devel.x86_64 libdc1394-devel.x86_64 jasper-devel.x86_64 jasper-utils.x86_84 swig libtool nasm.x86_84 libwebp-devel

wget github.com/Itseez/opencv/archive/2.4.9.zip

#需要使用新版本的cmake
wget cmake.org/files/v3.5/cmake-3.5.2.tar.gz

unzip 2.4.9.zip
cd opencv-2.4.9
mkdir build
cd build
env CC=/usr/bin/gcc44 CXX=/usr/bin/g++44 /usr/local/cmake/bin/cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_JAVA_SUPPORT=OFF ..
make
make install

#在make 时出现如下错误:
#collect2: ld returned 1 exit status
#make[2]: *** [lib/cv2.so] Error 1
#make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2
#make: *** [all] Error 2

#解决办法,重装编译python
./configure --enable-shared

#还有这个错误:
#[ 74%] Built target opencv_test_gpu
#[ 74%] Generating opencl_kernels.cpp, opencl_kernels.hpp
#CMake Error at /tmp/opencv/opencv-2.4.9/cmake/cl2cpp.cmake:50 (string):
#  string does not recognize sub-command MD5


#make[2]: *** [modules/ocl/opencl_kernels.cpp] Error 1
#make[1]: *** [modules/ocl/CMakeFiles/opencv_ocl.dir/all] Error 2
#make: *** [all] Error 2

#解决办法(把opencv-2.4.9/cmake/cl2cpp.cmake的50行注释):
sed -i '50s/^/#/' ../cmake/cl2cpp.cmake


#安装python完成后,启动提示错误:
#error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

#解决办法
echo "/usr/local/lib">>/etc/ld.so.conf && ldconfig

#再编译完成后测试:
pthon
>>> import cv2
>>> cv2.__version__
'2.4.9'

#如果在 import cv2 时提示错误:
#>>> import cv2
#libdc1394 error: Failed to initialize libdc1394

#解决办法:
ln /dev/null /dev/raw1394