Skip to main content

autocrop_kh

Automatic Document Segmentation and Cropping for Khmer IDs, Passport and Documents

Autocrop_kh is a Python package for automatic document segmentation and cropping, with a focus on Khmer IDs, Passport and other documents. It uses a DeepLabV3 model training on Khmer ID, Passport document datasets to accurately segment and extract documents from images.

License: Apache-2.0 License

Installation

Install from source

# clone repo 
git clone https://github.com/MetythornPenn/autocrop_kh.git

# install lib from source
pip install -e .

Install from PyPI

pip install autocrop-kh

Usage

Python Script

import cv2
from autocrop_kh import autocrop

# Download sample image from this url : "https://github.com/MetythornPenn/autocrop_kh/raw/main/sample/img-1.jpg"
# Model auto-download (default):
# The ONNX model is downloaded on first run from Hugging Face:
# "https://huggingface.co/metythorn/autocrop/resolve/main/autocrop_model_v2.onnx"

img_path = "sample/img-1.jpg"
model_path = None

extracted_document = autocrop(
    img_path=img_path,
    model_path=model_path,
    device='cuda:0',
    output_path="extracted_document.jpg"
)

print("Extracted document saved to extracted_document.jpg")
  • img_path: Path of the input image file.
  • model_path: Path to the pre-trained ONNX model (local path, .onnx only). If None, it auto-downloads from Hugging Face.
  • device: Specify cpu or cuda (default is cpu).
  • output_path: Optional. If set, saves the extracted image to this path.
  • AUTOCROP_KH_MODEL_DIR: Optional env var to change the download/cache directory.
  • AUTOCROP_KH_HF_REPO: Optional env var to change the Hugging Face repo (default metythorn/autocrop).

Result:

Left Image Right Image

Left Image Right Image

Noted : This model was trained with 25000 datasets include opensource data and my custom synthetic data.

Reference

Metadata

Release files for autocrop-kh 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autocrop-kh 1.1
File Size Uploaded Provenance
autocrop_kh-1.1.tar.gz 9.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for autocrop-kh 1.1
File Interpreter ABI Platform
autocrop_kh-1.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.6 kB

Release files / autocrop_kh-1.1.tar.gz

Download URL autocrop_kh-1.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b37617e30bde6607bbd9b1f78f9c23c3156fc16a898995092bf50a227da21497
BLAKE2b-256 checksum
How to use checksums
5b96bf57cd079103d47bf5719e9a8368806102ae118ea2eacaded2436d1f5310
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / autocrop_kh-1.1-py3-none-any.whl

Download URL autocrop_kh-1.1-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e21f37da87412668e01337759635290f537d0e129818f03d5ea0eaf43b94cff5
BLAKE2b-256 checksum
How to use checksums
5eb768a13bc02346e18fe76e3164445a78160d00ced3d40849158a9d8daab3f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for autocrop-kh 1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page