SRL Archive - OSR Help

OCR with a custom font


honeyhoney

2013-05-14 09:33:11

Used to be pretty good at this OCR stuff when it came to using the fonts that come with Simba but now I need/want to use a font that doesn't come with it.

I've created the bitmaps for the font (A-Z, capitals only, no spaces/symbols - numbered 65 to 90).

I've messed around with all the different values and can't seem to get this working;


LoadFont('CustomFont', False); //not too sure if this is even necessary as the font is found in Simba\Fonts\
GetTextAtExWrap(119, 95, 214, 190, 0, 0, 0, 0, 0, 'CustomFont');

I've defined the area closely round the text (often returns nothing). I've also encompassed multiple lines of text in which case it returns a jumble mess of characters (often some characters that aren't even present!). And finally I've tried to check for individual letters on their own.

This has lead me to believe that I've messed up somewhere when creating the bitmaps for the font.
Here's the A, B, and C bitmaps: (they got converted to .jpg by tinypic, here's a rar file including the bitmaps I've made: http://up.ht/16wZzlZ)
Here's what they look like when typed out: Here's a link to the font: http://www.fontspace.com/jackster-productions/pokemon-gb

Any help is appreciated.

honeyhoney

2013-05-15 11:20:06

Update:

After some more messing about today, I ommitted the LoadFont line and managed to get it working quite accurately.
GetTextAtExWrap(xs, ys, xe, ye, 0, 3, 0, colour, 0, 'CustomFont'); seems to work well.

I'd still appreciate it if someone went over the bitmaps I've created to make sure they're all done properly.

honeyhoney

2013-05-15 11:58:37

Update:

Pretty much got capitals sorted out.

[3346237] - DEBUG: Text: t h e Ru il ck broW n foz ti uPFs ov er t h e l
[3346237] - DEBUG: Text: THE QUICK BROWN FOX JUMPS OVER THE
[3346252] - DEBUG: Text: tHe Qu ICk bRoWN FOz JUPPs oVEr tHE Lsn
[3346252] - DEBUG: Text: zzzzzzz

Struggling with lowercase letters now though. Tempted to treat uppercase and lowercase as different fonts but that's obviously not ideal - not to mention I know lowercase alone isn't perfect as it seems to mix xxx up with zzz etc.
Really wasn't sure what to do with the bitmap dimensions - obviously letters like gjpqy go "below the line" so they have a bigger canvas size, though i wasn't sure if I was suppose to make canvas size uniform or not. Similar issue for mwx which are longer horizontally than other letters.

Again, any help would be nice. Let me know if you want to see the lowercase bitmaps and I'll upload them.

Janilabo

2013-05-19 08:43:37

Ello @honeyhoney,

Have you tried this trick below…
1. Download the fonts (http://www.fontspace.com/jackster-productions/pokemon-gb)
2. Extract those fonts from that .zip..
3. Copy em to C:\Windows\Fonts folder (it will install em)
4. Now you could us LoadSystemFont for Pokemon fonts.. This way, you don't need to play around with spacing and such (which is the problem you are wrestling with right now, I think)

Small example code:
var
Font: TFont;
bmp, width, height: Integer;

begin
Font := TFont.Create;
Font.Name := 'Pokemon GB';
Font.Size := 11;
Font.Style := [];
LoadSystemFont(Font,'test');
bmp := BitmapFromText('POKEMON', 'test');
GetBitmapSize(bmp, width, height);
DisplayDebugImgWindow(width, height);
DrawBitmapDebugImg(bmp);
Font.free;
end.

Comes up with this:


..and another example:


Pretty sure you could get this working with that trick, you'll just need to play around with it a little bit. :p

honeyhoney

2013-05-19 12:03:14

From: Janilabo
-snip-


Thanks, I'll try LoadSystemFont.

I actually managed to get it working pretty consistently with both uppercase and lowercase, minus the whole x/z confusion - obviously just some sort of bitmap size issue that I couldn't (be bothered :P) to fix.

I'll post my results here. Looks promising.