Convert Figma logo to code with AI

tesseract-ocr logotesseract

Tesseract Open Source OCR Engine (main repository)

60,774
9,348
60,774
424

Top Related Projects

Pure Javascript OCR for more than 100 Languages 📖🎉🖥

Python-based tools for document analysis and OCR

Tesseract Open Source OCR Engine (main repository)

Quick Overview

Tesseract is an open-source optical character recognition (OCR) engine developed by Google. It can recognize and read text in images and scanned documents, supporting over 100 languages. Tesseract is widely used for various OCR tasks and can be integrated into different applications and workflows.

Pros

  • High accuracy in text recognition across multiple languages
  • Actively maintained and regularly updated by Google and the community
  • Supports various image formats and can handle complex layouts
  • Offers both command-line interface and API for integration into other applications

Cons

  • Can be challenging to set up and configure for optimal performance
  • May struggle with handwritten text or highly stylized fonts
  • Processing speed can be slow for large or complex documents
  • Requires pre-processing of images for best results, which may not be ideal for all use cases

Code Examples

  1. Basic text recognition from an image:
import pytesseract
from PIL import Image

image = Image.open('example.png')
text = pytesseract.image_to_string(image)
print(text)
  1. Specifying a language for recognition:
import pytesseract
from PIL import Image

image = Image.open('french_text.png')
text = pytesseract.image_to_string(image, lang='fra')
print(text)
  1. Getting bounding box information for recognized text:
import pytesseract
from PIL import Image

image = Image.open('example.png')
data = pytesseract.image_to_data(image, output_type=pytesseract.Output.DICT)
for i, word in enumerate(data['text']):
    if word.strip():
        x, y, w, h = data['left'][i], data['top'][i], data['width'][i], data['height'][i]
        print(f"Word: {word}, Bounding Box: ({x}, {y}, {w}, {h})")

Getting Started

To get started with Tesseract OCR in Python:

  1. Install Tesseract OCR on your system (varies by OS)
  2. Install the Python wrapper:
    pip install pytesseract
    
  3. Install Pillow for image handling:
    pip install Pillow
    
  4. Use the following code to perform basic OCR:
    import pytesseract
    from PIL import Image
    
    image = Image.open('your_image.png')
    text = pytesseract.image_to_string(image)
    print(text)
    

Note: Make sure to have the Tesseract executable in your system PATH or specify its location using pytesseract.pytesseract.tesseract_cmd = r'path/to/tesseract'.

Competitor Comparisons

Pure Javascript OCR for more than 100 Languages 📖🎉🖥

Pros of Tesseract.js

  • Runs in the browser, making it easy to integrate into web applications
  • No need for server-side processing or installation
  • Supports multiple languages and can be easily customized

Cons of Tesseract.js

  • Generally slower performance compared to the native Tesseract
  • May have lower accuracy for complex documents or low-quality images
  • Limited support for advanced OCR features available in the native version

Code Comparison

Tesseract (C++):

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->Init(NULL, "eng");
api->SetImage(image);
char* outText = api->GetUTF8Text();

Tesseract.js (JavaScript):

const worker = Tesseract.createWorker();
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize(image);

Both examples demonstrate basic OCR functionality, but Tesseract.js uses a more modern, Promise-based API, while the native Tesseract uses a traditional C++ approach. The Tesseract.js version is more suitable for web development, while the native Tesseract is better for desktop or server-side applications requiring higher performance and accuracy.

Python-based tools for document analysis and OCR

Pros of ocropy

  • Designed for document analysis and layout understanding
  • Supports training on specific document types for improved accuracy
  • Includes tools for document cleanup and preprocessing

Cons of ocropy

  • Less actively maintained compared to Tesseract
  • Smaller community and fewer resources available
  • May require more manual configuration for optimal results

Code Comparison

Tesseract (Python):

import pytesseract
from PIL import Image

text = pytesseract.image_to_string(Image.open('image.png'))
print(text)

ocropy (Python):

from ocrolib import psegutils, morph, ocrolib
from PIL import Image

image = ocrolib.read_image_gray('image.png')
binary = ocrolib.binarize_sauvola(image)
segmentation = psegutils.segment(binary)
print(ocrolib.recognize_lines(segmentation))

Both libraries offer OCR capabilities, but their usage and focus differ. Tesseract is more straightforward for basic OCR tasks, while ocropy provides more advanced document analysis features. Tesseract has broader language support and is more actively maintained, making it a popular choice for general OCR applications. ocropy, on the other hand, excels in scenarios requiring detailed document understanding and layout analysis, particularly for specific document types when properly trained.

Tesseract Open Source OCR Engine (main repository)

Pros of UB-Mannheim/tesseract

  • Provides pre-built Windows binaries, making it easier for Windows users to install and use Tesseract
  • Includes additional language data and scripts for improved OCR performance
  • Offers more frequent updates and bug fixes for Windows-specific issues

Cons of UB-Mannheim/tesseract

  • Limited to Windows platform, lacking support for other operating systems
  • May not always be in sync with the latest official Tesseract release
  • Potential for divergence from the main Tesseract project over time

Code Comparison

While both repositories contain the core Tesseract OCR engine, their code structures differ slightly due to their focus. Here's a simplified example of how you might use Tesseract in each case:

tesseract:

import tesserocr
from PIL import Image

print(tesserocr.file_to_text('image.png'))

UB-Mannheim/tesseract:

import pytesseract
from PIL import Image

print(pytesseract.image_to_string(Image.open('image.png')))

The main difference lies in the Python wrapper used (tesserocr vs. pytesseract) and the specific function calls, but the core functionality remains similar.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tesseract OCR

Build status Build status
Coverity Scan Build Status CodeQL OSS-Fuzz
GitHub license Downloads

Table of Contents

About

This package contains an OCR engine - libtesseract and a command line program - tesseract.

Tesseract 4 adds a new neural net (LSTM) based OCR engine which is focused on line recognition, but also still supports the legacy Tesseract OCR engine of Tesseract 3 which works by recognizing character patterns. Compatibility with Tesseract 3 is enabled by using the Legacy OCR Engine mode (--oem 0). It also needs traineddata files which support the legacy engine, for example those from the tessdata repository.

Stefan Weil is the current lead developer. Ray Smith was the lead developer until 2018. The maintainer is Zdenko Podobny. For a list of contributors see AUTHORS and GitHub's log of contributors.

Tesseract has unicode (UTF-8) support, and can recognize more than 100 languages "out of the box".

Tesseract supports various image formats including PNG, JPEG and TIFF.

Tesseract supports various output formats: plain text, hOCR (HTML), PDF, invisible-text-only PDF, TSV, ALTO and PAGE.

You should note that in many cases, in order to get better OCR results, you'll need to improve the quality of the image you are giving Tesseract.

This project does not include a GUI application. If you need one, please see the 3rdParty documentation.

Tesseract can be trained to recognize other languages. See Tesseract Training for more information.

Brief history

Tesseract was originally developed at Hewlett-Packard Laboratories Bristol UK and at Hewlett-Packard Co, Greeley Colorado USA between 1985 and 1994, with some more changes made in 1996 to port to Windows, and some C++izing in 1998. In 2005 Tesseract was open sourced by HP. From 2006 until November 2018 it was developed by Google.

Major version 5 is the current stable version and started with release 5.0.0 on November 30, 2021. Newer minor versions and bugfix versions are available from GitHub.

Latest source code is available from main branch on GitHub. Open issues can be found in issue tracker, and planning documentation.

See Release Notes and Change Log for more details of the releases.

Installing Tesseract

You can either Install Tesseract via pre-built binary package or build it from source.

Before building Tesseract from source, please check that your system has a compiler which is one of the supported compilers.

Running Tesseract

Basic command line usage:

tesseract imagename outputbase [-l lang] [--oem ocrenginemode] [--psm pagesegmode] [configfiles...]

For more information about the various command line options use tesseract --help or man tesseract.

Examples can be found in the documentation.

For developers

Developers can use libtesseract C or C++ API to build their own application. If you need bindings to libtesseract for other programming languages, please see the wrapper section in the AddOns documentation.

Documentation of Tesseract generated from source code by doxygen can be found on tesseract-ocr.github.io.

Support

Before you submit an issue, please review the guidelines for this repository.

For support, first read the documentation, particularly the FAQ to see if your problem is addressed there. If not, search the Tesseract user forum, the Tesseract developer forum and past issues, and if you still can't find what you need, ask for support in the mailing-lists.

Mailing-lists:

Please report an issue only for a bug, not for asking questions.

License

The code in this repository is licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

NOTE: This software depends on other packages that may be licensed under different open source licenses.

Tesseract uses Leptonica library which essentially uses a BSD 2-clause license.

Dependencies

Tesseract uses Leptonica library for opening input images (e.g. not documents like pdf). It is suggested to use leptonica with built-in support for zlib, png and tiff (for multipage tiff).

Latest Version of README

For the latest online version of the README.md see:

https://github.com/tesseract-ocr/tesseract/blob/main/README.md