Skip to main content

A document scanner based on openCV3 and scikit-image

Project description


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.


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


Use /scripts/ to see what's happen.

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


Restful API server


The minimum required dependencies to run document-scanner are:

  • Python>=3.7
  • openCV3
  • scikit-image
  • pandas

Use the following command to install dependencies with pip:

$ pip install -r requirement.txt

For server, additional denpendencies are:

  • sanic
  • sanic_compress

Use the following command to install dependencies with pip:

$ pip install -r server-requirement.txt


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
doc_scanner-0.0.3-py2.py3-none-any.whl (11.6 kB) Copy SHA256 hash SHA256 Wheel py2.py3
doc_scanner-0.0.3.tar.gz (11.0 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page