To load an image with OpenCV we use the cv2.imread() function, it takes the path of the image as an argument. Next, we set the height and width of the image so that we can resize it, and we also create the green variable for the contour display later on. This function will help us perform a 4 point perspective transform to obtain the top-down view of the document. We start by importing the OpenCV library and the four_point_transform helper function from the imutils package. Image = cv2.resize(image, (width, height)) Load the ImageĬreate a new file inside the document-scanner directory, name it scanner.py and put the following code: from imutils.perspective import four_point_transform Ok great! We are now ready to start writing some code. Let's check the version of OpenCV by running the command below: $ python3 Pip install scipy # needed for the imutils package Open a new terminal and create a directory and the necessary packages: mkdir document-scanner Apply warp perspective to get the top-down view of the document.Select only the contours of the document.The steps that we need to follow to build this project are: This is a beginner tutorial so I will explain in detail each line of code so that you can follow along with me. This can be useful, for example, for scanning pages in a book. In this tutorial, we will create a simple document scanner using the OpenCV library. The library contains more than 2500 algorithms that are used for facial detection, gesture recognition, augmented reality, tracking moving objects, identifying objects, etc. OpenCV is a library written in C++ aimed to provide an infrastructure for computer vision and machine learning.
0 Comments
Leave a Reply. |