Coders Packet

Document Scanner using OpenCV (using Python)

By Sai Lokesh

A document scanner is a model based on OpenCV. It takes video as an input and scans the document present in the video and then zooms it and shows the clear text on the document.

A document scanner is a model based on OpenCV. It is written in Python. It takes the video as an input. The video may be a file in your system or it's capturing in real-time through webcam. Here the dependencies are OpenCV and NumPy. Even if you are capturing the page in an unorganized way using webcam still it wraps up the image and perfectly arranges the image. The first step will be capturing the video through webcam using OpenCV. place a paper with the content or any document with the content on it on a table and capture it.

The workflow is as follows :

The first step will be the image preprocessing. In that, the images are converted to gray, and then they will be dilated. To see the edges of the image we use imgcanny() function. To thicken the edges we use imgerode() function.

Now we have to get the contours of the image. Contours are nothing but the outline of the shapes present in the image. For that, we have to define the function imgcontour()(user-defined function) in which we find the contours present in the image by findcontour(). Now we have to iterate through that contours and have to find the area of each and every contour. From that list, we have to determine contour with the largest area and largest perimeter. Here for contours, we were given red color (255,0,0).

After that, we have to reorder the points which are boundaries that we got from drawing the contours on the image.

The next step will be wrapping up the image.this is that we find the border points i.e 4 edge points of the document in the image and we will zoom it and arrange the image in perfect order. This plays a crucial role when we capture the document in slant form.

Now, we have to stack the images,i.e the original video, and scanned video will be stacked together in the output.

To clear the output press '0'.

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Sai Lokesh (sailokeshvadlamudi)

Download packets of source code on Coders Packet