Skip to main content

OCR toolkits

Introduction

Collection of functions to work with ocr and synthetic data generater

Features

  • Generate synthetic images containing Khmer text
  • Customize text content from a file
  • Choose from multiple font styles
  • Option to apply random blur effect to images
  • Generate corresponding labels for each image

Installation

You can install the Khmer Text Image Generator using pip:

pip install ocr_toolkits

Usage

move files from a folder to another folder filter by extension

from ocr_toolkits import move_files_ext

# Move all files from 'src' directory to 'dst' directory
move_files_ext(
    src_dir = 'src', 
    dst_dir = 'dst1',
)
# Move only .jpg files from 'src' directory to 'dst' directory
move_files_ext(
    src_dir = 'src', 
    dst_dir = 'dst1',
    ext = '.jpg'
)

change files extension from a folder filter by extension

from ocr_toolkits import change_files_ext

# Example usage
change_files_ext(
  src_dir ='src', 
  dst_dir = 'dst', 
  ext = '.png'
)

delete files from a folder to another folder filter by extension

from ocr_toolkits import delete_files_ext


delete_files_ext(
    dir = 'dst',
    ext = '.jpg',
)

autocorrect gender

from ocr_toolkits.postprocess import autocorrect_gender


corrected_gender_eng = autocorrect_gender("ប្រុ", return_eng=False)
print(corrected_gender_eng)  # Output: Male

# Example usage with return_eng=False (Cambodian output)
corrected_gender_kh = autocorrect_gender("ស្រ", return_eng=False)
print(corrected_gender_kh)  # Output: ស្រី

resize image

from ocr_toolkits import resize_image

resized_image = resize_image(
    image_path='./images/img.jpg', 
    width=555,
    height=555,
    save=True,
    save_path='save.jpg'
)
  • create text file to words list eg. dict.txt and put all khmer words you want to gnerate or download sample data here

  • create a folder call font and download all font from this link : font

  • create python script to generate data eg. test.py

from khmerocr_tools import synthetic_data

# Set parameters
image_height = 128
output_folder = 'output'
output_labels_file = 'output/labels.txt'
text_file_path = "dict.txt"
font_option = [1, 2]  

# Generate images and labels
synthetic_data(
    text_file_path, 
    image_height, 
    output_folder, 
    output_labels_file, 
    font_option=font_option, 
    random_blur=True
)

Parameters

  • image_height: Height of the generated images in pixels.
  • output_folder: Path to the folder where generated images will be saved.
  • output_labels_file: Path to the file where labels will be saved.
  • text_file_path: Path to the text file containing Khmer text for generation.
  • font_option: List of integers representing font options.
    • 1 for AKbalthom KhmerLer Regular.
    • 2 for Khmer MEF1 Regular.
    • 3 for Khmer OS Battambang Regular.
    • 4 for Khmer OS Muol Light Regular.
    • 5 for Khmer OS Siemreap Regular.
    • Use an empty list [] to select all available fonts.
  • random_blur: Boolean flag indicating whether to apply random blur effect to images.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for ocr-toolkits 0.0.3

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

Source distribution (sdist)

Source distribution for ocr-toolkits 0.0.3
File Size Uploaded Provenance
ocr-toolkits-0.0.3.tar.gz 8.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ocr-toolkits 0.0.3
File Interpreter ABI Platform
ocr_toolkits-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.1 kB

Release files / ocr-toolkits-0.0.3.tar.gz

Download URL ocr-toolkits-0.0.3.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ad4ceec815f3b100f5e6de24f667e016045f2e7604d51e1baeae199a9e3d2833
BLAKE2b-256 checksum
How to use checksums
584e46cfac37ce74fc33171ff273b3f58e9c284b65a356ef379c90ec3cb7dfae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.4

Release files / ocr_toolkits-0.0.3-py3-none-any.whl

Download URL ocr_toolkits-0.0.3-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fcd706d5361a656c7754cabc957ec465390418f08b41bfd6d4a38701c4dce12
BLAKE2b-256 checksum
How to use checksums
c3d8a2838f7f62166b4cb0270aed47af95ddaac41e59ce61c02f7db0283da506
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.4

Security for ocr-toolkits 0.0.3

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