-
Notifications
You must be signed in to change notification settings - Fork 21
Home
This repository contains code to achieve the lovely scan effects provided by mobile camera based document scanning apps like Camscanner, Adobe Scan. I have kept the repository's name as "DocumentScanner" to make it more descriptive but the name I prefer to use for my project is "RScan".
The OpenCV based project has been implemented on both Python as well as JAVA indipendently. JAVA implementation is meant to make the project Android compatible.
In the Python language, the project uses only the OpenCV & numpy libraries. JAVA code is also based primarily on OpenCV library apart from some basic supports for ArrayLists etc.
This documentation will be using JAVA program as its reference but Python geeks need not get dissapointed as the same documentation will aslo help as complete guide for Python program (after all both Python & JAVA program use nothing other than our favourite OpenCV)
Lets begin !
My system has:
- Python 3.5.4 with OpenCV 3.4.3
- JAVA jdk 11.0.8 with OpenCV 3.4.4
Document scanning performs two major tasks, auto-crop of documents and processing the cropped images to make them look like scanned documents.
I have used Photoshop to figure out the combination of editing techniques required to achieve the scan effect. In Photoshop the scanning effect can be acheived using the operations, "white point select" & "black point select" provided by "Levels" features. Combination of these two point select operations result in the scan effect often regarded as "magic color" in various mobile apps. Apart from this,High Pass Filter can be used along with above two operations to achieve some exciting results while processing documents that don't contain images. Scanning of documents in the "Black & White" mode is achieved by processing the image in LAB color space using OpenCV.
Auto crop feature in RScan is programmed using image contours & HoughLine transform in combination with few other filters. Automatically cropping the documents require a robust edge detection algorithm. While researching for such algorithms I discovered neural network based Holistically-Nested Edge Detection(HED) by Saining Xie & Zhuowen Tu. HED outputs some very impressive edge detection but I haven't used it in the project yet as I was able to achieve some decent edge detection without a neural network approach but I believe a wise use of algorithms like HED can help achieve some very good results. Apart from HED, I also came around a GPU based Canny edge detection showcased in Google's Mediapipe website. Another reason which prevented me from using neural approach was I wanted to avoid heavy computational requirments and make things fast but over the time I felt if neural approach offers a decent speed then it may be used in the project in later stages.
In JAVA, the project has two packages namely "crop" & "scan". These packages contains various methods to implement the processing techniques.
In Python, I haven't structred the project using OOPs & functions but there are two separate .py files to implement the crop & scan features. I have tried my best to provide a well commented code for both Python and JAVA. Most of the image processing fraternity use Python and so do I, the only reason for which I coded it on JAVA too was to make it compatible on Android without loosing much on processing speed.
email id : [email protected]