image2data

Der Tech-Blog

...weitermachen, wo OCR aufhört

Einfache Barcodeerkennung (sample_2.i2dspt)

Dez 012014
// *****************************************************
// * sample_2.i2dspt                                   *
// *                                                   *
// * - Retrieving all barcodes from a page of an image *
// * - Showing the result in a message box             *
// *                                                   *
// * 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;
 
  iBarcodeCount: Integer;
  aBarcodes: Ti2dBarcodes;
 
  sText: String;
  oPage: TBitmap;
 
  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);
 
    // Perform a barcode recognition (obcr) on the bitmap object
    iBarcodeCount := i2dOBCRBitmap(oPage, 0, aBarcodes);
 
    // Iterate over the found barcode elements and build an info text
    for i := 0 to iBarcodeCount - 1 do
      sText := sText + Format('Barcode %d: position: %d/%d - size: %d/%d - type: %s - value: %s'#13#10,
                              [i, aBarcodes[i].Left, aBarcodes[i].Top, aBarcodes[i].Width, aBarcodes[i].Height, 
                               aBarcodes[i].Name, aBarcodes[i].Value]);
 
    // Show the info text
    i2dShowMessage(sText);
  finally
    // Destroy the bitmap object and release memory
    oPage.Free;
  end;
end.

Atom

powered by Nibbleblog