An image into a document scanner using python
no vote
You see, scanning a file using a smartphone can be broken down into three simple steps: Step 1: edge detection. Step 2: use the edge in the image to find the contour (contour) to indicate that a piece of paper is scanned. Step 3: apply a perspective transformation to obtain a top view of the file. Line 2-7 handle import we need the necessary Python package. We're going to talk about our four by importing what I discussed last week_ point_ The transform function starts. We will also use the imutils module, which contains convenient features for resizing, rotating, cropping and image editing. You can read more about imutils after my basic image manipulation. Next, let's import the threshold of scikit image_ Adaptive function. The feature will help us get a "black and white" feel of our scanned images. Finally, we will use numpy's numerical processing, argparse to parse the command line parameters, and CV2 to bind our OpenCV. Lines 10-13 handle parsing our command line parameters. We only need the image of a switch, - image, which is the image of the path containing the document we want to scan. Now that we have the path to our image, we can move on to step 1: edge detection. Line 61 performs warping modification. As a matter of fact, all the heavy work is done by four_ point_ Transform function. Also, you can read more about last week's post in this feature. We will pass two parameters to four_ point_ Transform: the first one is ours. We loaded the original image of the disk (not one of the sizes). The second parameter is to represent the file, multiplied by the contour of the adjusted size scale. So, you may wonder, why do we multiply by the adjustment ratio? We multiplied the adjusted ratio because we performed edge detection and found that the contour height = 500 pixels on the adjusted image. However, we want to perform the scan on the original image instead of the resized image, so we multiply the contour points by the resizing ratio. To get a black-and-white image, we take a distorted image, convert it to grayscale and apply adaptive threshold to line 65-67.