Games are fun and of course auctions in games are funniest
Now my little experience in fast buying.
What is OCR?
Optical Character Recognition or how to teach the computer to read.
Let first said that "computer" will read only digits 0..9 decimal notation. The digits (in my case) are equal sized and with equal spacing (gap between symbols).
Patterns
Digit : width= 5 x height= 7
gap : width= 1 x height= 7
coma: width= 1 x height= 7
Due to all digits equal I made small bitmaps with all 10 digits 0..9.
AHKv2.0Code: Select all
ocrBWConvert(ByRef bmp, color, varia:=0) ;convert bmp pattern to Black / White pattern
{ Gdip_GetImageDimensions(bmp, w, h)
Loop h
{ y:=A_Index-1
Loop w
{ x:= A_Index-1
Gdip_SetPixel(bmp, x, y, PixelCompare(Gdip_GetPixel(bmp, x, y), color, varia)? 0xFFFFFFFF: 0xFF000000)
} }
return bmp
} ;===============================================
The code convert bmp pattern to black foreground with white symbol in next order:
1.Get pixel from bitmap
2.Compare pixel to given color with given variation
3.If pixel match pixel is set to white
4.Else pixel is set to black
AHKv2.0Code: Select all
PixelCompare(ARGB1, ARGB2, varia:=0) ;compare ARGB1 to ARGB2 with variation (0..255)
{ Gdip_FromARGB(ARGB1, A1, R1, G1, B1)
Gdip_FromARGB(ARGB2, A2, R2, G2, B2)
return (abs(R1-R2) <= varia) && (abs(G1-G2) <= varia) && (abs(B1-B2) <= varia)
} ;===============================================
A color attribute is ignored. 0= strong equal. 255= any match.
Now I have 0.bmp .. 9.bmp patters and ready to read and compare.
Code: Select all
;try to recognize recBmp pattern compare to 0..9 given patterns
ocrGetDigit(recBmp, color, varia)
{ static digBmp:= object(0,"", 1,"", 2,"", 3,"", 4,"", 5,"", 6,"", 7,"", 8,"", 9,"")
static digIni ;static init bmps from file not work
if !digIni ;load bmps once till script exit
{ Loop 10
digBmp[A_Index-1]:= Gdip_CreateBitmapFromFile(A_ScriptDir "\ocr\" A_Index-1 ".bmp")
digIni:=1
}
Loop 10
if ocrBWCompare(recBmp, digBmp[A_Index-1], color, varia), return A_Index-1
return "" ;fail
} ;===============================================
function return 0..9 or "" if nothing is recognized.
If we search white digit: ocrGetDigit(bmpFromScreen, 0xFFFFFF, 50) ;50 is good variation
If we search red digit: ocrGetDigit(bmpFromScreen, 0xFF0000, 50)
If we search blue digit: ocrGetDigit(bmpFromScreen, 0x0000FF, 50)
And comparison - it is complicated but idea is the same like conversion If color match WHITE else BLACK.
AHKv2.0Code: Select all
ocrBWCompare(recog, given, color, varia:=0) ;compare bmp patterns reduce collors to Black / White
{ Gdip_GetImageDimensions(given, w, h)
Loop h
{ y:= A_Index-1
Loop w
{ x:= A_Index-1
if (Gdip_GetPixel(given, x, y) & 0xFFFFFF) != (PixelCompare(Gdip_GetPixel(recog, x, y), color, varia)? 0xFFFFFF: 0x000000)
return 0 ;fail
} }
return 1 ;success
} ;===============================================
At the end as the pattern is BLACK/WHITE and if color match/not match it is like comparing binary patterns (1=WHITE/0=BLACK) and in the same time quiet clean to be seen.
Further I will post how to concatenate recognized digits to value.