Skip to content

A opencv4 and scikit-image based python digital image document scanner.

License

Notifications You must be signed in to change notification settings

fMeow/document-scanner

Repository files navigation

Document-Scanner

Build Status

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.

Pipeline

  1. 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.

  2. Preprocessing

    1. Blur with Median filter

    2. Histogram equalization

    3. Morphological operation (Opening)

    4. (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.

    5. Canny edge detector

    6. Contour detection

    7. Morphological Erosion

    8. Morphological Dilation

      This step is to dilate the contour to reduce the impact of non-linear edge when calculating connectivity.

  3. Hough Transform

  4. 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.

  5. Frame detection

    1. Find possible frames
    2. Select the most possible frame
  6. Warp

  7. (TODO) Post process

Demo

Use /scripts/scan_demo.py to see what's happen.

Put images under /data/images and run the scripts.

Usage

Dependencies

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

Contribution