MacOS 安装 PHP的图片裁剪扩展Tclip_PHP
能进行人脸识别。图片中有人脸,将自动视为人脸区域为重要区域,将不会被裁剪掉。
自动识别其它重要区域。如果图片中未识别出人脸,则会根据特征分布计算出重区域。
总而言之,自动识别图片中的重要区域,并且在图片裁剪时保留重要区域。
源码地址:https://github.com/exinnet/tclip
安装opencv
根据github上的说明,在CentOS上安装没有问题,但在我的MacOS上就挂了。
首先遇到的问题就是,opencv安装不过去。还好,上github下载最新的opencv-2.4.11 安装成功。
下载地址:https://github.com/Itseez/opencv/releases
使用当前最新版本 OpenCV 2.4.11
安装依赖
在安装opencv之前,先安装一些依赖包:
代码如下:
brew install gtk+ pkgconfig libpng zlib libjpeg libtiff cmake
提示: brew的安装使用请参考 http://brew.sh/
安装opencv
开始安装 opencv:
代码如下:
tar zxf opencv-2.4.11.tar.gz
cd opencv-2.4.11
cmake CMakeLists.txt
make && make install
安装php tclip
先下载:https://github.com/exinnet/tclip/archive/master.zip
然后继续:
代码如下:
unzip tclip-master.zip
cd tclip-master/php_ext
phpize
./configure
如果不出意外,到这一步,应该就挂掉了,提示:
代码如下:
checking for opencv.pc file in default path... found in /usr/lib/pkgconfig
found in /usr/local/lib/pkgconfig
configure: error: no result from pkg-config opencv --libs --cflags opencv
在 Tclip 作者的页面上 http://www.bo56.com/tclip%E4%BA%BA%E8%84%B8%E8%AF%86%E5%88%AB%E5%9B%BE%E7%89%87%E8%A3%81%E5%89%AA/#download
评论中,也有网友遇到了类似的问题,提出修改办法为:
将 config.m4 中的 判断语句test ${i:${#i}-3} = “.so”,改为 test ${i:${#i}-6} = ".dylib”,并尝试将46行的.so 也改称 .dylib
依然提示no result的错误~
再翻翻config.m4的代码和执行 pkg-config opencv --libs --cflags opencv的输出结果:
代码如下:
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
感觉怎么对不上,于是跑到Linux安装成功的服务器执行了一下,输出结果如下:
代码如下:
-I/usr/local/include/opencv -I/usr/local/include /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
再看他的判断代码:
代码如下:
OPENCV_FLAGS="`pkg-config opencv --libs --cflags opencv`"
for i in $OPENCV_FLAGS;do
if test ${i:0:2} = "-I" ;then
PHP_ADD_INCLUDE(${i:2})
elif test ${i:${#i}-3} = ".so" ;then
dir_name=`dirname $i`
file_name=${i/$dir_name