ImageEn, unit iexHelperFunctions |
|
TIEBitmapHelper.OCR_GetOrientation
Declaration
function OCR_GetOrientation(Language: TIEOCRLanguages = OCR_English_Language; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault): Double; overload;
function OCR_GetOrientation(const LanguageCode: string; const LanguagePath: string = ''; Engine: TIEVisionOCREngine = ievOCRDefault): Double; overload;
Description
A shortcut method that creates a
TIEVisionOCR object and calls
getTextAngle and
getOrientation to accurately calculate the text angle of a document.
The language can be specified by
type or as a language code string (e.g. 'eng').
You can call
Rotate with the -1 * result to correctly rotate the image.
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") and the orientation file "osd.TrainedData". An exception is raised if either is not found
◼OCR requires
IEVision. You will need to
register it before calling the method
Method Behaviour
The following call:
deskewAngle := ImageEnView1.IEBitmap.OCR_GetOrientation();
if deskewAngle <> 0 then
ImageEnView1.Proc.Rotate( -deskewAngle, ierFast, clWhite );
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_OSD );
// Calculate Orientation and text angle
mOCR.getTextAngle( ImageEnView1.IEBitmap.GetIEVisionImage() );
mOCR.getOrientation( orientation, writingDirection, textlineOrder, deskewAngle );
// Calculate optimal rotation angle
deskewAngle := -deskewAngle * 180 / PI;
if orientation = ievOCROrientPAGE_RIGHT then
deskewAngle := deskewAngle - 90
else
if orientation = ievOCROrientPAGE_DOWN then
deskewAngle := deskewAngle - 180
else
if orientation = ievOCROrientPAGE_LEFT then
deskewAngle := deskewAngle - 270;
if deskewAngle <> 0 then
ImageEnView1.Proc.Rotate( -deskewAngle, ierFast, clWhite );
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
// Auto-fix the orientation and skew of the image
ShowTempHourglass();
deskewAngle := ImageEnView1.IEBitmap.OCR_GetOrientation();
if deskewAngle <> 0 then
ImageEnView1.Proc.Rotate( -deskewAngle, ierFast, clWhite );
For the following image, the returned value would be -92.94 deg.
See Also
◼TIEOCRLanguages