MacOS 安装 PHP的图片裁剪扩展Tclip
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的安装使用请参考
安装opencv
开始安装 opencv:
tar zxf opencv-2.4.11.tar.gz
cd opencv-2.4.11
cmake cmakelists.txt
make && make install
安装php tclip
先下载:
然后继续:
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
顺利安装完成。
以上所述就是本文的全部内容了,希望大家能够喜欢。
请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!
上一篇: Redis中哈希分布不均匀的解决办法