Detect page corners in a photo
I have tried 2 methodologies as follows:-
- conversion of image to Mat
- apply gaussian blur
- then canny edge detection
- find contours
the problem with this method is: 1. too many contours are detected 2. mostly open contours 3. doesn't detect what I want to detect
Then I changed my approach and tried adaptive thresholding after gaussian blur it is much better and I am able to detect the corners in 50% cases
The current problem I am facing is that the page detection requires contrasting and plain background without any reflections. I think it's too idealistic for real world use.
This is where I would like some help. Even a direction towards the solution is highly appreciated especially in java. Thanks in anticipation
Update: median blur did not help much so I traced the cause and found that the page boundary was detected in bits and pieces and not a single contour so it detected the biggest contour as a part of the page boundary Therefore performed some morphological operations to close relatively small gaps and the resultant largest contour is definitely improved but its its not optimum. Any ideas how I can improve the big gaps?
Update 2:
https://ibb.co/gB8Zm5 <--new Image
https://ibb.co/imvfR5 <-- canny result after matching the results of median and adaptive from your answer
Update 3:https://ibb.co/is6WzQ <-- Image before canny edge
this is not an easy task because of the high variability of the background. Instead of the gaussian blur you can try a median filter with a big kernel (is much mir stronger than gaussian) of your can try an edge detection method based on image pyramid which enhances strong long edges but ignores short and weak ones an example image would be helpful
Can you shed some light on how can I do "edge detection method based on image pyramid which enhances strong long edges but ignores short and weak ones?" I've added sample images. 1 with correct corner detection because of the obvious contrasting background and the other with a bit of similar background where largest contour in the image was wrongly detected.
@gurankas can you insert images in your post and not only a link?
@LBerger I tried a lot but they just won't upload. So I had to upload elsewhere and post their links