Document-Scanner is open-source python package to scan, segment and tranform images of documents as if the documents is scanned by a scanner. It includes predefined pipelines on preprocessing, frame detection, transformation and post processing to add styles.
-
Convert to HSV color space
The following pipelines is applied first on intensity slice , or the Value phase, of the original image. If failed to find frame in the intensity image, apply exactly the same processes to saturation image.
-
Preprocessing
-
Blur with Median filter
-
Histogram equalization
-
Morphological operation (Opening)
-
(Optional) Threshold based segmentation.
Here we assume that the document of interest is mainly white while background is darker. Then we can extract document from background with a proper threshold. After histogram, maybe we can just assume the document lays in the half brighter part on histogram.
-
Canny edge detector
-
Contour detection
-
Morphological Erosion
-
Morphological Dilation
This step is to dilate the contour to reduce the impact of non-linear edge when calculating connectivity.
-
-
Hough Transform
-
Intersection 1. Find the cartesian coordination of intersection points 1. Calculate connectivity on every intersections on four direction: up, right, bottom, left. 1, Corner Compute the possiblity on every intersection points to decide the orientation of corner.
-
Frame detection
- Find possible frames
- Select the most possible frame
-
Warp
-
(TODO) Post process
Use /scripts/scan_demo.py to see what's happen.
Put images under /data/images and run the scripts.
The minimum required dependencies to run document-scanner are:
- Python>=3.6
- OpenCV4
- scikit-image
- pandas
- numpy
Use the following command to install dependencies with pip:
pip install -r requirements.txt