Python binding to Tesseract API
Project description
Pysseract
A Python binding to Tesseract API. Tesseract is an open-source tool made available by Google for Optical Character Recognition (OCR) - that is, getting a computer to read the text in an image. Tesseract allows you to perform this task at a number of levels of granularity (one character at a time, one word at a time, and so on), by segmenting the page in a number of different ways (by assuming the whole page is one lump of text, or one line, or sparsely located throughout the source image), and with a number of different language models including ones you have built (pre-built models are available at https://github.com/tesseract-ocr/tessdata among other places).
Pip 19.3.1 or greater is required if you're installing the wheel for this package, otherwise just install the source. On Linux, if you install the wheel Tesseract comes included. You will however need to provide the Tesseract models. An example of how you might do this with English on a linux system is as follows:
curl -O https://raw.githubusercontent.com/tesseract-ocr/tessdata_fast/4.0.0/eng.traineddata
mkdir -p /usr/local/share/tessdata/ && sudo mv eng.traineddata /usr/local/share/tessdata/
The reason the file is being put in to /usr/local/share/tessdata/
is because that is the default value for TESSDATA_PREFIX
, an environment variable that Tesseract uses to locate model files. You're free to override the value of TESSDATA_PREFIX
, of course.
Documentation is hosted on readthedocs.
Basic usage
In order to just get all the text from an image and concatenate it into a string, run the following:
import pysseract
t = pysseract.Pysseract()
t.SetImageFromPath('tests/001-helloworld.png')
print(t.utf8Text)
If instead you want to iterate through the text boxes found in an image at the TEXTLINE level (coarser-grained than WORD, but also lower-level than BLOCK), then you might run the following:
with pysseract.Pysseract() as t:
resIter = t.GetIterator()
LEVEL = pysseract.PageIteratorLevel.TEXTLINE
for box, text in t.iterAt(LEVEL):
lines.append(text)
boxes.append(box)
A third possibility is that you may want to control how exactly the image is segmented. This is done before instantiating a ResultIterator
, as follows:
with pysseract.Pysseract() as t:
t.pageSegMode = pysseract.PageSegMode.SINGLE_BLOCK
t.SetImageFromPath("002-quick-fox.jpg")
t.SetSourceResolution(70)
resIter = t.GetIterator()
LEVEL = pysseract.PageIteratorLevel.TEXTLINE
lines = []
boxes = []
for box, text in t.IterAt(LEVEL):
lines.append(text)
boxes.append(box)
Building the package
Requirements
- gcc/clang with at least c++11 support
- libtesseract, libtesseract-dev (equivalent on non-Debian/Ubuntu systems)
- pybind11>=2.2
python3 setup.py test build install
Building the documentation
pip install sphinx sphinx_rtd_theme
python3 setup.py build_sphinx
You should find the generated html in build/sphinx
.
Contribute
Look at Tesseract BaseAPI
and import those functions of interest to pymodule.cpp
.
Please write a brief description in your wrapper function like those already in pymodule.cpp
.
Reference
LICENSE
GPLv3
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
Built Distributions
Hashes for pysseract-0.1.10-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 924383389789fa255aca87b1082a6a89c279a189520892f6d59a2c8df3dba3b5 |
|
MD5 | 8aa56d54003386598bb01d890241869d |
|
BLAKE2b-256 | 86a87ae2b1834e99f2b1d60f181bee3eb70bc532ae55e2cf7d1cce4254eca9cf |
Hashes for pysseract-0.1.10-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8025f3f60d0b9493bd407584d308f6ec5aa8f3606303fadd0def0184b8d47dd4 |
|
MD5 | 8a81205840989e9c394d3a2a3a528316 |
|
BLAKE2b-256 | 3ab90261614faa57e2a48e7244e2e51d058b7e77f20f836dc11684345022ac7a |
Hashes for pysseract-0.1.10-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7d51376a86f451417fc9f6f78ce87800d080886a5c128cf03d56474bf304a4c |
|
MD5 | b45927e59becd5046ff32d6a627e1c1b |
|
BLAKE2b-256 | dbd9f761e64bf1df1888a38650303bea5ef46269387dd2bf6d433725e60b1c93 |
Hashes for pysseract-0.1.10-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 109207f48081d31ec41e2053a2370a1268f22711e1b4dba4e3d5ed682c4d11d7 |
|
MD5 | 3ee805f275b12912592ee2098c96c79f |
|
BLAKE2b-256 | c55f4baf1df15ca91d7b465b6b3447ed551fa9d9451969767dc49358a941e70f |
Hashes for pysseract-0.1.10-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef37e02664439213e32761b66769ed0399fb7c09ab9e6700d106250c4cf34e13 |
|
MD5 | a2acdc4a65c88f7011290ace83f23134 |
|
BLAKE2b-256 | acff99bb36c07fb4de266c401d3264673665412f0d439de0d58c1f23fd937686 |
Hashes for pysseract-0.1.10-cp36-cp36m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bb713d0b22cb1caa864d049aa399829f2092c35c6f77fb22063e01613435eb8 |
|
MD5 | dc5c5379862314bf0a09f77cf737e20a |
|
BLAKE2b-256 | 488c0175eef2c930f6cb5cc6daabfb52ba3cac91286f36123b3ade9318242103 |
Hashes for pysseract-0.1.10-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69544e2be429d19e6b00200d83db3cb48b2ea7c562c794e3e015c08f41c1397d |
|
MD5 | d7537f5ca8d428aebf9b9eda62eeb725 |
|
BLAKE2b-256 | 889083ea6b0849638d5fa7d2fd8ba3e5adb742a79171bc9cc18173354466750b |
Hashes for pysseract-0.1.10-cp35-cp35m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba027ca12d51c8ceeec99399dd4563adb02def6d37ee97978d777c839f0565d2 |
|
MD5 | b407db132047713bb3cb7ffebdc75a43 |
|
BLAKE2b-256 | 748caef19a209ce54a5cb33604005fe48ebf262cba73ccdbf0cabe01406971a2 |