Tclip致力于人脸识别和图片显著性区域的识别。它与其他图片裁剪程序最大的不同之处在于,在裁剪后的图片中保留人脸和其他图片显著性区域。如:
如果按照从中间截取为 400 * 225 大小大图片。效果如下:
在php中使用裁剪图片效果如下:
安装步骤:
源码下载:
下载opencv源码:http://www.bo56.com/download/opencv2.tar.bz2
下载Tclip源码:
https://github.com/exinnet/tclip
安装opencv2:
此扩展依赖于opencv2.0 之上版本。因此安装前先安装opencv。opencv的安装步骤如下:
安装过程中有任何疑问可以加qq 179815944咨询。
1.安装如下依赖包: gtk+ gtk+-devel pkgconfig libpng zlib libjpeg libtiff cmake
如果是centos可以执行如下命令进行安装依赖包:
yum install gtk+ gtk+-devel pkgconfig libpng zlib libjpeg libtiff cmake
2.安装opencv2,步骤如下:
解压安装包
cd 进入安装包文件夹内。
cmake CMakeLists.txt
make && make install
vim /etc/profile
注意,在编译opencv时,要使用gcc的4.4版本。否则会报错。
3.设相关环境变量
在 unset i 前增加
export PKG_CONFIG_PATH=/usr/lib/pkgconfig/:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
保持退出后,执行如下命令
source /etc/profile
echo "/usr/local/lib/" > /etc/ld.so.conf.d/opencv.conf
ldconfig
安装php图片裁剪tclip扩展
cd 到源代码目录中的php_ext文件夹
phpize
./configure
make
cp modules/tclip.so 到 extension 目录
修改php.ini。加入 extension=tclip.so
重启fpm
安装命令行
如果想使用命令行方式,可以进行如下安装
cd 进入安装包soft文件夹内
chmod +x ./tclip.sh
./tclip.sh
使用方法说明
第一种:在php中图片裁剪使用格式:
tclip(文件原路径,裁剪后的图片保存路径,裁剪后的图片宽度,裁剪后的图片高度)
示例:
$source_file = "/tmp/a.jpg";
$dest_file = "/www/a_dest.jpg";
$width = 400;
$height = 200;
$ret =tclip($source_file, $dest_file, $width, $height);
执行成功$ret 为true,否则为false
第二种:命令行
参数说明:
-s 原图路径
-d 裁剪后的图片保存路径
-w 裁剪后的图片宽度
-h 裁剪后的图片高度
./tclip -s a.jpg -d a_dest.jpg -w 400 -h 200
请教下OS X 10.9.2下执行./configure时报了一个pkg-config的error,已经配置好了opencv的环境变量,单独执行pkg-config --libs --cflags opencv都正常,能帮忙看看问题出在哪里吗?~/Desktop/tclip-master/php_ext » ./configurechecking for grep that handles long lines and -e... /usr/bin/grepchecking for egrep... /usr/bin/grep -Echecking for a sed that does not truncate output... /usr/bin/sedchecking for cc... ccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables...checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether cc accepts -g... yeschecking for cc option to accept ISO C89... none neededchecking how to run the C preprocessor... cc -Echecking for icc... nochecking for suncc... nochecking whether cc understands -c and -o together... yeschecking for system library directory... libchecking if compiler supports -R... nochecking if compiler supports -Wl,-rpath,... yeschecking build system type... i386-apple-darwin13.2.0checking host system type... i386-apple-darwin13.2.0checking target system type... i386-apple-darwin13.2.0checking for PHP prefix... /usrchecking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/libchecking for PHP extension directory... /usr/lib/php/extensions/no-debug-non-zts-20100525checking for PHP installed headers prefix... /usr/include/phpchecking if debug is enabled... nochecking if zts is enabled... nochecking for re2c... noconfigure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.checking for gawk... nochecking for nawk... nochecking for awk... awkchecking if awk is broken... nochecking for tclip support... yes, sharedchecking for opencv.pc file in default path... found in /usr/lib/pkgconfigfound in /usr/local/lib/pkgconfigconfigure: error: no result from pkg-config opencv --libs --cflags opencv
由于mac系统opencv的lib文件格式为”.dylib”,而在config.m4中判断语句test ${i:${#i}-3} = “.so”,所以无法检测。请手动把语句改为 test ${i:${#i}-3} = “.dylib”最近会修复这个问题
修改后,依然会提示错误,我尝试将46行的.so 也改称 .dylib 后,依然提示no result的错误~
test ${i:${#i}-3} 中的3应该也要替换成6吧?
你好,你这个问题解决了么?我也遇到了这个错误:
configure: error: no result from pkg-config opencv --libs --cflags opencv
执行pkg-config opencv --libs --cflags opencv有返回结果:
-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_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so -lrt -lpthread -lm -ldl
config.log内容如下:
configure:3494: result: no
configure:3499: checking if compiler supports -Wl,-rpath,
configure:3528: cc -o conftest -g -O2 conftest.c -Wl,-rpath,/usr/lib >&5
configure:3535: $? = 0
configure:3557: result: yes
configure:3606: checking build system type
configure:3624: result: x86_64-unknown-linux-gnu
configure:3646: checking host system type
configure:3661: result: x86_64-unknown-linux-gnu
configure:3683: checking target system type
configure:3698: result: x86_64-unknown-linux-gnu
configure:3807: checking for PHP prefix
configure:3809: result: /usr/local/server/php
configure:3811: checking for PHP includes
configure:3813: result: -I/usr/local/server/php/include/php -I/usr/local/server/php/include/php/main -I/usr/local/server/php/include/php/TSRM -I/usr/local/server/php/include/php/Zend -I/usr/local/server/php/include/php/ext -I/usr/local/server/php/include/p
hp/ext/date/lib
configure:3815: checking for PHP extension directory
configure:3817: result: /usr/local/server/php/lib/php/extensions/no-debug-non-zts-20100525
configure:3819: checking for PHP installed headers prefix
configure:3821: result: /usr/local/server/php/include/php
configure:3824: checking if debug is enabled
configure:3854: result: no
configure:3857: checking if zts is enabled
configure:3887: result: no
configure:3958: checking for re2c
configure:3974: found /usr/bin/re2c
configure:3985: result: re2c
configure:3994: checking for re2c version
configure:4008: result: 0.13.5 (ok)
configure:4027: checking for gawk
configure:4044: found /bin/gawk
configure:4055: result: gawk
configure:4105: checking for tclip support
configure:4145: result: yes, shared
configure:4159: checking for opencv.pc file in default path
configure:4164: result: found in /usr/local/lib/pkgconfig
configure:4518: error: no result from pkg-config opencv --libs --cflags opencv
你好,图片源识别失败了。http://demo.bo56.com/tclip/images/49b403c44253e22ec52e568da93909ce.jpg, http://demo.bo56.com/tclip/images/49b403c44253e22ec52e568da93909ce_dest.jpg
收到,后续会对算法进行进一步的完善。
我在pkg-config opencv --libs --cflags opencv的时候会出现一个/usr/local/lib/libopencv_ts.a,导致在进行判断后缀是不是.dylib时报错了.尝试跳过这个.a的话编译成功,但是 php -m时会出现一个23970 segmentation fault请问可能是什么原因呢?
./tclip: error while loading shared libraries: libopencv_calib3d.so.2.4
执行如下命令。ldd ./tclip 看是不是提示找不到动态库libopencv_calib3d.so.2.4注意在make的时候,不要加sudo
为什么生成宽度只有1像素的图片.
tclip裁剪图片的宽度是你指定的。如果有问题,可以加我qq 1798159444。注明 tclip
此问已经解决。到github上下载最新版本即可。
无意溜达到了你的网站 留下足迹
太厉害啦!值得我们学习
路过,留个脚印,网站很棒!
在win系统下要怎么安装。。。。win+nginx。。。。
不错,支持一下!!!
OPENCV_FLAGS="-I/usr/local/Cellar/opencv/2.4.13.2/include/opencv -I/usr/local/Cellar/opencv/2.4.13.2/include -L/usr/local/Cellar/opencv/2.4.13.2/lib /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_ocl.dylib /usr/local/lib/libopencv_photo.dylib /usr/local/lib/libopencv_stitching.dylib /usr/local/lib/libopencv_superres.dylib /usr/local/lib/libopencv_video.dylib /usr/local/lib/libopencv_videostab.dylib" for i in $OPENCV_FLAGS;do if test ${i:0:2} = "-I" ;then PHP_ADD_INCLUDE(${i:2}) elif test ${i:${#i}-6} = ".dylib" ;then dir_name=`dirname $i` file_name=${i/$dir_name/} file_name=${file_name//lib/} file_name=${file_name/.dylib/} 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])在Mac下 我这也还编译不成功,请问下是什么原因
这样的链接http://demo.bo56.com/tclip 都打不开呀
哥们,这项目还在继续么。。。。