Reading Characters
Sorry, this code snippet is currently not available in ActiveX / Visual Basic.
Reading using TrueType fonts
////////////////////////////////////////////////////////
// This code snippet shows how to //
// - create a character database from TrueType fonts //
// - read the text in an image //
////////////////////////////////////////////////////////
// Load an image EImageBW8 image; image.Load("image.tif");
// Attach an ROI
EROIBW8 roi;
roi.Attach(&src, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2;
// 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 TrueType character to the character database ocr2.AddCharactersToDatabase("C:\\Windows\\Fonts\\calibrib.ttf"); ocr2.AddCharactersToDatabase("C:\\Windows\\Fonts\\yugothb.ttc");
// Read text from the image std::string result = ocr2.Read(roi);
////////////////////////////////////////////////////////
// This code snippet shows how to //
// - create a character database from TrueType fonts //
// - read the text in an image //
////////////////////////////////////////////////////////
// Load an image EImageBW8 image = new EImageBW8(); image.Load("image.tif");
// Attach an ROI
EROIBW8 roi = new EROIBW8();
roi.Attach(src, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2 = new EOCR2();
// 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 TrueType character to the character database ocr2.AddCharactersToDatabase("C:\\Windows\\Fonts\\calibrib.ttf"); ocr2.AddCharactersToDatabase("C:\\Windows\\Fonts\\yugothb.ttc");
// Read text from the image
string result = ocr2.Read(roi);
// Cleanup ocr2.CharsWidthRange.Dispose(); ocr2.Dispose(); roi.Dispose(); image.Dispose();
The image used in this code snippet
Reading using EOCR2 Character Database
////////////////////////////////////////////////////////
// This code snippet shows how to //
// - load a pre-made character database //
// - read the text in an image //
////////////////////////////////////////////////////////
// Load an image EImageBW8 image; image.Load("image.tif");
// Attach an ROI
EROIBW8 roi;
roi.Attach(&src, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2;
// 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
std::string result = ocr2.Read(roi);
////////////////////////////////////////////////////////
// This code snippet shows how to //
// - load a pre-made character database //
// - read the text in an image //
////////////////////////////////////////////////////////
// Load an image EImageBW8 image = new EImageBW8(); image.Load("image.tif");
// Attach an ROI
EROIBW8 roi = new EROIBW8();
roi.Attach(src, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2 = new EOCR2();
// 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
string result = ocr2.Read(roi);
// Cleanup ocr2.CharsWidthRange.Dispose(); ocr2.Dispose(); roi.Dispose(); image.Dispose();
Reading using EOCR2 Model file
////////////////////////////////////////////////////////
// This code snippet shows how to //
// - load a pre-made model file //
// - read the text in an image //
////////////////////////////////////////////////////////
// Load an image EImageBW8 image; image.Load("image.tif");
// Attach an ROI
EROIBW8 roi;
roi.Attach(&src, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2;
// Load a pre-made model file, this will: // - (re)set all parameters // - add the character database in the model file to the EOCR2 instance ocr2.Load("myModel.o2m");
// Read text from the image
std::string result = ocr2.Read(roi);
////////////////////////////////////////////////////////
// This code snippet shows how to //
// - load a pre-made model file //
// - read the text in an image //
////////////////////////////////////////////////////////
// Load an image EImageBW8 image = new EImageBW8(); image.Load("image.tif");
// Attach an ROI
EROIBW8 roi = new EROIBW8();
roi.Attach(src, 50, 224, 340, 96);
// Create an EOCR2 instance
EOCR2 ocr2 = new EOCR2();
// Load a pre-made model file, this will: // - (re)set all parameters // - add the character database in the model file to the EOCR2 instance ocr2.Load("myModel.o2m");
// Read text from the image
string result = ocr2.Read(roi);
// Cleanup ocr2.Dispose(); roi.Dispose(); image.Dispose();