Image cropping extension Tclip for installing PHP in MacOS

Source: Internet
Author: User
Tclip is an automatic profile picture recognition and php image cropping project. It can automatically recognize important areas in an image and retain important areas when cropping the image. Next let's take a look at how to install on MacOS. Tclip is used for image cropping and has the following features:

Supports face recognition. The image contains a face, which is automatically regarded as an important area of the face and will not be cropped out.
Automatically identifies other important areas. If the image does not recognize the face, the heavy area is calculated based on the feature distribution.
All in all, it automatically identifies important areas in the image and retains important areas when cropping the image.
Source code address: https://github.com/exinnet/tclip

Install opencv

According to the instructions on github, there is no problem with the installation on CentOS, but it will be suspended on my MacOS.

The first problem is that opencv cannot be installed. Fortunately, the latest opencv-2.4.11 is successfully installed on github.

: Https://github.com/Itseez/opencv/releases

Use the latest version of OpenCV 2.4.11

Install dependency

Install some dependent packages before installing opencv:

The code is as follows:


Brew install gtk + pkgconfig libpng zlib libjpeg libtiff cmake

Tip: For brew installation and use, refer to http://brew.sh/

Install opencv

Start to install 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: https://github.com/exinnet/tclip/archive/master.zip

Then proceed:

The code is as follows:


Unzip tclip-master.zip
Cd tclip-master/php_ext
Phpize
./Configure

If there is no accident, this step should be suspended, and the prompt is:

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

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 on Tclip author's page

In the comments, some netizens encountered similar problems and proposed the following methods:

Set config. test $ {I :$ {# I}-3} = ". so ", changed to test $ {I :$ {# I}-6} = ". dylib ", and try to split the 46 rows. so is also renamed. dylib
The error "no result" still appears ~

Go over the config. m4 code and run pkg-config opencv -- libs -- cflags opencv output:

The code is as follows:


-I/usr/local/include/opencv-I/usr/local/include-L/usr/local/lib-runtime-lopencv_contrib-lopencv_core-kernel-lopencv_flann-lopencv_gpu-lopencv_highgui -upgrade-lopencv_legacy-lopencv_ml-lopencv_nonfree-upgrade-lopencv_ocl-lopencv_photo-lopencv_stitching-lopencv_superres-lopencv_ts-lopencv_video-acceleration

I thought it was not correct, so I ran to the Linux-installed server and executed the command. the output is 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/users/usr/local/lib/libopencv_gpu.so/usr/local/lib/libopencv_highgui.so/usr/local/lib /libopencv_imgproc.so/usr/local/lib/logs/usr/local/lib/libopencv_ml.so/usr/local/lib/libopencv_nonfree.so/usr/local/lib/logs/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/release

Let's look at his judgment code:

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 all output on Linux is specific. so path, MacOS are relative paths, and config. m4 is determined based on the specific path and extension. it is easy to solve the problem after understanding the problem.

Modify the execution result of pkg-config opencv -- libs -- cflags opencv to a specific path and replace it with 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/modules/usr/local/lib/libopencv_gpu.dylib/usr/local/lib/modules/usr/ local/lib/libraries/usr/local/lib/libopencv_ml.dylib/usr/local/lib/libopencv_nonfree.dylib/usr/local/lib/libraries/usr/ local/lib/libopencv_photo.dylib/usr/local/lib/modules/usr/local/lib/libopencv_ts.dylib/usr/local/lib/libopencv_video.dylib/usr/local/lib/modules"

Continue:

The code is as follows:


Phpize
./Configure
Make
Make install

The installation is successful.

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

Please take a moment to share your article with your friends or leave a comment. Thank you for your support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.