Splitting the Pipeline¶
This code snippet shows how to split the pipeline.
C++¶
#include <eVision/EasyOcr/EasyDeepOCR/ETextReader.h>
using namespace eVision;
namespace EDO = eVision::EasyDeepOCR;
// Create an ETextReader instance
EDO::ETextReader reader;
// Create an ETopology instance (optional)
ETopology topology;
// ...
// Set the topology (optional)
reader.SetTopology(topology);
// Initialize the ETextReader
reader.Initialize();
// Load an image
EImageBW8 image;
image.Load("image.tif");
// Localize the text lines in the image
std::vector<ERectangle> rectangles = reader.Localize(image);
// Recognize the string inside each text line
std::vector<EDO::ETextLine> textLines;
for(const ERectangle& rectangle : rectangles)
textLines.emplace_back(reader.Recognize(image, rectangle));
// Merge the text lines into texts satisfying the topology
if(reader.GetHasTopology())
std::vector<EDO::EText> texts = reader.Merge(textLines);
C#¶
using eVision;
using System.Collections.Generic;
using EDO = eVision.EasyDeepOCR;
// Create an ETextReader instance
EDO.ETextReader reader = new EDO.ETextReader();
// Create an ETopology instance (optional)
ETopology topology = new ETopology();
// ...
// Set the topology (optional)
reader.Topology = topology;
// Initialize the ETextReader
reader.Initialize();
// Read an image
EImageBW8 image = new EImageBW8();
image.Load("image.tif");
// Localize the text lines in the image
ERectangle[] rectangles = reader.Localize(image);
// Recognize the string inside each text line
List<EDO.ETextLine> textLines = new List<EDO.ETextLine>();
foreach(var rectangle in rectangles)
textLines.Add(reader.Recognize(image, rectangle));
// Merge the text lines into texts satisfying the topology
if(reader.HasTopology)
{
EDO.EText[] texts = reader.Merge(textLines.ToArray());
}
Python¶
import eVision
from eVision import EasyDeepOCR as EDO
# Create an ETextReader instance
reader = EDO.ETextReader()
# Create an ETopology instance (optional)
topology = eVision.ETopology()
# ...
# Set the topology (optional)
reader.Topology = topology
# Initialize the ETextReader
reader.Initialize()
# Read an image
image = eVision.EImageBW8()
image.Load("image.tif")
# Localize the text lines in the image
rectangles = reader.Localize(image)
# Recognize the string inside each text line
text_lines = []
for rectangle in rectangles:
text_lines.append(reader.Recognize(image, rectangle))
# Merge the text lines into texts satisfying the topology
if reader.HasTopology: