Reading Using EOCR2 Character Database¶
This code snippet shows how to:
Load a pre-made character database
Read the text in an image.
C++¶
#include <eVision/EasyOcr/EasyOCR2/EOCR2.h>
using namespace eVision;
// Load an image
EImageBW8 image;
image.Load("image.tif");
// Attach an ROI
EROIBW8 roi;
roi.Attach(&image, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2;
// Enable the topology usage
ocr2.SetEnabledTopology(true);
// Set the required parameters
ocr2.SetCharsWidthRange(EIntegerRange(25, 25));
ocr2.SetCharsHeight(37);
ocr2.SetTopology("[LN]{10}\nN{3} N{4}");
ocr2.SetTextPolarity(EasyOCR2TextPolarity_WhiteOnBlack);
// Add a pre-made character database to the EOCR2 instance
ocr2.AddCharactersToDatabase("myDB.o2d");
// Read text from the image
EOCR2Text result = ocr2.Read2(roi);
C#¶
using eVision;
// Load an image
EImageBW8 image = new EImageBW8();
image.Load("image.tif");
// Attach an ROI
EROIBW8 roi = new EROIBW8();
roi.Attach(image, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2 = new EOCR2();
// Enable the topology usage
ocr2.EnabledTopology = true;
// Set the required parameters
ocr2.CharsWidthRange = new EIntegerRange(25, 25);
ocr2.CharsHeight = 37;
ocr2.Topology = "[LN]{10}\nN{3} N{4}";
ocr2.TextPolarity = EasyOCR2TextPolarity.WhiteOnBlack;
// Add a pre-made character database to the EOCR2 instance
ocr2.AddCharactersToDatabase("myDB.o2d");
// Read text from the image
EOCR2Text result = ocr2.Read2(roi);
Python¶
import eVision
# Load an image
image = eVision.EImageBW8()
image.Load("image.tif")
# Attach an ROI
roi = eVision.EROIBW8()
roi.Attach(image, 50, 224, 340, 96)
# Create an EOCR2 instance
ocr2 = eVision.EOCR2()
# Enable the topology usage
ocr2.EnabledTopology = True;
# Set the required parameters
ocr2.CharsWidthRange = eVision.EIntegerRange(25, 25)
ocr2.CharsHeight = 37
ocr2.Topology = "[LN]{10}\nN{3} N{4}"
ocr2.TextPolarity = eVision.EasyOCR2TextPolarity.WhiteOnBlack
# Add a pre-made character database to the EOCR2 instance
ocr2.AddCharactersToDatabase("myDB.o2d")
# Read text from the image
result = ocr2.Read2(roi)