After testing cropping images using entropy, we now try to go deeper in Image crop automation.
Those are nice feet
One of our worst case scenarios emerged from pictures like that this one :
If we only use the “entropy” crop, the render is as following :
The bottom of this picture seems to be the most informative part, which would explain why it is selected by the entropy crop. Even though this woman has nice feet, we’re not absolutely satisfied with the crop, as it remove what we believe to be the most important part of the picture: the woman’s face.
We have to do better
The best crop technique here will be to locate the face and to tell our “croper” to preserve it.
OpenCV seems to be one of the best library to detect faces and, well, it’s both free (as in freedom, and free beer) and open source 😉
We switched back to a PHP project to be able to perform the cropping work live. We thus found the PHP version of cropy on github : https://github.com/stojg/crop/ and added the face detection functionality into the project using OpenCV. It is now available to anyone, and we hope you’ll find it useful!
Now let’s detect the face:
Doesn’t it work it nicely? OK, I have to admit I selected the picture with care: the classifier we use is good but does not give perfect result on all pictures. Some false detection happen while some faces are not detected at all.
The image will be cropped to the specified dimensions, and the detected faces will be preserved, if possible.
Here is the result:
It is now a much better (and respectful) crop !
Picture by anoldent