Detailed Usage

Reading a Text

The core class of EasyDeepOCR is the ETextReader .NET Python.

In order to read a text, create a new ETextReader instance and initialize it using ETextReader::Initialize() .NET Python. To read the texts in a loaded image, use ETextReader::Read() .NET Python. This method will return a vector of EasyDeepOCR::EText .NET Python.

Note

When the topology is not specified, the returned EText .NET Python always contains a single ETextLine .NET Python.

Note

The method ETextReader::Initialize .NET Python is designed to pre-allocate memory and to load the necessary resources needed by the ETextReader .NET Python.

  • This initialization can be time-consuming, but it must only be performed once after an instantiation, a loading from memory or a copy from another instance.

  • The duration of the process ranges from a few seconds to several minutes, depending on the execution settings and the computing platform.

See also

Code snippet

Getting a Score

Each ETextLine .NET Python and EText .NET Python returned by the ETextReader .NET Python has a score attached to it.

The score of an ETextLine

The score of an ETextLine .NET Python:

  • Is the arithmetic mean of the detection score and the recognition score.

  • Is in the interval [0.0; 1.0].

  • You can use it to get an approximation of the reading quality of the underlying text.

Use ETextLine::GetScore .NET Python to get the score of an ETextLine.

The score of an EText

The score of an EText .NET Python (that is composed of multiple ETextLine .NET Python):

  • Is the average of all line scores

  • Is in the interval [0.0; 1.0].

  • You can use it to get an approximation of the reading quality of the underlying lines.

Use EText::GetScore .NET Python to get the score of an EText.

See also

Code snippet

Drawing an ETextLine or an EText

See also

Sample program

Specifying a Topology

A topology is a canvas that a given string can satisfy, or not.

Specifying a topology improves the relevance of the outputs of ETextReader .NET Python because only the texts that fit into the canvas are returned. Before applying this filter, the ETextReader .NET Python tries to correct a few small mistakes in order to prevent excessive filtering. In addition, the topology triggers the grouping of lines into texts. In other words, an ETextReader .NET Python returns EText .NET Python composed of several ETextLine .NET Python only when several lines are required by the topology.

In practice, a topology is an instance of the class ETopology .NET Python, which is basically a vector of ETopologyLine .NET Python, with the nth entry referring to the nth text line. As mentioned previously, a topology thus never matches a text whose number of lines is different from the size of the vector ETopologyLine .NET Python.

The canvas mentioned in the first paragraph must be specified inside the class ETopologyLine .NET Python and in particular, by setting its “format string”. This “format string” is a string that can be interpreted using:

  • The eVision simplified format

  • A standard regular expression format.

See also

Code snippet

The eVision Simplified Format

  • Each character from the “format string” represents a “character class”.

  • An ETextLine .NET Python satisfies the ETopologyLine .NET Python if each of its characters belongs to the corresponding “character class” specified by the “format string”.

  • The eVision simplified format is composed of the following eight “character classes”:

    • A: an uppercase ASCII letter: ABCDEFGHIJKLMNOPQRSTUVWXYZ

    • a: a lowercase ASCII letter: abcdefghijklmnopqrstuvwxyz

    • 0: a digit: 0123456789

    • P: an ASCII punctuation character: !"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~

    • V: a character belonging to either A or 0

    • X: a character belonging to either A, a, 0 or P

    • : a space

    • S: a character belonging to either X or a space

“Literal Groups”

  • You can specify a “literal group”, that is a group of characters that should appear verbatim in the ETextLine .NET Python.

    • These “literal groups” must be included inside square brackets []. Note that square brackets themselves must not appear in a literal group.

  • For more flexibility, you can use a “range quantifier” or an “exact quantifier” just after a “character class”:

    • Add a “range quantifier” as {m,n} to specify that the preceding “character class” must be matched between m and n times.

    • Add an “exact quantifier” as {n} to specify that the preceding “character class” must be matched exactly n times.

  • Examples

    • The “format string” [Lot:] 00[-]0{1,3} matches all the following strings:

      • Lot: 12-783

      • Lot: 74-1

      • Lot: 09-447

      • Lot: 85-75

    • The “format string” [Exp:] 00[/]00[/]0{4} matches all the following strings:

      • Exp: 06/07/2024

      • Exp: 01/03/1995

      • Exp: 75/42/0065

      • Exp: 01/22/1569

The Regular Expression Format

Setting the Text Angle

The text angle is an optional parameter of ETextReader .NET Python that controls the reading direction of the texts that are returned.

Text angle

10°

80°

-120°

-35°

Reading direction

Performing an Optimization

You can optimize the ETextReader .NET Python for your own specific use case.

After this optimization:

  • The reader only returns the texts that belong to the same “customer use case” as the one used for the optimization.

  • The processing speed may increase.

  • EasyDeepOCR may find challenging texts that were not detected before the optimization.

This optimization is based on the method ETextReader::Optimize .NET Python that requires an instance of the class ESampleList .NET Python.

Considering that the ESampleList .NET Python is filled, the optimization only requires a few lines of code, as illustrated below.

#include <eVision/EasyOcr/EasyDeepOCR/ETextReader.h>
using namespace eVision;
namespace EDO = eVision::EasyDeepOCR;
// Create an ESample vector
std::vector<EDO::ESample> samples;
// Fill the vector
// ...
// Create an ESampleList instance
EDO::ESampleList sampleList;
// Set the samples
sampleList.SetSamples(samples);
// Create an ETextReader instance
EDO::ETextReader reader;
// Initialize the ETextReader
reader.Initialize();
// Optimize the ETextReader
EDO::EOptimizationReport report = reader.Optimize(sampleList); 
// ...
using eVision;
using EDO = eVision.EasyDeepOCR;
// Create an ESample vector
EDO.ESample[] samples = new EDO.ESample[] { } ;
// Fill the vector
// ...
// Create an ESampleList instance
EDO.ESampleList sampleList = new EDO.ESampleList();
// Set the samples
sampleList.Samples = samples;
// Create an ETextReader instance
EDO.ETextReader reader = new EDO.ETextReader();
// Initialize the ETextReader
reader.Initialize();
// Optimize the ETextReader
EDO.EOptimizationReport report = reader.Optimize(sampleList); 
// ...
import eVision
from eVision import EasyDeepOCR as EDO
# Create an ESample vector
samples = []
# Fill the vector
# ...
# Create an ESampleList instance
sampleList = EDO.ESampleList()
# Set the samples
sampleList.Samples = samples
# Create an ETextReader instance
reader = EDO.ETextReader()
# Initialize the ETextReader
reader.Initialize()
# Optimize the ETextReader
report = reader.Optimize(sampleList); 
# ...

Splitting the Pipeline

Hint

While the function ETextReader::Read .NET Python is suitable for straightforward OCR tasks, the split pipeline becomes beneficial when you require a custom processing for a specific use case.

See also

Code snippet

Using ETextReader::Localize

The method ETextReader::Localize .NET Python identifies regions in an image that contain text lines and returns them as rectangles.

  • This method is appropriate for identifying the locations of text lines in an image without reading their contents.

  • This approach is particularly useful in scenarios where certain regions might need filtering based on size, position or other geometric properties before proceeding with the recognition.

  • It also serves as an excellent first step when building a custom OCR pipeline that requires specialized handling of different text regions.

Using ETextReader::Recognize

The method ETextReader::Recognize .NET Python accepts an ERegion .NET Python or an ERectangle .NET Python as input and outputs a ETextLine .NET Python.

  • It can work with either a miniature image containing only text or a region within a larger image.

  • This method is particularly valuable when working with images that contain text in specific areas requiring different processing parameters, such as different topology constraints.

Using ETextReader::Merge

The method ETextReader::Merge .NET Python combines recognized multiple ETextLine .NET Python into structured objects EText .NET Python based on the defined ETopology .NET Python.

  • This method becomes valuable when working with images where the relationship between the text lines carries a semantic meaning.

  • By organizing the text according to the topology, the method ETextReader::Merge .NET Python preserves the logical relationships between the different text elements.