centos7 安装php-opencv扩展

使用的PHP版本是7.3  ;opencv 版本是 4+

1、安装php-opencv  首先需要先安装opencv

         需要epel来安装部分的插件

yum -y install epel-release

         需要安装一系列的依赖 支持opencv  --会需要很长的时间

sudo yum -y ffmpeg ffmpeg-devel --downloadonly --downloaddir=.
sudo yum -y install git gcc gcc-c++ cmake3 cmake-gui
sudo yum -y install qt5-qtbase-devel
sudo yum install -y python34 python34-devel python34-pip
sudo yum install -y python python-devel python-pip
sudo yum -y install python-devel numpy python34-numpy
sudo yum -y install gtk2-devel
sudo yum -y install vlc 
sudo yum install -y libpng-devel
sudo yum install -y jasper-devel
sudo yum install -y openexr-devel
sudo yum install -y libwebp-devel
sudo yum -y install libjpeg-turbo-devel
sudo yum install -y freeglut-devel mesa-libGL mesa-libGL-devel
sudo yum -y install libtiff-devel
sudo yum -y install libdc1394-devel
sudo yum -y install tbb-devel eigen3-devel
sudo yum -y install boost boost-thread boost-devel
sudo yum -y install libv4l-devel
sudo yum -y install gstreamer-plugins-base-devel
sudo yum -y install autoconf automake mercurial pkgconfig zlib-devel libtool freetype-devel make
sudo yum install -y hdf5-devel
sudo yum install -y liblas-devel atlas-devel 
sudo yum install -y gcc-gfortran
sudo yum install -y libevent-devel lua-devel openssl-devel flex mysql-devel
sudo yum install -y xz gettext-devel
sudo yum install -y tcl
sudo yum install -y openblas-devel
sudo yum install -y tesseract-devel tesseract-osd
sudo yum install -y java-1.7.0-openjdk-devel
sudo yum install -y pylint
sudo yum install -y python-flake8
sudo yum install -y vtk-devel vtk-python vtk-qt vtk
sudo yum install -y ccache
sudo yum install -y gflags gflags-devel
sudo yum install -y glog glog-devel
sudo yum install -y libpng libpng-devel
sudo yum install -y libXaw-devel freeimage freeimage-devel zziplib-devel cppunit-devel libXt-devel libX11-devel
sudo yum install -y re2c libgnomeui-devel
sudo yum install -y gcc gcc-c++ gtk2-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devel libpng-devel gstreamer-devel libavc1394-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils swig python libtool nasm
sudo yum install -y gcc g++ cmake git  python-devel numpy  gtk2 libdc1394 libv4l gstreamer* nasm libtool swig jasper libdc1394-devel jasper-devel jasper-utils libraw1394-devel libgphoto2 tesseract libavc1394-devel gstreamer-devel libpng-devel libjpeg-devel libtiff-devel zlib-devel gimp gimp-devel gtk+-devel yasm libpciaccess libva-freeworld libva-intel-driver phonon-backend-gstreamer

2、拉取opencv 的源码

git clone https://github.com/opencv/opencv_contrib.git

git clone https://github.com/opencv/opencv.git

最好的放在同一目录下  后边会使用到

3、opencv 的编译

cd opencv
mkdir build
cmake3 -D CMAKE_BUILD_TYPE=RELEASE ..
cmake3 -D CMAKE_INSTALL_PREFIX=/usr/local ..
cmake3 -D INSTALL_C_EXAMPLES=ON ..
cmake3 -D INSTALL_PYTHON_EXAMPLES=ON ..
cmake3 -D WITH_TBB=ON -D WITH_EIGEN=ON ..
cmake3 -D WITH_V4L=ON ..
cmake3 -D OPENCV_SKIP_PYTHON_LOADER=ON ..
cmake3 -D OPENCV_GENERATE_PKGCONFIG=ON ..
cmake3 -D WITH_QT=ON ..
cmake3 -D WITH_OPENGL=ON ..
cmake3 -D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 ..
cmake3 -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..

注意: 最后一条的路径 之前放在同一目录下可以不用更改

cmake3 -D ENABLE_CXX11=ON ..

make && make install

检测是否编译成功 可以查看 /usr/local/lib64/pkgconfig  这个目录下是否有 opencv4.cp 这个文件

4、修改环境变量  永久生效

vi /etc/profile
export  PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig #  在最后一行加上
source /etc/profile

5、查看是否成功

pkg-config --libs opencv

6、安装PHP-opencv

 1) 下载php-opencv 源码

git clone https://github.com/hihozhou/php-opencv.git

2)

cd php-opencv

phpize

./configure --with-php-config=/usr/local/php/bin/php-config --enable-debug

make CXXFLAGS='-std=c++11'  

make install

3)  在php.ini 中加入

extension=opencv.so

4)保存退出 重启php 即可

5)可以php-m 查看是否成功

出现的问题: 1、一定要注意你安装的版本 

                        2、编译会很慢 ,opencv 编译会失败,可以先删除那个模块试试

你可能感兴趣的:(opencv,php)