Linux下安装opencv的PHP扩展教程

2023-05-08 00:34:53
黄豆 UsualTool.com
编程思维/PHP 1662
loading
下载opencv及PHP扩展
wget https://github.com/opencv/opencv/archive/xxx.zip
wget https://github.com/opencv/opencv_contrib/archive/xxx.zip
wget https://github.com/hihozhou/php-opencv/xxx.zip


#编译OpenCV
#将opencv3rdpartyippicv||ffmpeg和opencv_contribmodulesxfeatures2dcmake中的https://raw.githubusercontent.com改为https://raw.staticdn.net
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
make && make install

#指定openvc的头文件位置
#1.修改临时环境变量
export  PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
#2.修改环境变量文件,永久生效
vi /etc/profile
export  PKG_CONFIG_PATH=/usr/local/lib/pkgconfig    #添加在文件末尾并保存退出
source /etc/profile    #退出后执行

#添加动态库信息
/bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'

#检查opencv是否安装成功
pkg-config --libs opencv


#编译PHP-OpenCV
git clone https://github.com/hihozhou/php-opencv.git
cd php-opencv
phpize
./configure --with-php-config=/www/server/php/74/bin/php-config --enable-debug
make && make install

#php.ini会增加opencv.so扩展
+分享给朋友+
郑重提醒:部分素材来源于互联网,如果侵犯了您的权利,请及时联络我们更正,谢谢合作,电邮:usualtool@qq.com