Skip to main content

Fast and accurate OCR on images and PDFs using Apple Vision framework directly from command line.

Project description

Apple Vision Framework Python Utilities

Fast and accurate OCR on images and PDFs using Apple Vision framework directly from command line.

Features

  • Fast and accurate, multi-language support (-l, --lang), powered by Apple's industry-strength Vision framework.
  • Supports all common input image formats: PNG, JPEG, TIFF and WebP.
  • Supports PDF input (the file gets converted to images first). This tool does NOT assume a file is PDF just because it has a .pdf extension, you need to pass -p, --pdf flag.
  • Outputs extracted text only by default, but can output in JSON format containing confidence of recognition for each line with -j, --json flag.

Demo

Below is the output of running the tests:

https://g.teddysc.me/96d5b1217b90035c163b3c97ce99112f

Installation

pipx

This is the recommended installation method.

$ pipx install apple-vision-utils

pip

$ pip install apple-vision-utils

Usage

$ apple-ocr --help

usage: apple-ocr [-h] [-j] [-p] [-l LANG] [--pdf2image-only]
                 [--pdf2image-dir PDF2IMAGE_DIR] [-V]
                 file_path

Extract text from an image or PDF using Apple's Vision framework.

positional arguments:
  file_path             Path to the image or PDF file.

options:
  -h, --help            show this help message and exit
  -j, --json            Output results in JSON format.
  -p, --pdf             Specify if the input file is a PDF.
  -l LANG, --lang LANG  Specify the language for text recognition (e.g., eng,
                        fra, deu, zh-Hans for Simplified Chinese, zh-Hant for
                        Traditional Chinese). Default is 'zh-Hant', which
                        works with images containing both Chinese characters
                        and latin letters.
  --pdf2image-only      Only convert PDF to images without performing OCR.
  --pdf2image-dir PDF2IMAGE_DIR
                        Specify the directory to store output images. By
                        default, a secure temporary directory is created.
  -V, --version         show program's version number and exit

Develop

$ git clone https://github.com/tddschn/apple-vision-utils.git
$ cd apple-vision-utils
$ poetry install

Test

# in the root of the project
poetry install
poetry shell
cd tests && ./test.sh

Project details


Download files

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

Source Distribution

apple_vision_utils-0.1.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

apple_vision_utils-0.1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file apple_vision_utils-0.1.2.tar.gz.

File metadata

  • Download URL: apple_vision_utils-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.3 Darwin/23.4.0

File hashes

Hashes for apple_vision_utils-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ac45eb7dbfda7e33b4949bc53799f07cf7a1c6b32e0796889504547e83e306eb
MD5 247628ce05c7e834e3b864e6c9767b3c
BLAKE2b-256 b576ba80fcaae23eb2e9c16fe30093774487633450f0578f1c29a8beed6dce3f

See more details on using hashes here.

File details

Details for the file apple_vision_utils-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for apple_vision_utils-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f48037e6eaf44b2eae92ccd4c7dea8c4b434a5c634a5ed1d3ae145f8c57d343
MD5 d2ebfba90e01ffc69fe16cca63bf0306
BLAKE2b-256 04a6956bf97d8e6b49c15a030654e045886bc8c415129420c0cd971e3532135e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page