stojg / crop

PHP Image crops
BSD 2-Clause "Simplified" License
259 stars 40 forks source link

Face detection cropping is very slow because it uses the original image #17

Open asgh opened 9 years ago

asgh commented 9 years ago

Face detection cropping should run the detection on the resized image, not the original image.

It's far too slow otherwise.

This can be done in the getFaceListFromClassifier function - write the resized image to a temporary file, then check that for faces (and then use safeZone instead of safeZoneList in getSafeZoneList).

If you are worried about accuracy then make it an option.

asgh commented 9 years ago

Also, the new interface allows passing an imageMagic instance for $imagePath and that won't work for face detection.

jdeniau commented 9 years ago

I do not agree with you, because the results may really vary depending on the rendering size you asked. The heads may not be detected on the small image.

The solution could be for you to resize the image in a "non destructive" size (personally I use images with 2000px for max height/width) and then crop the image.

Furthermore, you may not have write access for a temporary file.

The option could be a good solution though. Feel free to make a PR.

For the Imagick in the Crop constructor, you are right. But I do not see a quick way to fix this (the only solution will be to write the Imagick on disk, wich implies the same problems as bellow ;) ) The constructor of the CropFace still needs a string, and works with path, because the face detect extension will only work on real files.

asgh commented 9 years ago

That's why I figured fix two things at once. It's not just Imagick you can also have a URL. So I think always writing a temp file is the right thing to do. There's nothing we can do if someone doesn't have write access - but I think that will be rare.

The only question left is what resolution to use (original, resized, or user specified max).

I'll see if I can make a PR next week, not sure.

jdeniau commented 9 years ago

The pre-resize size should be the option parameter then. This way you let the user decide what is best for him. Le 26 nov. 2014 09:50, "asgh" notifications@github.com a écrit :

That's why I figured fix two things at once. It's not just Imagick you can also have a URL. So I think always writing a temp file is the right thing to do. There's nothing we can do if someone doesn't have write access

  • but I think that will be rare.

The only question left is what resolution to use (original, resized, or user specified max).

I'll see if I can make a PR next week, not sure.

— Reply to this email directly or view it on GitHub https://github.com/stojg/crop/issues/17#issuecomment-64531622.