0

I'm working on a research project which requires me to identify text within an image. Over the forum I saw a post of using memcmp, but I'm having no luck with this.

To give more details on my task :

I screen capture this. My image reads "GPS: Initial Location 34 45 23".

I then dip into a predefined map of images that I load at the start of my application.The map contains images for text - Initial, Reset, Launch, ....

How do I check if the image I captured matches to one of the predefined images in the map.

Kindly help.

Attaching a snapshot of code

public static bool CompareMemCmp(Bitmap b1, Bitmap b2)
{
  if ((b1 == null) != (b2 == null)) return false;

  var bd1 = b1.LockBits(new Rectangle(new Point(0, 0), b1.Size), ImageLockMode.ReadOnly, b1.PixelFormat);
  var bd2 = b2.LockBits(new Rectangle(new Point(0, 0), b2.Size), ImageLockMode.ReadOnly, b2.PixelFormat);

  try
  {
    IntPtr bd1scan0 = bd1.Scan0;
    IntPtr bd2scan0 = bd2.Scan0;

    int stride = bd1.Stride;
    int len = stride * b1.Height;

    int stride2 = bd2.Stride;
    int len2 = stride2 * b2.Height;

    for (int i = 0; i < len; ++i)
    {
      bd1scan0 = bd1.Scan0 + i;

      int test = memcmp(bd1scan0, bd2scan0, len2);
      if (test == 0)
      {
        Console.WriteLine("Found the string");
        return true;
      }
    }

    return false;
  }
  finally
  {
    b1.UnlockBits(bd1);
    b2.UnlockBits(bd2);
  }
}
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443

1 Answers1

0

If you are looking for an exact match, i.e. a match where every bit is the same, you could use this approach. However, if this is not the case, other algorithms might be better. One example would be to use cross correlation. I used it to compare audio files and it works great. See this question

Community
  • 1
  • 1
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • My first task is to appropriately tag the captured image. I should be able to identify if it is 'Initial' message, 'Reset' message, or 'Launch' message. Once I'm able to identify the right class of message, I then need to read the coordinates – Chili Manku Aug 18 '11 at 13:55
  • This comment doesn't answer my question. It's not clear whether you need bitwise equality of the "Initial" part in your image with the predefined image or if you need a similarity like in real OCR. – Daniel Hilgarth Aug 18 '11 at 13:59
  • Daniel, appreciate your follow up. I would like to have something similar to OCR. Attaching a snapshot of code in my original post. – Chili Manku Aug 18 '11 at 14:16