image2data

Der Tech-Blog

...weitermachen, wo OCR aufhört

Strukturerkennung einer Seite (sample_7.i2dspt)

Dez 012014
// *****************************************************
// * sample_7.i2dspt                                   *
// *                                                   *
// * - Retrieving the structure of an image            *
// * - Showing the result in the i2dBitmapViewer       *
// *                                                   *
// * Press F9 to execute the code or F7/F8 to debug it *
// *                                                   *
// * Be sure that the sample data was installed!       *
// *                                                   *
// * Contact www.norpa.eu for more information         *
// *****************************************************
 
var
  // Declare some variables
  i: Integer;
 
  oPage: TBitmap;
 
  aOCRObjects: Ti2dOCRObjects;
  aOCRZones: Ti2dOCRZones;
 
  rProcessSettings: Ti2dProcessSettings;
 
begin
  // Get the configured process settings. We must know the configured "in"-folder because that's
  // where the sample docs are located in!
  i2dGetProcessSettings(rProcessSettings);
 
  // Create the bitmap object
  oPage := TBitmap.Create;
 
  try
    // Load first page of the image into the bitmap object
    i2dLoadBitmap(rProcessSettings.InPath + 'sample_invoice_1.tif', 1, oPage);
 
    // Deskew the image
    i2dDeskewBitmap(oPage);
 
    // Get the image objects
    i2dGetBitmapObjects(oPage, 3, 3, 4, 11, 5, 5, 5, 5, 3, aOCRObjects);
 
    // Get the image structure
    i2dGetBitmapStructure(oPage, 200, 100, 10, 10, aOCRObjects, aOCRZones);
 
    // And show it
    i2dForceTCBitmap(oPage);
 
    oPage.Canvas.Brush.Color := clGreen;
    oPage.Canvas.Brush.Style := bsBDiagonal;
    oPage.Canvas.Pen.Width := 3;
    oPage.Canvas.Pen.Color := clGreen;
 
    for i := 0 to Length(aOCRZones) - 1 do
      oPage.Canvas.Rectangle(aOCRZones[i].Left, aOCRZones[i].Top, aOCRZones[i].Left + aOCRZones[i].Width, aOCRZones[i].Top + aOCRZones[i].Height);
 
    i2dShowInBitmapViewerB(oPage);
  finally
    // Destroy the bitmap object and release memory
    oPage.Free;
  end;
end.

Atom

powered by Nibbleblog