OMRDetectMarks

Example requests & Code samples for GdPicture Toolkits.
Post Reply
rromeijn
Posts: 28
Joined: Fri Jun 18, 2010 4:21 pm

OMRDetectMarks

Post by rromeijn » Tue May 14, 2013 11:35 am

Is there a Delphi Example available of how to use the OMRDetectMarks function.
Somehow i am not able to translate the C# sample to a working delphi version.

A Delphi Equivalent of the C# sample application will do fine for me.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: OMRDetectMarks

Post by Loïc » Tue May 14, 2013 5:15 pm

Hello,

So far I have been able to write the following snippet based on this tutorial: http://blog.virtec.org/2008/07/the-myst ... safearray/

The code is a conversion of the vb sample of the reference guide. It is unfortunately don't work but I guess I am close to the goal:

Code: Select all

procedure TForm1.Button8Click(Sender: TObject);
type
  TArrayOfInteger = array of Integer;
var
  GdPictureImaging1: _GdPictureImaging;
  ImageID: integer;
  Areas, Confidence : TArrayOfInteger;
  result: PSafeArray;
  r: Integer;
  i: Integer;
begin
  GdPictureImaging1 := CreateComObject(CLASS_GdPictureImaging) as _GdPictureImaging;
  ImageID :=  GdPictureImaging1.CreateGdPictureImageFromFile('c:\\test.tif');
  if ImageID <> 0 then
  begin
      SetLength(Areas, 8);
      SetLength(Confidence, 2);
      Areas[0] := 997;
      Areas[1] := 242;
      Areas[2] := 38;
      Areas[3] := 33;
      Areas[4] := 762;
      Areas[5] := 271;
      Areas[6] := 53;
      Areas[7] := 42;
      result := GdPictureImaging1.OMRDetectMarks(ImageID, PSafeArray(Areas), 2, 0.5, PSafeArray(Confidence), True);
      for i := 0 to 1 do
      begin
          SafeArrayGetElement(result, i, r);
          //do something with r
          r:=r;
      end;
      GdPictureImaging1.ReleaseGdPictureImage(ImageID);
  end;
end;
Hope this brings some lights...

Kind regards,

Loïc

rromeijn
Posts: 28
Joined: Fri Jun 18, 2010 4:21 pm

Re: OMRDetectMarks

Post by rromeijn » Wed May 15, 2013 12:35 pm

This is almost exactly as far as i came.
Meanwhile i have been trying other things, and this is what i came up with (but still doesn't work)

Code: Select all

procedure TForm1.Button8Click(Sender: TObject);
type
  TArrayOfInteger = array of Integer;
var
  GdPictureImaging1: _GdPictureImaging;
  ImageID: integer;
  Areas: TArrayOfInteger;
  psAreas, result: PSafeArray;
  Bounds: array[0..0] of pSafeArrayBound;
  r: Integer;
  i: Integer;
begin
  GdPictureImaging1 := CreateComObject(CLASS_GdPictureImaging) as _GdPictureImaging;
  ImageID :=  GdPictureImaging1.CreateGdPictureImageFromFile('c:\\test.tif');
  if ImageID <> 0 then
  begin
      SetLength(Areas, 8);
      Areas[0] := 997;
      Areas[1] := 242;
      Areas[2] := 38;
      Areas[3] := 33;
      Areas[4] := 762;
      Areas[5] := 271;
      Areas[6] := 53;
      Areas[7] := 42;
      Bounds[0].lLbound:=0;
      Bounds[0].cElements:=8;
      psAreas := SafeArrayCreate(VarInteger, 1, @Bounds);
      psAreas.pvData:=Areas;

      //Just to check if psAreas is filled the correct way
      for i := 0 to 7 do
      begin
          SafeArrayGetElement(result, i, r);
           r:=r; // breakpoint here
      end;

      result := GdPictureImaging1.OMRDetectMarks(ImageID, psAreas, 2);
      for i := 0 to 1 do
      begin
          SafeArrayGetElement(result, i, r);
          //do something with r
          r:=r;
      end;
      GdPictureImaging1.ReleaseGdPictureImage(ImageID);
  end;
end;
when i run this, i get the error:

The specified matrix is not of the expected type.

Does this help you (or anyone else) to come to a working Delphi sample?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest