...

/

A Review of the Document Scanner

A Review of the Document Scanner

Review the steps of creating a document scanner.

Let’s look at the correct code for creating the document scanner.

First, we set the size of our document after scanning.

frameWidth = 480
frameHeight = 640

Image Processing

We change the image to grayscale and then make it blurry. This helps us get the edges properly. To get the edges, we use the cv2.canny() function of the OpenCV library:

Press + to interact
def imageProcessing(img):
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
imgBlur = cv2.GaussianBlur(imgGray,(5,5),1)
imgCanny = cv2.Canny(imgBlur,200,200)
return imgCanny

Get image contours

Next, we define the variable that we’ll use in this function. We define a NumPy array, biggest, and an integer, bArea. We use the cv2.findcontours method to find all the contours:

Press + to interact
biggest = np.array([])
bArea = 0
contours,heirarchy = cv2.findContours(img,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

We loop ...