MacOS 安装 PHP的图片裁剪扩展Tclip,
Tclip 用于图片裁剪,有以下特点:
能进行人脸识别。图片中有人脸,将自动视为人脸区域为重要区域,将不会被裁剪掉。
自动识别其它重要区域。如果图片中未识别出人脸,则会根据特征分布计算出重区域。
总而言之,自动识别图片中的重要区域,并且在图片裁剪时保留重要区域。
源码地址: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/}
file_name=${file_name/\/lib/}
file_name=${file_name/.so/}
PHP_ADD_LIBRARY_WITH_PATH($file_name,$dir_name,TCLIP_SHARED_LIBADD)
else
AC_MSG_ERROR([no result from pkg-config opencv --libs --cflags opencv])
fi
done
我立刻就明白了,Linux上输出的都是具体的.so路径,MacOS上都是相对的路径,而config.m4中是根据具体路径和扩展名判断的,明白了问题,解决就简单了。
将 pkg-config opencv --libs --cflags opencv 的执行结果修改为具体的路径,并替换到config.m4中:
复制代码 代码如下:
OPENCV_FLAGS="-I/usr/local/include/opencv -I/usr/local/include /usr/local/lib/libopencv_calib3d.dylib /usr/local/lib/libopencv_contrib.dylib /usr/local/lib/libopencv_core.dylib /usr/local/lib/libopencv_features2d.dylib /usr/local/lib/libopencv_flann.dylib /usr/local/lib/libopencv_gpu.dylib /usr/local/lib/libopencv_highgui.dylib /usr/local/lib/libopencv_imgproc.dylib /usr/local/lib/libopencv_legacy.dylib /usr/local/lib/libopencv_ml.dylib /usr/local/lib/libopencv_nonfree.dylib /usr/local/lib/libopencv_objdetect.dylib /usr/local/lib/libopencv_photo.dylib /usr/local/lib/libopencv_stitching.dylib /usr/local/lib/libopencv_ts.dylib /usr/local/lib/libopencv_video.dylib /usr/local/lib/libopencv_videostab.dylib"
再继续执行:
复制代码 代码如下:
phpize
./configure
make
make install
顺利安装完成。
以上所述就是本文的全部内容了,希望大家能够喜欢。
请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!
http://www.bkjia.com/PHPjc/973283.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/973283.htmlTechArticleMacOS 安装 PHP的图片裁剪扩展Tclip, Tclip 用于图片裁剪,有以下特点: 能进行人脸识别。图片中有人脸,将自动视为人脸区域为重要区域,...