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
https://ibb.co/fMWPjF
https://ibb.co/doyRya
https://ibb.co/fTT4jF
https://ibb.co/k1vH4F
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?
https://ibb.co/kVKrya
https://ibb.co/hmndda
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