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.9-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e81c8fba5b43e00886692b23b8271c4b715c9b442bfff5d6f9d83cfb3d25e82f |
|
MD5 | 8997736dc5dd74179ff2086a2ddb62b7 |
|
BLAKE2b-256 | 20a1ce52a780fa2392e8998fdcaf606cdf2c67ae230bbca250c2fd81728a2812 |
Hashes for pysseract-0.1.9-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c90d7a091f4116c653faad12c1944e9ac5c01a540947f2770d76da7836324e15 |
|
MD5 | 5c90c6a6a1d2faf0e6d984d517976e12 |
|
BLAKE2b-256 | f8f55c96a3c87588a7c344ae5b66e6f6888b3b045f8d9030cd8a2d7172780b05 |
Hashes for pysseract-0.1.9-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fd5171a43bcb0e80c1a115062d963da41ed3e546730eb52b231397eb796c70c |
|
MD5 | fae48dac6452e798974b3a4443558bd1 |
|
BLAKE2b-256 | bf6ea63e055c009fe2c111118bccd95feebea4b876b116ec3a53d4c391cbbc1f |
Hashes for pysseract-0.1.9-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ae60fa16fd8f5bfc8f8fb6dc0cba711deef652f00d42b1a23c3950ec3185889 |
|
MD5 | a3d23551860b0e8c053d6452c699f83e |
|
BLAKE2b-256 | 80a7dc37c46befc4a6922baad7696353fc69b1d4c19c101257eacbb638df276c |
Hashes for pysseract-0.1.9-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eeddbe1aa1647b11eb6419f85d7f1d0284c718943581e40c71287b835674695 |
|
MD5 | 823082ed8967bd0f9e3147d75e5fc431 |
|
BLAKE2b-256 | 233d889c1f0f011430a34466852340fbab0b360c23007780033093609c42c436 |
Hashes for pysseract-0.1.9-cp36-cp36m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa26893da494d6edd2ef935d5695c2941eec145b26a3a86aeb9572e1c8bd8697 |
|
MD5 | e6f2109aa4fede3ac6e17851ce4cb01f |
|
BLAKE2b-256 | b1c15d79512b8388fefa27bb0601545bee1e6a1e4a017245267db10493c7517d |
Hashes for pysseract-0.1.9-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb561d48fb06115495347b217cac695197b97ec523b5e05c34279c193675493b |
|
MD5 | f086b88c940949a53979962d7f3c6bf1 |
|
BLAKE2b-256 | 9d5f7b5fd660156b46c13e6fc99fbec93f1b90a7ca1384333f45339d9f007bdc |
Hashes for pysseract-0.1.9-cp35-cp35m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c8be967cbc1159fba40af27921c0bbf57dcea32e04eb109014d7c38b05d61df |
|
MD5 | 81d55e68a622506a9480b4e42d859a70 |
|
BLAKE2b-256 | 36eb95f87d460131d3a862fbf1790b04b8946943d7fe2f0ac0dba8e4938deb6c |