Download the PHP package yama6a/php-glyph-ocr without Composer

On this page you can find all versions of the php package yama6a/php-glyph-ocr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-glyph-ocr

PHP Glyph OCR

A pure PHP OCR engine for clean rendered text bitmaps, such as the images of Blu-ray and DVD subtitles. It is a port of the nOCR engine from Subtitle Edit by Nikolaj Olsson.

The engine cuts an image into lines and glyphs and compares each glyph with a database of known glyphs. It reads text that a computer drew, in a font that the database knows. It does not read photos, scans or handwriting.

Install

Needs PHP 8.2 or later with ext-zlib. ext-gd is optional and only needed for Image::fromGd().

Usage

Option Default Meaning
inkThreshold 200 Minimum premultiplied red + green + blue of an ink pixel, 1 to 765
spaceWidth null Empty columns that make a space. null uses a third of the typical glyph height of the line
maxWrongPixels 25 Error budget of the loose match passes
fixLatinCase true Picks upper or lower case for letters such as o and O from their height
unknownText '*' Text of a glyph that matches nothing
italicSlant 0.0 Above 0, a glyph that matches nothing is slanted back by this factor and tried again
rightToLeft false Puts the glyphs of each line in right to left order
minLineHeight 12 Minimum line height in pixels until the recognizer has learned the glyph heights
lineContext true Compares each glyph with the other glyphs of its line to pick I or l, o, O or 0, and comma or apostrophe. false keeps the database text, as Subtitle Edit does

Databases and training

GlyphDatabase reads and writes the .nocr files of Subtitle Edit, version 1 and 2. The package ships two databases:

Method Glyphs File size Load time, PHP 8.5 Memory
GlyphDatabase::subtitleFonts() 2,007 254 KB + 477 KB 90 ms 76 MB
GlyphDatabase::latin() 699 477 KB 58 ms 52 MB

tests/fixtures/generator/train.php writes resources/SubtitleFonts.nocr again. The fonts and their licenses are in tests/fixtures/generator/fonts. The database holds line segments measured on rendered glyphs, and no font outlines.

Train a glyph from a sample that a person confirmed. The new glyph goes first, so it wins over older glyphs that match equally well:

Accuracy

The golden images in tests/fixtures are white or yellow subtitles, 20 to 60 pixels, 1 or 2 lines. tests/fixtures/SOURCES.md describes them. One recognizer reads each set in order.

Character accuracy, with the lines read without error in brackets:

Set Fonts subtitleFonts() latin() After training
Blu-ray, smooth RGBA DejaVu Sans, Liberation Sans 98.8% (9 of 11) 93.8% (3 of 11) 99.2% (10 of 11)
PGS palette DejaVu Sans, Liberation Sans 100% (8 of 8) 93.0% (3 of 8) 100% (8 of 8)
DVD, 4 colours, 24 to 30 px DejaVu Sans, Liberation Sans 95.5% (4 of 8) 63.2% (0 of 8) 94.2% (4 of 8)
Italic DejaVu Sans, Liberation Sans 98.0% (3 of 5) 92.1% (1 of 5) 97.0% (2 of 5)
No outline DejaVu Sans, Liberation Sans 98.9% (4 of 5) 79.8% (1 of 5) 96.6% (3 of 5)
Small, 20 to 24 px DejaVu Sans, Liberation Sans 98.1% (3 of 4) 50.0% (0 of 4) 92.3% (1 of 4)
Capital I and lower case l DejaVu Sans, Liberation Sans, Noto Sans, Open Sans 99.4% (15 of 17) 90.2% (3 of 17) 97.9% (10 of 17)
Unseen font Open Sans 96.7% (5 of 8) 84.9% (0 of 8) 96.7% (4 of 8)
All 98.3% (51 of 66) 85.0% (11 of 66) 97.4% (42 of 66)

Speed

Mean time per golden image, one image of 1 or 2 lines, after the database is loaded:

PHP 8.2 PHP 8.5
subtitleFonts() 122 ms 115 ms
latin() 244 ms 247 ms
Load subtitleFonts() 184 ms 90 ms
Load latin() 122 ms 58 ms

A full 1920x1080 frame with the same 2 lines takes about 1 second and 103 MB, so crop the image to the text where you can. A glyph that matches nothing is the slow case, because it runs through every match pass. So the subtitle fonts database is faster on the fonts it knows. Measured on one core of an x86_64 machine, without JIT.

Limits

Exceptions

Every exception implements GlyphOcr\Exceptions\GlyphOcrException: InvalidArgumentException, InvalidImageException for a PNG that does not decode, and InvalidDatabaseException for a .nocr file that does not load.

Attribution

This package is a port of the nOCR engine from Subtitle Edit by Nikolaj Olsson, MIT license, at commit b8da12a. LICENSE keeps both copyright notices.

This package Subtitle Edit file in src/libuilogic/Ocr
Internal/Matcher.php, Glyph.php NOcrDb.cs, NOcrChar.cs
GlyphDatabase.php NOcrDb.cs, NOcrChar.cs (file format)
Internal/Splitter.php, Internal/SplitItem.php NikseBitmapImageSplitter2.cs, ImageSplitterItem2.cs
Internal/Bitmap.php NikseBitmap2.cs
Internal/LinePoints.php NOcrLine.cs
Internal/CaseFixer.php NOcrCaseFixer.cs
Internal/LineHeightTracker.php OcrLineHeightTracker.cs
Trainer.php NOcrChar.cs, NOcrLineGenerator.cs
GlyphSample.php (merge) ExpandedOcrGroup.cs
resources/Latin.nocr Ocr/Latin.nocr at the repository root, unchanged

resources/SubtitleFonts.nocr is trained on renderings of these fonts:

Font License
DejaVu Sans 2.37 Bitstream Vera license with public domain changes
Liberation Sans 2.1.5 SIL Open Font License 1.1
Noto Sans 2.015 SIL Open Font License 1.1

All versions of php-glyph-ocr with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-zlib Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yama6a/php-glyph-ocr contains the following files

Loading the files please wait ...