asyncio tesseract wrapper for Tesseract-OCR
Project description
aiopytesseract
A Python asyncio wrapper for Tesseract-OCR.
Installation
Install and update using pip:
pip install aiopytesseract
Usage
List all available languages by Tesseract installation
import aiopytesseract
await aiopytesseract.languages()
await aiopytesseract.get_languages()
Tesseract version
import aiopytesseract
await aiopytesseract.tesseract_version()
await aiopytesseract.get_tesseract_version()
Tesseract parameters
import aiopytesseract
await aiopytesseract.tesseract_parameters()
Confidence only info
import aiopytesseract
await aiopytesseract.confidence("tests/samples/file-sample_150kB.png")
Deskew info
import aiopytesseract
await aiopytesseract.deskew("tests/samples/file-sample_150kB.png")
Extract text from an image: locally or bytes
from pathlib import Path
import aiopytesseract
await aiopytesseract.image_to_string("tests/samples/file-sample_150kB.png")
await aiopytesseract.image_to_string(
Path("tests/samples/file-sample_150kB.png").read_bytes(), dpi=220, lang='eng+por'
)
Box estimates
from pathlib import Path
import aiopytesseract
await aiopytesseract.image_to_boxes("tests/samples/file-sample_150kB.png")
await aiopytesseract.image_to_boxes(Path("tests/samples/file-sample_150kB.png")
Boxes, confidence and page numbers
from pathlib import Path
import aiopytesseract
await aiopytesseract.image_to_data("tests/samples/file-sample_150kB.png")
await aiopytesseract.image_to_data(Path("tests/samples/file-sample_150kB.png")
Information about orientation and script detection
from pathlib import Path
import aiopytesseract
await aiopytesseract.image_to_osd("tests/samples/file-sample_150kB.png")
await aiopytesseract.image_to_osd(Path("tests/samples/file-sample_150kB.png")
Generate a searchable PDF
from pathlib import Path
import aiopytesseract
await aiopytesseract.image_to_pdf("tests/samples/file-sample_150kB.png")
await aiopytesseract.image_to_pdf(Path("tests/samples/file-sample_150kB.png")
Generate HOCR output
from pathlib import Path
import aiopytesseract
await aiopytesseract.image_to_hocr("tests/samples/file-sample_150kB.png")
await aiopytesseract.image_to_hocr(Path("tests/samples/file-sample_150kB.png")
Multi ouput
from pathlib import Path
import aiopytesseract
async with aiopytesseract.run(
Path('tests/samples/file-sample_150kB.png').read_bytes(),
'output',
'alto tsv txt'
) as resp:
# will generate (output.xml, output.tsv and output.txt)
print(resp)
alto_file, tsv_file, txt_file = resp
Config variables
from pathlib import Path
import aiopytesseract
async with aiopytesseract.run(
Path('tests/samples/text-with-chars-and-numbers.png').read_bytes(),
'output',
'alto tsv txt'
config=[("tessedit_char_whitelist", "0123456789")]
) as resp:
# will generate (output.xml, output.tsv and output.txt)
print(resp)
alto_file, tsv_file, txt_file = resp
from pathlib import Path
import aiopytesseract
await aiopytesseract.image_to_string(
"tests/samples/text-with-chars-and-numbers.png",
config=[("tessedit_char_whitelist", "0123456789")]
)
await aiopytesseract.image_to_string(
Path("tests/samples/text-with-chars-and-numbers.png").read_bytes(),
dpi=220,
lang='eng+por',
config=[("tessedit_char_whitelist", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")]
)
For more details on Tesseract best practices and the aiopytesseract, see the folder:
docs
.
Examples
If you want to test aiopytesseract easily, can you use some options like:
- docker/docker-compose
- streamlit
Docker / docker-compose
After clone this repo run the command below:
docker-compose up -d
streamlit app
For this option it's necessary first install aiopytesseract
and streamlit
, after execute:
# remote option:
streamlit run https://github.com/amenezes/aiopytesseract/blob/master/examples/streamlit/app.py
# local option:
streamlit run examples/streamlit/app.py
note: The streamlit example need python >= 3.10
Links
- License: Apache License
- Code: https://github.com/amenezes/aiopytesseract
- Issue tracker: https://github.com/amenezes/aiopytesseract/issues
- Docs: https://github.com/amenezes/aiopytesseract
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiopytesseract-0.14.0.tar.gz
(19.4 kB
view details)
Built Distribution
File details
Details for the file aiopytesseract-0.14.0.tar.gz
.
File metadata
- Download URL: aiopytesseract-0.14.0.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2688610ad8d2e80cc3d2e31933c0855e1a577084f3f28df670088bc097828fb8 |
|
MD5 | aadeec176f3b686ad4941b5d3f73716b |
|
BLAKE2b-256 | 9475852d4572e6b421c5062df9ef6c78521d63af554eac4bb139ec13304f0993 |
File details
Details for the file aiopytesseract-0.14.0-py2.py3-none-any.whl
.
File metadata
- Download URL: aiopytesseract-0.14.0-py2.py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b936ed0f990cfc375044fd59b08268b256537477b189523ef8b8132b77f1e50 |
|
MD5 | d9a36fa9549d751f0c226ff86b35932c |
|
BLAKE2b-256 | 23297dea7d9d7bb89c71f6aab116523007a8fedfc68af734b4080d1e6b2fc9c0 |