image2data

Der Tech-Blog

...weitermachen, wo OCR aufhört

Bitmapobjekte finden (sample_8.i2dspt)

Dez 012014
// *****************************************************
// * sample_8.i2dspt                                   *
// *                                                   *
// * - Retrieving the objects 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;
 
  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, 2, 2, 4, 11, 5, 5, 5, 5, 3, aOCRObjects);
 
    // And show it
    i2dForceTCBitmap(oPage);
 
    oPage.Canvas.Brush.Style := bsClear;
    oPage.Canvas.Pen.Width := 2;
    oPage.Canvas.Pen.Color := clGreen;
 
    for i := 0 to Length(aOCRObjects) - 1 do
      oPage.Canvas.Rectangle(aOCRObjects[i].Left, aOCRObjects[i].Top, aOCRObjects[i].Left + aOCRObjects[i].Width, aOCRObjects[i].Top + aOCRObjects[i].Height);
 
    i2dShowInBitmapViewerB(oPage);
  finally
    // Destroy the bitmap object and release memory
    oPage.Free;
  end;
end.

Atom

powered by Nibbleblog