ImageEn, unit iexHelperFunctions

TIEBitmapHelper.OCR

TIEBitmapHelper.OCR


Declaration

function OCR(Language: TIEOCRLanguages = OCR_English_Language; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault): string; overload;
function OCR(OcrRect: TRect; Language: TIEOCRLanguages = OCR_English_Language; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault): string; overload;
function OCR(const LanguageCode: string; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault): string; overload;
function OCR(OcrRect: TRect; const LanguageCode: string; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault): string; overload;


Description

A shortcut method that creates a TIEVisionOCR object and calls recognize to return all detected text in the image.
You can specify a rect to limit recognition to an area of the image (to speed up processing). Specify Rect(0,0,0,0) to recognize the whole image.
The language can be specified by type or as a language code string (e.g. 'eng').
Optionally you can specify the segmentation mode, path that contains the language file and OCR engine.



Note:
You must add the iexHelperFunctions unit to your uses clause
LanguagePath and Engine cannot be changed after first use (without restarting the application)
You wil require a TrainedData file for the specified language (e.g. "eng.TrainedData"). An exception is raised if it is not found
OCR requires IEVision. You will need to register it before calling the method


Method Behaviour

The following call:

ocrText := ImageEnView1.IEBitmap.OCR( OCR_English_Language, ievOCRAuto );

Is the same as calling:

// create OCR object
mOCR := IEVisionLib.createOCR(PAnsiChar( AnsiString( '' )), PAnsiChar( AnsiString( IEOCRLanguageList[langCode].Code )), ievOCRDefault );

// set page layout
mOCR.setSegmentationMode( ievOCRAuto );

// OCR
r := IEVisionRect( 0, 0, ImageEnView1.IEBitmap.Width, ImageEnView1.IEBitmap.Height );
ocrText := mOCR.recognize( ImageEnView1.IEBitmap.GetIEVisionImage(), r ).c_str();


Demo

Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr


Example

// Detect text in the image
ShowTempHourglass();
r := IERectangleToRect( ImageEnView1.SelectedRect );  // Get selection (if any)
Memo1.Lines.Text := ImageEnView1.IEBitmap.OCR( OCR_English_Language, ievOCRAuto );


See Also

TIEOCRLanguages
LanguageExistsInFolder
IEVisionLanguageCodeToName
IEVisionLanguageNameToCode