Home >Backend Development >PHP Tutorial >MacOS Install PHP image cropping extension Tclip_PHP tutorial

MacOS Install PHP image cropping extension Tclip_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:00:13795browse

MacOS Install PHP image cropping extension Tclip

Tclip is an automatic avatar recognition, PHP image cropping project. It can automatically identify important areas in the picture and retain the important areas when cropping the picture. Let’s take a look at how to install it on MacOS.

Tclip is used for image cropping and has the following features:

Can perform face recognition. If there is a face in the picture, the face area will automatically be regarded as an important area and will not be cropped.
Automatically identify other important areas. If no face is recognized in the image, the heavy area is calculated based on the feature distribution.
In summary, important areas in an image are automatically identified and retained when cropping the image.
Source code address: https://github.com/exinnet/tclip

Install opencv

According to the instructions on github, there is no problem installing on CentOS, but it hangs on my MacOS.

The first problem encountered is that opencv cannot be installed. Fortunately, I downloaded the latest opencv-2.4.11 from github and installed it successfully.

Download address: https://github.com/Itseez/opencv/releases

Use the latest version of OpenCV 2.4.11

Install dependencies

Before installing opencv, install some dependency packages:

The code is as follows:


brew install gtk pkgconfig libpng zlib libjpeg libtiff cmake

Tips: For the installation and use of brew, please refer to http://brew.sh/

Install opencv

Start installing opencv:

The code is as follows:


tar zxf opencv-2.4.11.tar.gz
cd opencv-2.4.11
cmake CMakeLists.txt
make && make install

Install php tclip

Download first: https://github.com/exinnet/tclip/archive/master.zip

Then continue:

The code is as follows:


unzip tclip-master.zip
cd tclip-master/php_ext
phpize
./configure

If nothing else happens, you should be dead at this point. Tip:

The code is as follows:


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

On the Tclip author’s page http://www.bo56.com/tclip face recognition image cropping/#download

In the comments, some netizens also encountered similar problems and suggested the following modifications:

Change the judgment statement test ${i:${#i}-3} = “.so” in config.m4 to test ${i:${#i}-6} = “.dylib” , and try to rename the 46-line .so to .dylib
Still prompting no result error~

Look through the code of config.m4 and execute pkg-config opencv --libs --cflags. The output of opencv:

The code is as follows:


-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

I felt something was wrong, so I ran to the server where Linux was successfully installed and executed it. The output was as follows:

The code is as follows:


-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

Look at his judgment code again:

The code is as follows:


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

I immediately understood that the output on Linux are all specific .so paths, and on MacOS they are all relative paths, while config.m4 is judged based on the specific path and extension. Once I understand the problem, I can solve it. Simple.

Modify the execution result of pkg-config opencv --libs --cflags opencv to the specific path and replace it in config.m4:

The code is as follows:


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"

Continue execution:

The code is as follows:


phpize
./configure
make
make install

The installation was successfully completed.

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/973926.htmlTechArticleMacOS Install the PHP image cropping extension Tclip Tclip is an avatar automatic recognition, PHP image cropping project. It can automatically identify important areas in the picture and retain the important areas when cropping the picture...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn