1

I'm working on a C# OCR program (project for my own learning purposes, nothing commercial-quality) that will recognize Hebrew characters. I plan to do this by separating the glyphs from the images and then applying template matching methods.

Where I'm at

I've got it now so that I can separate individual glyphs out of images. Each glyph is represented with a 2D array of pixels. For instance, the character "bet" looks something like:

..........
.*******..
.......*..
.......*..
.********.
..........

where "." represents an empty space and "*" represents a filled-in pixel.

I'm now to the point where I'm going to apply a template matching algorithm to identify what glyph this 2D array of pixels represents (in this case, it should match the "bet" template).

The issue

I'm having trouble finding a simple explanation of a good template matching algorithm (most of what I find are theses or links to code libraries), and was wondering if someone knew of any I might study.

I'd like to emphasize that I want to do this by hand and not simply use a library. I am willing to study how a library solves the problem, however, if it's not split into fifteen bajillion different pieces. :)

I'd also be willing to hear if there's any better methods for doing what I'm trying to do.

Mac Sigler
  • 189
  • 1
  • 15
  • It looks way too broad of a question... "If you can imagine an entire book that answers your question, you’re asking too much" (http://stackoverflow.com/faq#dontask). – Alexei Levenkov Aug 21 '12 at 21:56
  • @AlexeiLevenkov Perhaps I didn't state it well enough... I'm just asking if people have knowledge of specific algorithms that will help me match an isolated but unclassified glyph to a template. Most answers I see here on SO or Google simply point to giant libraries that are intended as your one-stop OCR solution. – Mac Sigler Aug 21 '12 at 22:01
  • May I ask how you are separating out the glyphs? If you are looking for an alogrithm I always start at Wikipedia. – paparazzo Aug 21 '12 at 22:01
  • @Blam I read in the image in successive vertical lines. If a glyph has been encountered (i.e. "I've seen a filled in pixel") but a new vertical line is read in consisting of pure whitespace, I make that my glyph separator. It's primitive, but it seems to work quite nicely from my testing. That's basically the sort of thing I'm looking for. Primitive and simple, but it works. Stuff on Wikipedia and other sites seem to formalize it to the point where it's hard for newbies to understand what's going on, thus why I'm asking the question to get some clarification/advice. :) – Mac Sigler Aug 21 '12 at 22:07
  • But how does the vertical line scan miss characters on other lines or like a horizontal line on the page? – paparazzo Aug 21 '12 at 22:38
  • @Blam That's a good point, I've only tested with one-line images, so this approach would probably need to be tweaked. But at the moment I'm content with just worrying about one-line Bitmaps. Once I get the template matching down, I can go back and try to fix it for multi-line Bitmaps. – Mac Sigler Aug 23 '12 at 14:22
  • Then after multi-line you have the issue of stray dots, page rotated, vertical lines, horizontal lines, font type, and font scale. Commercial OCR packages have very complex algorithms to isolate a character. They look for down comers and other traits to reduce the number of options to match. Then they have to settle on best match as rarely is there a perfect match. A better approach might be to use an existing commercial product. – paparazzo Aug 23 '12 at 15:15
  • @Blam There is a fixed font type of (at the moment) 30 pt Arial font. This isn't something meant to be used in a real-life situation, but rather a project to learn how OCR algorithms work. Which is why I'm shying away from using libraries. I've edited my original question to better indicate such. – Mac Sigler Aug 23 '12 at 15:54

1 Answers1

0

Generate a number for each template , since it is array of pixels and if you associate each pixel with a number( like 0,2,4,8,16 etc) and empty pixel is 0 and filled pixel is 1.

Then for each glyph also calculate the total and match them.

charvind
  • 154
  • 2
  • 9
  • This was a while ago, but I did end up using something very similar in the end, basically calculating percentages of matched pixels. It's not very perfect at all, but it came reasonably close for my purposes. – Mac Sigler Jun 05 '13 at 15:00