9

I want to detect the 4 corners of the document in android. Iam using opencv library.

Iam using the following approach- (1) grayscale the image (2) Apply median blur (3) Apply adaptive threshold (4) Canny Edge detection (5) find contours (6) find the largest contour (7) get the edges and corners of the largest contour

My code is

srcImg = Utils.loadResource(this, R.drawable.test1, Highgui.CV_LOAD_IMAGE_COLOR);
Imgproc.cvtColor(srcImg, srcImg, Imgproc.COLOR_BGR2GRAY);
Imgproc.medianBlur(srcImg, srcImg, 9);
Imgproc.adaptiveThreshold(srcImg, srcImg, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 11, 2);
Imgproc.Canny(srcImg, srcImg, 50, 80);


Imgproc.findContours(srcImg,contours , hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);

After canny edge detection, the outlining boundary at many points are broken due to which the largest contour detected in the image is not the actual boundary of the document. In some images the largest contour is showing some part of the boundary but in some images it is pointing to the center of the document or completely outside the document

(A)How do I proceed further in this condition ?

Another approach i applied was to apply houghes line transform and calculate the point of intersection of the lines which are intersecting at 90 degree angle but in that case am not getting exactpoints. when I put 88

(B)How to handle that much number of points

(C)or do I need to follow completely different approach ?

2
  • 1
    Can you share any sample images for the experiment? Commented Aug 2, 2022 at 6:08
  • Instead of doing canny why not apply find contours on the adaptive thresholded image? Commented Jan 30, 2024 at 7:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.