Crop image after selecting area using edge detection in android

chAmi picture chAmi · Jun 26, 2012 · Viewed 8k times · Source

I want to automatically select area of the page to crop later. I thought edge detection might be useful and used canny edge detection to find edges of the image. Now I have this image! but I've no clear idea to select area of the page as a rectangle. Can anyone suggest a method or implementation for this problem? What I really want to do is this selecting the area of the page as follows. Is there any other method to do this? I have also seen boundary detection in the book of introduction to digital image processing using matlab. But I'm not familiar with that. Can I use that for this purpose?

Answer

don_pablito picture don_pablito · Oct 12, 2015

I assume that you have "Canny-ed" image. Now you can use Imgproc.findCountours, to find and store edges (you need List<MatOfPoint>for that). Before using findContours i would play with Imgproc.dilate, which might help finding contours(it "fattens" lines so we are sure that findContours wont miss your target). Then you need only to use Imgproc.boudningRect to get your ROI. Then just crop image using this ROI.