I'm using the code below to get the rotation angle or orientation of a scanned document image. However, the issue is some documents scanned upside down are giving a result of ievOCROrientPAGE_UP instead of ievOCROrientPAGE_DOWN.
Here is an example. It seems documents with lots of text are fine. But the more sparse the text it fails.
Attached is an example.
function TEnOCR.GetRotation(ABitmap: TIEBitmap): Integer;
var
AOCR: TIEVisionOCR;
AStr: String;
begin
Result := 0;
try //Seems to crash on a blank page
if not Assigned(ABitmap) and Assigned(FViewer) then ABitmap := FViewer.IEBitmap;
if not Assigned(ABitmap) then exit;
AOCR := GetVisionOCR;
try
AOCR.setSegmentationMode(ievOCRAUTO_OSD); //Must be ievOCRAUTO_OSD
FTextAngle := AOCR.getTextAngle(ABitmap.GetIEVisionImage) * 180 / PI; //From Radians to Degree
AOCR.getOrientation(FOrientation, FWritingDirection, FTextlineOrder, FDeskewAngle);
finally
AOCR := nil;
end;
case FOrientation of
ievOCROrientPAGE_UP: Result := 0;
ievOCROrientPAGE_RIGHT: Result := 90;
ievOCROrientPAGE_DOWN: Result := 180;
ievOCROrientPAGE_LEFT: Result := 270;
end;
except end;
end;
attach/jeffp/2025114123143_Orientation-Down2.tif