Brainy Pi

Available to select audience (currently beta)

Document scanner
Scanning documents is a vital function utilized in almost every field today. However, manually scanning and digitizing large volumes of documents can be time-consuming and labor-intensive. Automating this process can lead to increased efficiency and productivity. In this blog, we will explore how to automate the scanning of documents using OpenCV, an open-source computer vision library, and build and deploy this application on BrainyPi. By the end of this blog, users will have a clear understanding of the tools and techniques required to develop a document scanner using Opencv on BrainyPi which can help save time and effort in various industries.

docScanner.py

  1. This is a Python script for a document scanner that uses OpenCV. The script starts by importing the necessary libraries and defining a main() function.
  2. In the main() function, the script initializes the camera cv2.VideoCapture() module and waits for 2 seconds for the camera to warm up. Then it initializes trackbars using docScannerUtils.initializeTrackbars().
  3. The script then enters an infinite loop where it captures an image from the camera, scans the document in the image using docScannerUtils.scanDocumentsInImage(), and displays the resulting image using docScannerUtils.stackImages().
  4. If the s key is pressed, the script saves the scanned image to a file in the “Scanned” directory with a name like “qmyImage0.jpg”, “qmyImage1.jpg”, and so on. It then displays a green rectangle with text “Scan Saved” on the image.
If the q key is pressed, the script turns off the camera, closes all windows, and ends the program.
  1. Overall, the script provides a simple way to scan documents using OpenCV.

docScannerUtils.py

  1. The scanDocumentsInImage() function is the main function that performs the document scanning.
    • Inputs:
      1. inputImage ([opencv Mat]): Input image
    • Outputs:
      1. imageArray ([array of opencv Mat]): Contains array of images, with the last image being the scanned document.

Running Code for Document scanner using OpenCV on BrainyPi

  1. We also need to get the code before proceeding with the dependencies installation.
git clone https://github.com/brainypi/brainypi-opencv-examples.git
cd document-scanner
  1. Installing the dependencies
pip install -r requirements.txt
  1. We can now run the code and start scanning the QR codes.
python docScanner.py
  1. Press q exit out of the program.

EndNotes

Hence, we understood and implemented Document scanner using opencv on BrainyPi. Stay tuned to upcoming blogs !
0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*