SBM
SBM

Reputation: 87

How to do a perspective transformation of an image which is missing corners using opencv java

I am trying to build a document scanner using openCV. I am trying to auto crop an uploaded image. I have few use cases where there is a gap in the border when the document is out of frame(captured image).

Ex image

Original Image

Below is the canny edge detection of the given image.

Canny Edge Image

The borders are missing here and findContours does not return me proper results due to this. How can I handle such images.

Both automatic canny edge detection as well as dilate does not work in such cases because it can join only small edges.

Also few documents might have only 2 sides or 3 sides captured using camera and how can we crop the other areas which is not required.

Example Image:

enter image description here

Is there any specific technique for handling such documents? Please suggest few ideas.

Upvotes: 2

Views: 1414

Answers (1)

xszym
xszym

Reputation: 938

Your problem is unusual. One way to solve this problem which comes to my mind is to:

  1. Add white borders around image. https://docs.opencv.org/3.4/dc/da3/tutorial_copyMakeBorder.html

  2. Find lines in edges

http://www.robindavid.fr/opencv-tutorial/chapter5-line-edge-and-contours-detection.html

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html

  1. Make Probablistic HoughLines

  2. Crop image by these lines. It will for sure work for image like 1st one. For image like 2nd one you can use perpendicular and parallel lines.

For sure your algorithm must be pretty complex to works good. The easiest way is to take a picture of whole document if it is possible.

Good luck!

Upvotes: 1

Related Questions