Android auto crop camera captured images

Dory picture Dory · May 31, 2013 · Viewed 8.3k times · Source

I am looking for some kind of auto trim/crop functionality in android. Which detects a object in captured image and creates a square box around object for cropping. I have found face detection apis in android, but my problem is captured images are documents/pages not human faces so how can I detected documents or any other object from captured picture.

I am thinking of any algorithms for object detection or some color detection. Is there any apis or libraries available for it.

I have tried following link but not found any desired output.

Find and Crop relevant image area automatically (Java / Android)

https://github.com/biokys/cropimage

Any small hint would also help me alot. Please help. Thanks in advance

Answer

littleimp picture littleimp · Oct 22, 2013

Use OpenCV for android.

You can use the Watershed (Imgproc.watershed) function to segment the image into foreground and background. Then you can crop around the foreground (which will be the document).

The watershed algorithm needs some markers pre-defining the regions. You can for example assume the document to be in the middle of the image, so create a marked region in the middle of the image to get the watershed algorithm started.