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
順利安裝完成。
以上所述就是本文的全部內容了,希望大家能夠喜歡。
請您花一點時間將文章分享給您的朋友或者留下評論。我們將會由衷感謝您的支持!