Results 1 to 10 of 10

Thread: Reading GE progress text. Need help.

  1. #1
    Join Date
    Jun 2014
    Location
    Oklahoma
    Posts
    336
    Mentioned
    22 Post(s)
    Quoted
    231 Post(s)

    Default Reading GE progress text. Need help.

    I am attempting to write a GE flipper. To find margins for items I need to read the text in the progress screen.



    So this screen. I only really need the gold numbers. So after quite a while fiddling with Olly's Tesseract tool, I couldn't find settings that would read it accurately as is. So I made this function that goes in and makes it readable.

    Simba Code:
    function TRSGrandExchange.getProgressNumbers(): TIntegerArray;
    var
      textArea : TBox := [self.x1 + 29, self.y1 + 366, self.x1 + 423, self.y1 + 398];
      TessFilter: TTesseractFilter = [4, 4, [False, 24, TM_Mean]];
      TABMap, x, y : Integer;
      TessStr : String;
      Nums : TStringArray;
    begin
      if not self.isOpen() then
      begin
        print('TRSGrandExchange.abortSlot(): Cannot abort as the GE is not open', TDebug.ERROR);
        exit([-1]);
      end;

      TABMap := BitmapFromClient(textArea);

      //DebugBitmap(TABMap);    //a

      for x := 0 to 394 do
      begin
        for y:= 0 to 32 do
        begin
          if not SimilarColors(FastGetPixel(TABMap,x,y),224656,80) then
            FastSetPixel(TABMap,x,y,0)
          else
            FastSetPixel(TABMap,x,y,255);
        end;
      end;

      //DebugBitmap(TABMap);    //b

      Tesseract_ApplyFilter(TABMap,TessFilter);

      DebugBitmap(TABMap);    //c


      TessStr := Tesseract_GetText(TABMap);

      Writeln(TessStr);
      FreeBitmap(TABMap);
    end;

    Here is a picture with all the debug images.



    And output.
    Code:
    -- setupSRL(): True
    -- TRSGrandExchange.isOpen(): Result = True
    -- TRSGrandExchange.isOpen(): Result = True
    1
    218
    -- Succesfully freed SMART[15388]
    Successfully executed.
    I've tried and failed to make the output string go into 2 integers (the top one and bottom one). But everytime I encounter some kind of inaccuracy. And when it reads more complex numbers it will output with spaces. Such as:

    Code:
    1
    1 4.8 56
    From reading
    Code:
    1
    14,856
    So I need to figure out a way deal with these unnecessary characters (spaces, commas, periods) and get the string into two pieces (for each integer) and then convert it.

    I've tried fiddling with some of the functions here http://docs.villavu.com/simba/scriptref/string.html . Is there a way to detect the next line character? If thats what it's called at least..

  2. #2
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Why not read both lines separately? I can try and throw something up later if i get the time.

  3. #3
    Join Date
    Jun 2014
    Location
    Oklahoma
    Posts
    336
    Mentioned
    22 Post(s)
    Quoted
    231 Post(s)

    Default

    ... that's a really good point.

    So I just doubled everything (redundant code everywhere but oh well)

    Simba Code:
    function TRSGrandExchange.getProgressNumbers(): TIntegerArray;
    var
      textArea1 : TBox := [self.x1 + 29, self.y1 + 366, self.x1 + 423, self.y1 + 382];
      textArea2 : TBox := [self.x1 + 29, self.y1 + 382, self.x1 + 423, self.y1 + 398];
      TessFilter: TTesseractFilter = [4, 4, [False, 24, TM_Mean]];
      TABMap1, TABMap2, x, y : Integer;
      TessStr : String;
      Nums : TStringArray;
    begin
      if not self.isOpen() then
      begin
        print('TRSGrandExchange.abortSlot(): Cannot abort as the GE is not open', TDebug.ERROR);
        exit([-1]);
      end;

      TABMap1 := BitmapFromClient(textArea1);
      TABMap2 := BitmapFromClient(textArea2);

      //DebugBitmap(TABMap);    //a

      for x := 0 to 394 do
      begin
        for y:= 0 to 16 do
        begin
          if not SimilarColors(FastGetPixel(TABMap1,x,y),224656,80) then
            FastSetPixel(TABMap1,x,y,0)
          else
            FastSetPixel(TABMap1,x,y,255);

          if not SimilarColors(FastGetPixel(TABMap2,x,y),224656,80) then
            FastSetPixel(TABMap2,x,y,0)
          else
            FastSetPixel(TABMap2,x,y,255);
        end;
      end;

      //DebugBitmap(TABMap);    //b

      Tesseract_ApplyFilter(TABMap1,TessFilter);
      Tesseract_ApplyFilter(TABMap2,TessFilter);

      DebugBitmap(TABMap2);    //c

      SetLength(Nums,2);
      Nums[0] := Tesseract_GetText(TABMap1);
      Nums[1] := Tesseract_GetText(TABMap2);

      Writeln(Nums[0]);
      WriteLn(Nums[1]);

      //fix string up
      for x := 0 to 1 do
      begin
        for y := 0 to length(Nums[x]) do
        begin
          if not isStrInArr(Nums[x][y],false,['1','2','3','4','5','6','7','8','9','0']) then
            Delete(Nums[x],y,1);
        end;
      end;
      Writeln(Nums[0]);
      WriteLn(Nums[1]);


      Result := [StrToInt(Nums[0]),StrToInt(Nums[1])];  

      FreeBitmap(TABMap1);
      FreeBitmap(TABMap2);
    end;

    Then I think I figured the string part out.

    output
    Code:
    1
    1 4.8 56
    1
    14856
    -- Succesfully freed SMART[15388]
    Successfully executed.

  4. #4
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Can i get a screenshot of a item work more (so it has commas and such in)?

  5. #5
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    The key when reading those yellow numbers is to make the box perfect. Auto-detecting the size of the box is pretty important because when you get all those letters in there it really screws everything up. You should be able to avoid all the weirdness and use regular tesseract functions if you get the box right.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  6. #6
    Join Date
    Jun 2014
    Location
    Oklahoma
    Posts
    336
    Mentioned
    22 Post(s)
    Quoted
    231 Post(s)

    Default

    Quote Originally Posted by 3Garrett3 View Post
    The key when reading those yellow numbers is to make the box perfect. Auto-detecting the size of the box is pretty important because when you get all those letters in there it really screws everything up. You should be able to avoid all the weirdness and use regular tesseract functions if you get the box right.
    Simba Code:
    for x := 0 to 394 do
      begin
        for y:= 0 to 16 do
        begin
          if not SimilarColors(FastGetPixel(TABMap1,x,y),224656,80) then
            FastSetPixel(TABMap1,x,y,0)
          else
            FastSetPixel(TABMap1,x,y,255);

          if not SimilarColors(FastGetPixel(TABMap2,x,y),224656,80) then
            FastSetPixel(TABMap2,x,y,0)
          else
            FastSetPixel(TABMap2,x,y,255);
        end;
      end;

    This part gets rid of every letter (pixel on that note) that is not the gold color then sets it to black. And then sets the gold to red. So no need to calculate where the gold letters are. (might be faster by like 20ms though but I don't care that much)


    @Olly;
    The second function I posted finds these numbers

  7. #7
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    Quote Originally Posted by Camel View Post
    Simba Code:
    for x := 0 to 394 do
      begin
        for y:= 0 to 16 do
        begin
          if not SimilarColors(FastGetPixel(TABMap1,x,y),224656,80) then
            FastSetPixel(TABMap1,x,y,0)
          else
            FastSetPixel(TABMap1,x,y,255);

          if not SimilarColors(FastGetPixel(TABMap2,x,y),224656,80) then
            FastSetPixel(TABMap2,x,y,0)
          else
            FastSetPixel(TABMap2,x,y,255);
        end;
      end;

    This part gets rid of every letter (pixel on that note) that is not the gold color then sets it to black. And then sets the gold to red. So no need to calculate where the gold letters are. (might be faster by like 20ms though but I don't care that much)
    It still leaves you with a big box of black right? I find that having a focused box (ie no extra blank space) makes it much more accurate. I run into problems if there is too much blank space in the box. Probably has something to do with the tesseract resizing. So instead of having a huge box, I made all my text reading autodetect the gold color and narrow the box until no white was found - then we have a box of only gold. Then I read from that.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  8. #8
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Trick is indeed to crop the image to the text you want to read, that and some basic filters + whitelist.

    Simba Code:
    {$i srl-6/srl.simba}

    var
      bmp := BitmapFromString(189, 17, 'meJzlWl1QlNcZZndZYAXkb0VwQcmylWFjjNFGoE7VTFMlCv5Ok9RkzGisxqiAEXGioEYTo1DpJBck+JNEepHGaKZR007EtNNeNCbphU4l6UUzgjcqvQJyIzf2+b7HfXz5tnU606tYZmfn7Dnvec57nvfnvOf7iMdKK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exgB/4wEHJrWPCsVr5dBf+boFEfYiDKbqYK4HwLrBr165Lly6BYQROMpNcNGoeWdt2LOmZYXTsw201ku8O9ilfhXkqzhucXrhEEy8+uIoHX09Z9QRVx6j6raTW/c7ZrN/qaR+i2ohIvl9XJB796TF7zLz+sw9zCGIRbPDeg0/em/53PuEtsPu9+eRzif+ST5SjPK+RkJu3NbFqBZOeF7WWT6ueR1U9G4dK9jWWffJjfUMXNMsqHSaeeGWsWclvhy2axzT229Koqz0nPjbnUWyWSU92UfmnLdM35A/J3mvfxWhdlaOygt5cWIHvI59ffXERRxJcBUUCfBsJf27NLBZsOkSsn8fHviJh28avNKFvx00ZHzOPTxXOUoZTRKZnpx5hRYGOAxsmUfNexlIhDfX/AM61tOSOOSyaZzmBK8N4AvyhyrJ4Ur616UWre/C/v3wm/u3Ez1stcPggToBCs1nLtuOmStERI1psgCvqbRqPjb2RkX/8RIhJzJ4F4llhaxeKJ/5nQJKKnWjiphMzb4o13aZoSywvpDH32aNGPSmFaUSJxZrbIutfXGzGu+/5/BeGz7H/');

      area: TBox;
      TPA: TPointArray;
      w, h, new: Integer;
      s: String;
    begin
      SetTargetBitmap(bmp);
      GetBitmapSize(bmp, w, h);

      FindColorsTolerance(TPA, 362675, 0, 0, w-1, h-1, 50);
      Area := GetTPABounds(TPA);
      Area.expand(2);

      new := BitmapFromClient(Area);
      FreeTarget(GetImageTarget());
      FreeBitmap(bmp);

      GetBitmapSize(new, w, h);
      ResizeBitmapEx(new, RM_Bilinear, w * 5, h * 5);
      ThresholdAdaptiveBitmap(new, 0, 255, False, TM_Mean, 10);
      writeln(s := Tesseract_GetText(new, '0123456789,'));
      writeln(ExtractFromStr(s, Numbers));

      DebugBitmap(new);
      FreeBitmap(new);
    end.
    Last edited by Olly; 10-01-2015 at 10:54 PM.

  9. #9
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by Olly View Post
    Trick is indeed to crop the image to the text you want to read, that and some basic filters + whitelist.
    ...
    You can often also remove extra spacings simply by scaling the height more than the width. Not that this is needed in this exact case where you just want the numbers anyway.
    > ResizeBitmapEx(new, RM_Bilinear, w * 4, h * 6);
    !No priv. messages please

  10. #10
    Join Date
    Sep 2014
    Location
    Netherlands
    Posts
    264
    Mentioned
    11 Post(s)
    Quoted
    130 Post(s)

    Default

    Hi, I was working on a flipping script. But I haven't been active in a few months. I'm planning to get active again and finish the script in a few months. This is what I use to get the item price:

    Simba Code:
    function getItemPrice(): String;
    var
      tessFilter: TTesseractFilter = [6, 6, [false, 15, TM_Mean]];
      myBox: tBox;
      i, i2, x, y : integer;

    begin
      myBox := intToBox(280, 393, 289, 410);

      for i := 289 to 400 do
      begin
        myBox := IntToBox(280, 393, i, 410);
        if (findColorSpiralTolerance(x, y, 12040118, myBox, 29, colorSetting(2, 0.96, 0.07))) then
          begin
            i := i -3;
            break;
          end;
      end;

      for i2 := 50 to 280 do
      begin
        myBox := IntToBox(i2, 393, i, 410);
        if not findColorSpiralTolerance(x, y, 12040118, myBox, 29, colorSetting(2, 0.96, 0.07)) then
        begin

          break;
        end;
      end;

      smartImage.drawBox(IntToBox(i2, 393, i, 410), false, 922721);
      result := extractFromStr(tesseractGetText(intToBox(i2, 393, i, 412), tessFilter), Numbers);
    end;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •