dumass Posted October 19, 2015 Share Posted October 19, 2015 (edited) This has been a pita for days.... I have tried many different ways in achieving this. I cant get gettextat to work not matter what I try. Anyway here is where I am at. I already have a the digits in black and white bitmaps. I take a screen grab from a location that only includes one digit. Then I change every pixel in the bitmap to black or white depending on its original color. Now my current way to detect the image is compare all the digits 0-9 to the bitmap with similarBitmapsEx which returns a TPA with the non matching pixel coords. Which ever one has the least non matching pixels determines the digit. This method is not very accurate and being off by 1 pixel in any direction makes it completely inaccurate. Any suggestions? My number before the Black and White pixel change lol1.bmp After the pixel change lol.bmp var bmp : TSCARBitmap; Function bmpToBW(bmp : TSCARBitmap; tol : Integer) : TSCARBitmap; Var x,y, whiteColor : Integer; retBmp : TSCARBitmap; Begin whiteColor := 16777215; retBmp := bmp; For y:=0 to retBmp.Height-1 do For x:=0 to retBmp.Width-1 do If getTolerance(retBmp.Pixel[x,y],whiteColor) >= tol then Begin retBmp.Pixel[x,y] := 0; End else Begin retBmp.Pixel[x,y] := whiteColor; End; result := retBmp; End; Function getChar(bmp : TSCARBitmap) : String; Var TPA : TPointArray; bmpChar : TSCARBitmap; c : String; low, i : Integer; Begin low := 125; c := ''; bmpChar := TSCARBitmap.Create(''); For i:= 48 To 58 do Begin bmpChar.LoadFromBMP('C:\Users\Admin\Documents\SCAR Divi\Fonts\'+IntToStr(i)+'.bmp'); SimilarBitmapsEx(bmp, bmpChar, 0, TPA); //writeln(TPAToStr(TPA)); if Length(TPA) < low then Begin low := Length(tpa); c := IntToStr(i); End; End; Writeln(c); Result := c; End; begin //decimal ones 336,45,344,58 //decimal tens 328, 45, 336, 58 //decimal huns 319, 45, 327, 58 bmp := TSCARBitmap.Create(''); bmp := GetClient.CaptureEx(319,45,327,58); bmp := bmpToBW(bmp, 120); getChar(bmp); end. Edited October 19, 2015 by dumass Quote Link to comment Share on other sites More sharing options...
Wanted Posted October 21, 2015 Share Posted October 21, 2015 (edited) Can you show us the more of the original text and talk about its origin? It's very difficult to attempt to help you from the images provided. Edited October 24, 2015 by Wanted Quote Link to comment Share on other sites More sharing options...
dumass Posted October 21, 2015 Author Share Posted October 21, 2015 (edited) Sure. The first image is the I'd Like to be able to read the text which shows my storage space (130/140) and my current coins available (9166) info.bmp With the second image I'd like to read the price of the items that are being sold, below the item for sale. Also Id like to read how many of the item are for sale, top right of the item. I already have a working script that searches for the bitmap of the item I need to buy and then it goes through the process of buying it. But i'd like the script to know if I have enough space and cash before attempting to purchase it. The text in the two images are the same font and size. I get more accurate results with the second image. I'm guessing because the background is always blue, as in the first image the background is partly transparent. Also in the first image the game cycles through day and night phases so the background changes from brighter to darker. The only problem with the second image is the text changes positions, it seems to be centered in the box. So the more decimal places it is the further left the text starts. market.bmp Thanks for your help. Ive tried a few other things to get more accurate results, it has helped some but still gives me wrong readings on certain digits. Anyway here is my new code What I did was search each of the bitmaps for the first white pixel started from top to bottom and then bottom to top. And finds the distance between the two first white points found. Then the second getDistance2 searches the bitmap top: left to right and bottom: right to left and then finds the distance between those two points. I determine which digit it is by adding these four things together and selecting the lowest number. The difference between the number of the white pixels in the screen grab bitmap and the font bitmap. The total number of Points that the pixels dont match. The difference between the distance in the screen grab bitmap and the distance between the font bitmap, with both functions. var bmp : TSCARBitmap; Function bmpToBW(bmp : TSCARBitmap; tol : Integer) : TSCARBitmap; Var x,y, whiteColor : Integer; retBmp : TSCARBitmap; Begin whiteColor := 16777215; retBmp := bmp; For x:=0 to retBmp.Width-1 do For y:=0 to retBmp.Height-1 do If getTolerance(retBmp.Pixel[x,y],whiteColor) >= tol then Begin retBmp.Pixel[x,y] := 0; End else Begin retBmp.Pixel[x,y] := whiteColor; End; result := retBmp; End; Function countWhite(bmp : TSCARBitmap) : Integer; Var x,y, count, whitecolor: Integer; Begin whiteColor := 16777215; For x:=0 to bmp.Width-1 do For y:=0 to bmp.Height-1 do If bmp.Pixel[x,y] = whiteColor then count := count + 1; Result := count; End; Function getDistance(bmp : TSCARBitmap) : Extended; Var x,y, whitecolor: Integer; p1, p2 : TPoint; Begin whiteColor := 16777215; For x:=0 to bmp.Width-1 do For y:=0 to bmp.Height-1 do If bmp.Pixel[x,y] = whiteColor then begin p1 := Point(x,y); x:= bmp.Width-1; y:= bmp.Height-1; end; For x:=bmp.Width-1 downto 0 do For y:=bmp.Height-1 downto 0 do If bmp.Pixel[x,y] = whiteColor then begin p2 := Point(x,y); x:=0; y:=0; end; Result := Distance(p1.X,p1.Y,p2.X,p2.Y); End; Function getDistance2(bmp : TSCARBitmap) : Extended; Var x,y, whitecolor: Integer; p1, p2 : TPoint; Begin whiteColor := 16777215; For y:=0 to bmp.Height-1 do For x:=0 to bmp.Width-1 do If bmp.Pixel[x,y] = whiteColor then begin p1 := Point(x,y); x:= bmp.Width-1; y:= bmp.Height-1; end; For y:=bmp.Height-1 downto 0 do For x:=bmp.Width-1 downto 0 do If bmp.Pixel[x,y] = whiteColor then begin p2 := Point(x,y); x:=0; y:=0; end; Result := Distance(p1.X,p1.Y,p2.X,p2.Y); End; Function getChar(bmp : TSCARBitmap) : String; Var TPA : TPointArray; bmpChar : TSCARBitmap; c : String; i : Integer; score, low : Extended; Begin low := 10000; c := ''; bmpChar := TSCARBitmap.Create(''); For i:= 48 To 58 do Begin bmpChar.LoadFromBMP('C:\Users\Admin\Documents\SCAR Divi\Fonts\'+IntToStr(i)+'.bmp'); score := score + abs(countWhite(bmpChar)-countWhite(bmp)); writeln(score); SimilarBitmapsEx(bmp, bmpChar, 0, TPA); score := score + Length(TPA); writeln(score); score := score + abs(getDistance(bmpChar)-getDistance(bmp)); writeln(score); score := score + abs(getDistance2(bmpChar)-getDistance2(bmp)); writeln(score); writeln('~~~~~~~~~~~~~~~~~~'); if score < low then Begin low := score; c := IntToStr(i); End; score := 0; End; Writeln(c); Result := c; End; begin //decimal ones 336,45,344,58 //decimal tens 328, 45, 336, 58 //decimal huns 319, 45, 327, 58 bmp := TSCARBitmap.Create(''); bmp := GetClient.CaptureEx(336, 45, 344, 58); bmp := bmpToBW(bmp, 120); //writeln(IntToStr(countWhite(bmp))); getChar(bmp); end. Here are my font bmps 48.bmp 49.bmp 50.bmp 51.bmp 52.bmp 53.bmp 54.bmp 55.bmp 56.bmp 57.bmp Am I approaching this in the wrong direction? Thanks in advance. Edited October 21, 2015 by dumass Quote Link to comment Share on other sites More sharing options...
Wanted Posted October 24, 2015 Share Posted October 24, 2015 Eh unless you are a wizard with OCR in this case you're better off making DTMs of all the numbers 0-9 and then doing searches for them and analyzing their positions to get the sequences of numbers and then putting them together to find the number. Kind of a pseudo OCR based on FindDTMs DTM5 found at this position DTM9 found at this position first position is just left of the 2nd position Number must be 59 etc.. Quote Link to comment Share on other sites More sharing options...
dumass Posted October 25, 2015 Author Share Posted October 25, 2015 Ok, Ill try that way. Any example scripts that utilize DTM's so I can get a better understanding of them? Quote Link to comment Share on other sites More sharing options...
Wanted Posted October 26, 2015 Share Posted October 26, 2015 Ok, Ill try that way. Any example scripts that utilize DTM's so I can get a better understanding of them? Scripts... not really since DTMs are encoded with the DTM editor. You'll need to find a guide on DTMs or just read the documentation on the SCAR manual. Quote Link to comment Share on other sites More sharing options...