{"id":13593746,"url":"https://github.com/sirfz/tesserocr","last_synced_at":"2025-05-12T20:51:10.819Z","repository":{"id":41983576,"uuid":"48203815","full_name":"sirfz/tesserocr","owner":"sirfz","description":"A Python wrapper for the tesseract-ocr API","archived":false,"fork":false,"pushed_at":"2025-05-08T07:06:06.000Z","size":549,"stargazers_count":2092,"open_issues_count":51,"forks_count":257,"subscribers_count":56,"default_branch":"master","last_synced_at":"2025-05-08T08:22:49.476Z","etag":null,"topics":["cython","ocr","optical-character-recognition","python-library","tesseract"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sirfz.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-17T23:29:36.000Z","updated_at":"2025-05-08T07:06:11.000Z","dependencies_parsed_at":"2024-03-28T14:43:24.973Z","dependency_job_id":"f4d3fd61-74ba-412a-8105-f1c2f70e45c9","html_url":"https://github.com/sirfz/tesserocr","commit_stats":{"total_commits":165,"total_committers":32,"mean_commits":5.15625,"dds":0.4363636363636364,"last_synced_commit":"3c9519bf0a6bf866669fd93057b04d40b97302c6"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirfz%2Ftesserocr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirfz%2Ftesserocr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirfz%2Ftesserocr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sirfz%2Ftesserocr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sirfz","download_url":"https://codeload.github.com/sirfz/tesserocr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253821018,"owners_count":21969616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cython","ocr","optical-character-recognition","python-library","tesseract"],"created_at":"2024-08-01T16:01:24.049Z","updated_at":"2025-05-12T20:51:10.792Z","avatar_url":"https://github.com/sirfz.png","language":"Python","funding_links":[],"categories":["资源列表","Python","Computer Vision","计算机视觉","光学字符识别OCR","Software","Computer Vision [🔝](#readme)"],"sub_categories":["计算机视觉","OCR","Drone Frames","OCR libraries by programming language"],"readme":"=========\ntesserocr\n=========\n\nA simple, |Pillow|_-friendly,\nwrapper around the ``tesseract-ocr`` API for Optical Character Recognition\n(OCR).\n\n.. image:: https://github.com/sirfz/tesserocr/actions/workflows/build.yml/badge.svg\n    :target: https://github.com/sirfz/tesserocr/actions/workflows/build.yml\n    :alt: Github Actions build status\n\n.. image:: https://img.shields.io/pypi/v/tesserocr.svg?maxAge=2592000\n    :target: https://pypi.python.org/pypi/tesserocr\n    :alt: Latest version on PyPi\n\n.. image:: https://img.shields.io/pypi/pyversions/tesserocr.svg?maxAge=2592000\n    :alt: Supported python versions\n\n**tesserocr** integrates directly with Tesseract's C++ API using Cython\nwhich allows for a simple Pythonic and easy-to-read source code. It\nenables real concurrent execution when used with Python's ``threading``\nmodule by releasing the GIL while processing an image in tesseract.\n\n**tesserocr** is designed to be |Pillow|_-friendly but can also be used\nwith image files instead.\n\n.. |Pillow| replace:: ``Pillow``\n.. _Pillow: http://python-pillow.github.io/\n\nRequirements\n============\n\nRequires libtesseract (\u003e=3.04) and libleptonica (\u003e=1.71).\n\nOn Debian/Ubuntu:\n\n::\n\n    $ apt-get install tesseract-ocr libtesseract-dev libleptonica-dev pkg-config\n\nYou may need to `manually compile tesseract`_ for a more recent version. Note that you may need\nto update your ``LD_LIBRARY_PATH`` environment variable to point to the right library versions in\ncase you have multiple tesseract/leptonica installations.\n\n|Cython|_ (\u003e=0.23) is required for building and optionally |Pillow|_ to support ``PIL.Image`` objects.\n\n.. _manually compile tesseract: https://github.com/tesseract-ocr/tesseract/wiki/Compiling\n.. |Cython| replace:: ``Cython``\n.. _Cython: http://cython.org/\n\nInstallation\n============\nLinux and BSD/MacOS\n-------------------\n::\n\n    $ pip install tesserocr\n\nThe setup script attempts to detect the include/library dirs (via |pkg-config|_ if available) but you\ncan override them with your own parameters, e.g.:\n\n::\n\n    $ CPPFLAGS=-I/usr/local/include pip install tesserocr\n\nor\n\n::\n\n    $ python setup.py build_ext -I/usr/local/include\n\nTested on Linux and BSD/MacOS\n\n.. |pkg-config| replace:: **pkg-config**\n.. _pkg-config: https://pkgconfig.freedesktop.org/\n\nWindows\n-------\n\nThe proposed downloads consist of stand-alone packages containing all the Windows libraries needed for execution. This means that no additional installation of tesseract is required on your system.\n\nThe recommended method of installation is via Conda as described below.\n\nConda\n`````\n\nYou can use the `simonflueckiger \u003chttps://anaconda.org/simonflueckiger/tesserocr\u003e`_ channel to install from Conda:\n\n::\n\n    \u003e conda install -c simonflueckiger tesserocr\n\nOr alternatively the `conda-forge \u003chttps://anaconda.org/conda-forge/tesserocr\u003e`_ channel:\n\n::\n\n    \u003e conda install -c conda-forge tesserocr\n\npip\n```\n\nDownload the wheel file corresponding to your Windows platform and Python installation from `simonflueckiger/tesserocr-windows_build/releases \u003chttps://github.com/simonflueckiger/tesserocr-windows_build/releases\u003e`_ and install them via:\n\n::\n\n    \u003e pip install \u003cpackage_name\u003e.whl\n\nBuild from source\n`````````````````\n\nIf you need Windows tessocr package and your Python version is not supported by above mentioned project,\nyou can try to follow `step by step instructions for Windows 64bit` in `Windows.build.md`_.\n\n.. _Windows.build.md: Windows.build.md\n\ntessdata\n========\n\nYou may need to point to the tessdata path if it cannot be detected automatically. This can be done by setting the ``TESSDATA_PREFIX`` environment variable or by passing the path to ``PyTessBaseAPI`` (e.g.: ``PyTessBaseAPI(path='/usr/share/tessdata')``). The path should contain ``.traineddata`` files which can be found at https://github.com/tesseract-ocr/tessdata.\n\nMake sure you have the correct version of traineddata for your ``tesseract --version``.\n\nYou can list the current supported languages on your system using the ``get_languages`` function:\n\n.. code:: python\n\n    from tesserocr import get_languages\n\n    print(get_languages('/usr/share/tessdata'))  # or any other path that applies to your system\n\nUsage\n=====\n\nInitialize and re-use the tesseract API instance to score multiple\nimages:\n\n.. code:: python\n\n    from tesserocr import PyTessBaseAPI\n\n    images = ['sample.jpg', 'sample2.jpg', 'sample3.jpg']\n\n    with PyTessBaseAPI() as api:\n        for img in images:\n            api.SetImageFile(img)\n            print(api.GetUTF8Text())\n            print(api.AllWordConfidences())\n    # api is automatically finalized when used in a with-statement (context manager).\n    # otherwise api.End() should be explicitly called when it's no longer needed.\n\n``PyTessBaseAPI`` exposes several tesseract API methods. Make sure you\nread their docstrings for more info.\n\nBasic example using available helper functions:\n\n.. code:: python\n\n    import tesserocr\n    from PIL import Image\n\n    print(tesserocr.tesseract_version())  # print tesseract-ocr version\n    print(tesserocr.get_languages())  # prints tessdata path and list of available languages\n\n    image = Image.open('sample.jpg')\n    print(tesserocr.image_to_text(image))  # print ocr text from image\n    # or\n    print(tesserocr.file_to_text('sample.jpg'))\n\n``image_to_text`` and ``file_to_text`` can be used with ``threading`` to\nconcurrently process multiple images which is highly efficient.\n\nAdvanced API Examples\n---------------------\n\nGetComponentImages example:\n```````````````````````````\n\n.. code:: python\n\n    from PIL import Image\n    from tesserocr import PyTessBaseAPI, RIL\n\n    image = Image.open('/usr/src/tesseract/testing/phototest.tif')\n    with PyTessBaseAPI() as api:\n        api.SetImage(image)\n        boxes = api.GetComponentImages(RIL.TEXTLINE, True)\n        print('Found {} textline image components.'.format(len(boxes)))\n        for i, (im, box, _, _) in enumerate(boxes):\n            # im is a PIL image object\n            # box is a dict with x, y, w and h keys\n            api.SetRectangle(box['x'], box['y'], box['w'], box['h'])\n            ocrResult = api.GetUTF8Text()\n            conf = api.MeanTextConf()\n            print(u\"Box[{0}]: x={x}, y={y}, w={w}, h={h}, \"\n                  \"confidence: {1}, text: {2}\".format(i, conf, ocrResult, **box))\n\nOrientation and script detection (OSD):\n```````````````````````````````````````\n\n.. code:: python\n\n    from PIL import Image\n    from tesserocr import PyTessBaseAPI, PSM\n\n    with PyTessBaseAPI(psm=PSM.AUTO_OSD) as api:\n        image = Image.open(\"/usr/src/tesseract/testing/eurotext.tif\")\n        api.SetImage(image)\n        api.Recognize()\n\n        it = api.AnalyseLayout()\n        orientation, direction, order, deskew_angle = it.Orientation()\n        print(\"Orientation: {:d}\".format(orientation))\n        print(\"WritingDirection: {:d}\".format(direction))\n        print(\"TextlineOrder: {:d}\".format(order))\n        print(\"Deskew angle: {:.4f}\".format(deskew_angle))\n\nor more simply with ``OSD_ONLY`` page segmentation mode:\n\n.. code:: python\n\n    from tesserocr import PyTessBaseAPI, PSM\n\n    with PyTessBaseAPI(psm=PSM.OSD_ONLY) as api:\n        api.SetImageFile(\"/usr/src/tesseract/testing/eurotext.tif\")\n\n        os = api.DetectOS()\n        print(\"Orientation: {orientation}\\nOrientation confidence: {oconfidence}\\n\"\n              \"Script: {script}\\nScript confidence: {sconfidence}\".format(**os))\n\nmore human-readable info with tesseract 4+ (demonstrates LSTM engine usage):\n\n.. code:: python\n\n    from tesserocr import PyTessBaseAPI, PSM, OEM\n\n    with PyTessBaseAPI(psm=PSM.OSD_ONLY, oem=OEM.LSTM_ONLY) as api:\n        api.SetImageFile(\"/usr/src/tesseract/testing/eurotext.tif\")\n\n        os = api.DetectOrientationScript()\n        print(\"Orientation: {orient_deg}\\nOrientation confidence: {orient_conf}\\n\"\n              \"Script: {script_name}\\nScript confidence: {script_conf}\".format(**os))\n\nIterator over the classifier choices for a single symbol:\n`````````````````````````````````````````````````````````\n\n.. code:: python\n\n    from __future__ import print_function\n\n    from tesserocr import PyTessBaseAPI, RIL, iterate_level\n\n    with PyTessBaseAPI() as api:\n        api.SetImageFile('/usr/src/tesseract/testing/phototest.tif')\n        api.SetVariable(\"save_blob_choices\", \"T\")\n        api.SetRectangle(37, 228, 548, 31)\n        api.Recognize()\n\n        ri = api.GetIterator()\n        level = RIL.SYMBOL\n        for r in iterate_level(ri, level):\n            symbol = r.GetUTF8Text(level)  # r == ri\n            conf = r.Confidence(level)\n            if symbol:\n                print(u'symbol {}, conf: {}'.format(symbol, conf), end='')\n            indent = False\n            ci = r.GetChoiceIterator()\n            for c in ci:\n                if indent:\n                    print('\\t\\t ', end='')\n                print('\\t- ', end='')\n                choice = c.GetUTF8Text()  # c == ci\n                print(u'{} conf: {}'.format(choice, c.Confidence()))\n                indent = True\n            print('---------------------------------------------')\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirfz%2Ftesserocr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirfz%2Ftesserocr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirfz%2Ftesserocr/lists"}