Anchor script producing protected memory error

Discussions about forms processing support.
Post Reply
blewis
Posts: 31
Joined: Wed May 18, 2011 4:28 am

Anchor script producing protected memory error

Post by blewis » Tue May 24, 2011 10:07 pm

I am still doing an evaluation, so perhaps I just have the code wrong, but I wanted to use the anchor functionality to help improve my OMR. I took a look at some of the samples, but I am still not sure if I am right and I am getting an "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." error.

Here is my code snippet

Code: Select all

            Dim templateImageID As Integer
            Dim anchorTemplateID As Integer

            Dim anchor_left As Integer = 0
            Dim anchor_top As Integer = 0
            Dim anchor_width As Integer = 0
            Dim anchor_height As Integer = 0
            Dim accuracy As Double = 0
            Dim Mode As GdPicture.OMRMode = GdPicture.OMRMode.FavorSpeed

            templateImageID = oGdPictureImaging.CreateGdPictureImageFromFile("d:\mypath\answer_sheet_template.png")
            anchorTemplateID = oGdPictureImaging.CreateAnchorTemplate(templateImageID, 101, 101, 65, 71)

            Dim anchorStatus As Integer = oGdPictureImaging.FindAnchor(scanImageID, templateImageID, Mode, 0, 0, 700, 700, anchor_left, anchor_top, anchor_width, anchor_height, accuracy)
As soon as I get to the last line of this snippet (FindAnchor), I get the error. "scanImageID" is set higher up in the script and it is working. Here is the trace:

Code: Select all

[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
   al.GDPICTUREOMR_Anchor(IntPtr A_0, IntPtr A_1, Int32 A_2, Int32 A_3, Int32 A_4, Int32 A_5, Int32 A_6, Int32 A_7, Int32 A_8, Int32 A_9, Int32& A_10, Int32& A_11, Int32& A_12, Int32& A_13, Double& A_14, Int32 A_15) +0
   GdPicture.GdPictureImaging.FindAnchor(Int32 ImageID, Int32 AnchorTemplateID, OMRMode Mode, Int32 SearchLeft, Int32 SearchTop, Int32 SearchWidth, Int32 SearchHeight, Int32& PosLeft, Int32& PosTop, Int32& PosWidth, Int32& PosHeight, Double& Accuracy) +249
   score.Page_Load(Object s, EventArgs e) +531
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
To be honest, I am not even sure if I am using this functionality correct. I have the OMRDetectMarks method working just fine, but I wanted to take into account if scans had been upside-down in the scanner, etc. I figured this would help. Is the idea that you set the template, then search different regions of the image to test if that anchor is there? If it's found, do I have to do any transformations (e.g. flips) myself if I find the anchor in the upside-down position?

Thanks in advance,
Bryan

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

Re: Anchor script producing protected memory error

Post by Loïc » Wed May 25, 2011 11:00 am

Hi Bryan,

Is it possible to get the answer_sheet_template.png file for investigation ?

If the problem come from the OMR lib, we will fix it in priority.


Kind regards,

Loïc

EDIT: Your snippet appears good to me.

blewis
Posts: 31
Joined: Wed May 18, 2011 4:28 am

Re: Anchor script producing protected memory error

Post by blewis » Wed May 25, 2011 4:57 pm

I have attached the template image. It's just a simple bubble sheet I designed for testing (I'm evaluating gdPicture with the hope of getting the Ultimate Ed. if it works out). I am using the four box pattern in the upper left as the anchor.

Thanks!
Bryan
Attachments
answer_sheet_template.png

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

Re: Anchor script producing protected memory error

Post by Loïc » Wed May 25, 2011 5:15 pm

Hi again,

In fact your snippet was wrong. You were not using good parameters.
Here a fixed version:

Code: Select all

      Dim templateImageID As Integer
      Dim anchorTemplateID As Integer
      Dim anchor_left As Integer = 0
      Dim anchor_top As Integer = 0
      Dim anchor_width As Integer = 0
      Dim anchor_height As Integer = 0
      Dim accuracy As Double = 0
      Dim Mode As GdPicture.OMRMode = GdPicture.OMRMode.FavorSpeed

      templateImageID = Imaging1.CreateGdPictureImageFromFile("D:\GdPicture\Testing\Images\OMR\answer_sheet_template.png")
      If templateImageID <> 0 Then
         anchorTemplateID = Imaging1.CreateAnchorTemplate(templateImageID, 101, 101, 65, 71)
         If anchorTemplateID <> 0 Then
            If Imaging1.FindAnchor(templateImageID, anchorTemplateID, Mode, 0, 0, 700, 700, anchor_left, anchor_top, anchor_width, anchor_height, accuracy) = GdPictureStatus.OK Then
               MsgBox("Accuracy: " & accuracy.ToString)
            Else
               MsgBox("Error during template matching process")
            End If
         Else
            MsgBox("Can't create anchor template !")
         End If
      Else
         MsgBox("Can't open file")
      End If

Let me know if you encounter any other problem, any other special questions or feedback. We want put lot of efforts on the OMR engine.

Kind regards,

Loïc

blewis
Posts: 31
Joined: Wed May 18, 2011 4:28 am

Re: Anchor script producing protected memory error

Post by blewis » Wed May 25, 2011 5:35 pm

Loic,

Thanks for the quick reply. This code is working now (no errors) and I am able to print out an accuracy score. Forgive me if I am missing something, but I would appreciate a bit more detail about how to leverage this function (now that it's working!!). The reference documentation does a great job of telling me all about the methods, but lacks a bit of the bigger picture info. Now that I have imported the template and run FindAnchor I have an accuracy, in my case 44.5. Does this mean the system is 44.5% confident the anchor is within the bounds I set in the FindAnchor call? I assume that if any transformations need to be done, that I must do them myself (i.e. the anchor system does nothing automatically)? So I I use FindAnchor and discover that my anchor image is in fact in the lower right instead of the upper left, then it's my job to rotate the image 180 deg?

Thanks,
Bryan
Bryan Lewis
gdPicture 10.2.5 Ultimate

blewis
Posts: 31
Joined: Wed May 18, 2011 4:28 am

Re: Anchor script producing protected memory error

Post by blewis » Wed May 25, 2011 5:46 pm

As another followup, I am still a bit stumped. No matter what image I send through, I get the same accuracy of 44.5. I have tried the a regular scan sheet in the proper orientation, one that is upside down and also a completely blank page and it's all the same return value.
Bryan Lewis
gdPicture 10.2.5 Ultimate

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

Re: Anchor script producing protected memory error

Post by Loïc » Wed May 25, 2011 6:18 pm

Hi,

I discovered a deep bug that appears on certain rare case. Your image has a palette of 256 entries, and only the first two are used for black & white color...

This has already be fixed on our current GdPicture8 release. We will publish a beta within 7 days if you are interested: viewtopic.php?t=3087

Currently, a workaround with the V7 is to convert to image to 24 bpp calling the ConvertTo24bpp method before applying template matching:

Replace this part:

Code: Select all

If Imaging1.FindAnchor(templateImageID, anchorTemplateID, Mode, 0, 0, 700, 700, anchor_left, anchor_top, anchor_width, anchor_height, accuracy) = GdPictureStatus.OK Then
by:

Code: Select all

Imaging1.ConvertTo24Bpp(templateImageID)
If Imaging1.FindAnchor(templateImageID, anchorTemplateID, Mode, 0, 0, 700, 700, anchor_left, anchor_top, anchor_width, anchor_height, accuracy) = GdPictureStatus.OK Then
Because you are matching the anchor on the original image, you can expect 100% of level accuracy.
By our experience, accuracy returned by the engine should be in the range [80-100] to consider the result as relevant.

Hope this helps !

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest