Get the smallest rectangle from image

I have a image , I have changed the image to grayscale “Imgproc.cvtColor(src, dst, Imgproc.COLOR_RGB2GRAY)”, I have applied canny detector. I need to get the smallest rectangle from the image , Image example can be a copy of Aadhar card on A4 sheet.
I have successfully done the edge detections using the link , OpenCV - Canny Edge Detection - Tutorialspoint

have a look at the contours tutorial
(it has java code, too, look at the update() method there !)

1 Like

Thanks , I went through and tried implementing , I need to draw contours to the smallest rectangle , I see contours in my entire image. Can you please explain me on how do I get the rectangle or any document which gives me on how to get the smallest rectangle from the image with explanation.Please see the ref link , Dealing with contours and bounding rectangle in OpenCV 2.4 - python 2.7 - Stack Overflow, here cod e is in Python

loop over the contours and check contourArea()

there are several ways to determine, if a contour is a rectangle, probably the most simple one is getting the minAreaRect() and compare the size with the contour’s area again

1 Like