ImageEn, unit iexHelperFunctions

TIEBitmapHelper.OCR

TIEBitmapHelper.OCR

Declaration

function OCR(Language: TIEOCRLanguages = OCR_English_Language; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault; Prepare: Boolean = False): string; overload;
function OCR(OcrRect: TRect; Language: TIEOCRLanguages = OCR_English_Language; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault; Prepare: Boolean = False): string; overload;
function OCR(const LanguageCode: string; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault; Prepare: Boolean = False): string; overload;
function OCR(OcrRect: TRect; const LanguageCode: string; SegmentationMode: TIEVisionOCRPageSegmentationMode = ievOCRAuto; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault; Prepare: Boolean = False): 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.
If Prepare is True, the image (or rect) is preprocessed with prepareForOCR before recognition: the background is normalized, small text is enlarged, skew is corrected, and the image is binarized and cleaned up. This improves results for photos and poor scans, but is slower and makes little difference for clean scans.


Note:
◼You must add the iexHelperFunctions unit to your uses clause
◼Delphi/C++ 2005 or newer is required to use helper classes
◼LanguagePath and Engine cannot be changed after first use (without restarting the application)
◼You will 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 Behavior

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

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

// Detect text in a photo of a document (preprocess the image first)
Memo1.Lines.Text := ImageEnView1.IEBitmap.OCR( OCR_English_Language, ievOCRAuto, '', ievOCRDefault, True );

See Also

◼prepareForOCR
◼TIEOCRLanguages
◼LanguageExistsInFolder
◼IEVisionLanguageCodeToName
◼IEVisionLanguageNameToCode
◼TIEVisionOCR
◼recognize