All Projects → thiagoalessio → Tesseract Ocr For Php

thiagoalessio / Tesseract Ocr For Php

Licence: mit
A wrapper to work with Tesseract OCR inside PHP.

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to Tesseract Ocr For Php

ocr
Simple app to extract text from pictures using Tesseract
Stars: ✭ 98 (-95.64%)
Mutual labels:  ocr, tesseract, text-recognition
React Native Tesseract Ocr
Tesseract OCR wrapper for React Native
Stars: ✭ 384 (-82.91%)
Mutual labels:  ocr, tesseract, text-recognition
Node Tesseract Ocr
A Node.js wrapper for the Tesseract OCR API
Stars: ✭ 92 (-95.91%)
Mutual labels:  ocr, tesseract, text-recognition
Adelaidet
AdelaiDet is an open source toolbox for multiple instance-level detection and recognition tasks.
Stars: ✭ 2,565 (+14.15%)
Mutual labels:  ocr, text-recognition
Text recognition toolbox
text_recognition_toolbox: The reimplementation of a series of classical scene text recognition papers with Pytorch in a uniform way.
Stars: ✭ 114 (-94.93%)
Mutual labels:  ocr, text-recognition
Swiftytesseract
A Swift wrapper around Tesseract for use in iOS, macOS, and Linux applications
Stars: ✭ 170 (-92.43%)
Mutual labels:  ocr, tesseract
Tesseract
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.
Stars: ✭ 43,199 (+1822.52%)
Mutual labels:  ocr, tesseract
Tesseract Macos
Objective C wrapper for the open source OCR Engine Tesseract (macOS)
Stars: ✭ 154 (-93.15%)
Mutual labels:  ocr, tesseract
Sightseq
Computer vision tools for fairseq, containing PyTorch implementation of text recognition and object detection
Stars: ✭ 116 (-94.84%)
Mutual labels:  ocr, text-recognition
Unilm
Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities
Stars: ✭ 4,082 (+81.66%)
Mutual labels:  ocr, text-recognition
Crnn.pytorch
crnn实现水平和垂直方向中文文字识别, 提供在3w多个中文字符训练的水平识别和垂直识别的预训练模型; 欢迎关注,试用和反馈问题... ...
Stars: ✭ 145 (-93.55%)
Mutual labels:  ocr, text-recognition
Aadhaar Card Ocr
Extract text information from Aadhaar Card using tesseract-ocr 😎
Stars: ✭ 112 (-95.02%)
Mutual labels:  ocr, tesseract
Tabulo
Table Detection and Extraction Using Deep Learning ( It is built in Python, using Luminoth, TensorFlow<2.0 and Sonnet.)
Stars: ✭ 110 (-95.1%)
Mutual labels:  ocr, tesseract
Ocrtable
Recognize tables and text from scanned images that contain tables. 从包含表格的扫描图片中识别表格和文字
Stars: ✭ 155 (-93.1%)
Mutual labels:  ocr, tesseract
Links Detector
📖 👆🏻 Links Detector makes printed links clickable via your smartphone camera. No need to type a link in, just scan and click on it.
Stars: ✭ 106 (-95.28%)
Mutual labels:  ocr, tesseract
Tesseract Ocr for windows
Visual Studio Projects for Tessearct and dependencies
Stars: ✭ 122 (-94.57%)
Mutual labels:  ocr, tesseract
Textrecognitiondatagenerator
A synthetic data generator for text recognition
Stars: ✭ 2,075 (-7.65%)
Mutual labels:  ocr, text-recognition
Scene Text Recognition
Scene text detection and recognition based on Extremal Region(ER)
Stars: ✭ 146 (-93.5%)
Mutual labels:  ocr, text-recognition
Lambda Text Extractor
AWS Lambda functions to extract text from various binary formats.
Stars: ✭ 159 (-92.92%)
Mutual labels:  ocr, tesseract
Tesserocr
A Python wrapper for the tesseract-ocr API
Stars: ✭ 1,567 (-30.26%)
Mutual labels:  ocr, tesseract

Tesseract OCR for PHP

Tesseract OCR for PHP

A wrapper to work with Tesseract OCR inside PHP.

CI AppVeyor Codacy Test Coverage
Latest Stable Version Total Downloads Monthly Downloads
Join the chat

Installation

Via Composer:

$ composer require thiagoalessio/tesseract_ocr

‼️ This library depends on Tesseract OCR, version 3.02 or later.


Note for Windows users

There are many ways to install Tesseract OCR on your system, but if you just want something quick to get up and running, I recommend installing the Capture2Text package with Chocolatey.

choco install capture2text --version 3.9

⚠️ Recent versions of Capture2Text stopped shipping the tesseract binary.


Note for macOS users

With MacPorts you can install support for individual languages, like so:

$ sudo port install tesseract-<langcode>

But that is not possible with Homebrew. It comes only with English support by default, so if you intend to use it for other language, the quickest solution is to install them all:

$ brew install tesseract tesseract-lang

Usage

Basic usage

use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('text.png'))
    ->run();
The quick brown fox
jumps over
the lazy dog.

Other languages

use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('german.png'))
    ->lang('deu')
    ->run();
Bülowstraße

Multiple languages

use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('mixed-languages.png'))
    ->lang('eng', 'jpn', 'spa')
    ->run();
I eat すし y Pollo

Inducing recognition

use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('8055.png'))
    ->allowlist(range('A', 'Z'))
    ->run();
BOSS

Breaking CAPTCHAs

Yes, I know some of you might want to use this library for the noble purpose of breaking CAPTCHAs, so please take a look at this comment:

https://github.com/thiagoalessio/tesseract-ocr-for-php/issues/91#issuecomment-342290510

API

run

Executes a tesseract command, optionally receiving an integer as timeout, in case you experience stalled tesseract processes.

$ocr = new TesseractOCR();
$ocr->run();
$ocr = new TesseractOCR();
$timeout = 500;
$ocr->run($timeout);

image

Define the path of an image to be recognized by tesseract.

$ocr = new TesseractOCR();
$ocr->image('/path/to/image.png');
$ocr->run();

imageData

Set the image to be recognized by tesseract from a string, with its size. This can be useful when dealing with files that are already loaded in memory. You can easily retrieve the image data and size of an image object :

//Using Imagick
$data = $img->getImageBlob();
$size = $img->getImageLength();
//Using GD
ob_start();
// Note that you can use any format supported by tesseract
imagepng($img, null, 0);
$size = ob_get_length();
$data = ob_get_clean();

$ocr = new TesseractOCR();
$ocr->imageData($data, $size);
$ocr->run();

executable

Define a custom location of the tesseract executable, if by any reason it is not present in the $PATH.

echo (new TesseractOCR('img.png'))
    ->executable('/path/to/tesseract')
    ->run();

version

Returns the current version of tesseract.

echo (new TesseractOCR())->version();

availableLanguages

Returns a list of available languages/scripts.

foreach((new TesseractOCR())->availableLanguages() as $lang) echo $lang;

More info: https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc#languages-and-scripts

tessdataDir

Specify a custom location for the tessdata directory.

echo (new TesseractOCR('img.png'))
    ->tessdataDir('/path')
    ->run();

userWords

Specify the location of user words file.

This is a plain text file containing a list of words that you want to be considered as a normal dictionary words by tesseract.

Useful when dealing with contents that contain technical terminology, jargon, etc.

$ cat /path/to/user-words.txt
foo
bar
echo (new TesseractOCR('img.png'))
    ->userWords('/path/to/user-words.txt')
    ->run();

userPatterns

Specify the location of user patterns file.

If the contents you are dealing with have known patterns, this option can help a lot tesseract's recognition accuracy.

$ cat /path/to/user-patterns.txt'
1-\d\d\d-GOOG-441
www.\n\\\*.com
echo (new TesseractOCR('img.png'))
    ->userPatterns('/path/to/user-patterns.txt')
    ->run();

lang

Define one or more languages to be used during the recognition. A complete list of available languages can be found at: https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc#languages

Tip from @daijiale: Use the combination ->lang('chi_sim', 'chi_tra') for proper recognition of Chinese.

 echo (new TesseractOCR('img.png'))
     ->lang('lang1', 'lang2', 'lang3')
     ->run();

psm

Specify the Page Segmentation Method, which instructs tesseract how to interpret the given image.

More info: https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality#page-segmentation-method

echo (new TesseractOCR('img.png'))
    ->psm(6)
    ->run();

oem

Specify the OCR Engine Mode. (see tesseract --help-oem)

echo (new TesseractOCR('img.png'))
    ->oem(2)
    ->run();

dpi

Specify the image DPI. It is useful if your image does not contain this information in its metadata.

echo (new TesseractOCR('img.png'))
    ->dpi(300)
    ->run();

allowlist

This is a shortcut for ->config('tessedit_char_whitelist', 'abcdef....').

echo (new TesseractOCR('img.png'))
    ->allowlist(range('a', 'z'), range(0, 9), '-_@')
    ->run();

configFile

Specify a config file to be used. It can either be the path to your own config file or the name of one of the predefined config files: https://github.com/tesseract-ocr/tesseract/tree/master/tessdata/configs

echo (new TesseractOCR('img.png'))
    ->configFile('hocr')
    ->run();

setOutputFile

Specify an Outputfile to be used. Be aware: If you set an outputfile then the option withoutTempFiles is ignored. Tempfiles are written (and deleted) even if withoutTempFiles = true.

In combination with configFile you are able to get the hocr, tsv or pdf files.

echo (new TesseractOCR('img.png'))
    ->configFile('pdf')
    ->setOutputFile('/PATH_TO_MY_OUTPUTFILE/searchable.pdf');
    ->run();

digits

Shortcut for ->configFile('digits').

echo (new TesseractOCR('img.png'))
    ->digits()
    ->run();

hocr

Shortcut for ->configFile('hocr').

echo (new TesseractOCR('img.png'))
    ->hocr()
    ->run();

pdf

Shortcut for ->configFile('pdf').

echo (new TesseractOCR('img.png'))
    ->pdf()
    ->run();

quiet

Shortcut for ->configFile('quiet').

echo (new TesseractOCR('img.png'))
    ->quiet()
    ->run();

tsv

Shortcut for ->configFile('tsv').

echo (new TesseractOCR('img.png'))
    ->tsv()
    ->run();

txt

Shortcut for ->configFile('txt').

echo (new TesseractOCR('img.png'))
    ->txt()
    ->run();

tempDir

Define a custom directory to store temporary files generated by tesseract. Make sure the directory actually exists and the user running php is allowed to write in there.

echo (new TesseractOCR('img.png'))
    ->tempDir('./my/custom/temp/dir')
    ->run();

withoutTempFiles

Specify that tesseract should output the recognized text without writing to temporary files. The data is gathered from the standard output of tesseract instead.

echo (new TesseractOCR('img.png'))
    ->withoutTempFiles()
    ->run();

Other options

Any configuration option offered by Tesseract can be used like that:

echo (new TesseractOCR('img.png'))
    ->config('config_var', 'value')
    ->config('other_config_var', 'other value')
    ->run();

Or like that:

echo (new TesseractOCR('img.png'))
    ->configVar('value')
    ->otherConfigVar('other value')
    ->run();

More info: https://github.com/tesseract-ocr/tesseract/wiki/ControlParams

Thread-limit

Sometimes, it may be useful to limit the number of threads that tesseract is allowed to use (e.g. in this case). Set the maxmium number of threads as param for the run function:

echo (new TesseractOCR('img.png'))
    ->threadLimit(1)
    ->run();

Where to get help

Join the chat on Gitter.

How to contribute

You can contribute to this project by:

  • Helping new users on Gitter;
  • Opening an Issue if you found a bug or wish to propose a new feature;
  • Placing a Pull Request with code that fix a bug, missing/wrong documentation or implement a new feature;

Just make sure you take a look at our Code of Conduct and Contributing instructions.

License

tesseract-ocr-for-php is released under the MIT License.

Made with love in Berlin

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].