Skip to content

A Document Scanner in python using OpenCV, that takes an image of a document, detects the document's edges, applies a perspective transform to get a top-down view.

License

Notifications You must be signed in to change notification settings

joellijo32/Document-Scanner-using-OpenCV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Document Scanner

This project is a document scanner built using OpenCV and Python. It takes an image of a document, detects the document's edges, applies a perspective transform to get a top-down view.

Features

  • Automatic Document Detection: Finds the document in the image using edge detection and contour analysis.
  • Perspective Correction: Warps the detected document to a flat, top-down view.
  • Inverted Output: Option to invert the colors of the output.

Project Structure

opencv-project-template/
│
├── src/
│   ├── main.py       # Main application logic
│   └── utils.py      # Helper functions for image processing
│
├── assets/           # Input images
│   └── sample.jpg
│
├── results/          # Processed output image
│   └── corrected.png
│
├── requirements.txt  # Python dependencies
├── README.md         # Project documentation

Installation

  1. Clone the repository:
    git clone <repo-link>
  2. Install the required dependencies:
    pip install -r requirements.txt

Usage

Run the main.py script from the root directory:

python src/main.py --image assets/sample.jpg

Arguments

  • -i, --image: Path to the input image (Required).
  • -I, --inverted: Optional flag to invert the output colors.

Example

python src/main.py --image assets/receipt.jpg --inverted

Output

The processed images will be saved in the results/ directory:

  • corrected.png: The perspective-corrected image.
  • scanned.png (or scanned_inverted.png): The final grayscale output.

Sample run :

Input image:

1

Output image:

corrected

Overall Working: collage

Made by Joel Lijo Mathew.

About

A Document Scanner in python using OpenCV, that takes an image of a document, detects the document's edges, applies a perspective transform to get a top-down view.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages