Results 1 to 4 of 4

Thread: FindBitmapInBitmap

  1. #1
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default FindBitmapInBitmap

    Why does SRL not have a function for this already? I'm struggling to write one lol. I use the below to gather my minimap bitmaps then I use another function below to Check whether they match..

    Problem: It's too accurate -_- So I need to know how to check neighbouring pixels or something to make it less accurate. Basically the below will check the colours of the bitmap with a tolerance but I noticed that not only does the colours change every so often (This is not a problem) but rather the minimap shifts ever so slightly to a direction.. Anything more than a 5 pixels shift makes it return false..

    Basically if I'm standing on a square and I run the below function, it will grab my bitmap. If I move 4 squares, the bitmaps don't match until I'm within 2 - 3 squares of my old position.

    How can I fix it. The entire script is on this thread: http://villavu.com/forum/showthread.php?t=81885

    Simba Code:
    Procedure GetMinimap(var Map: Integer);
    var
      TPA, Draw: TPointArray;
      TIA: TIntegerArray;
      I, BMP: Integer;
    begin
      BMP:= CreateBitmap(MMX2 - MMX1 + 1, MMY2 - MMY1 + 1);
      TPA:= TPAFromBox(MMBox);
      FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, MMCX, MMCY);
      TIA:= GetColors(TPA);

      TPA:= TPAFromBox(IntToBox(0, 0, MMX2 - MMX1, MMY2 - MMY1));
      DrawTPABitmap(BMP, TPA, 0);
      FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, (MMX2 - MMX1)/2, (MMY2 - MMY1)/2);

      SetLength(DRAW, 1);
      For I:= 0 To High(TPA) do
      begin
        Draw[0]:= TPA[I];
        DrawTPABitmap(BMP, Draw, TIA[I]);
      end;

      For I:= 0 To High(TPA) do
      begin
        if (SimilarColors(TIA[I], 67075, 20)) then       //If similar to black, make it completely black.
          FastSetPixel(BMP, TPA[I].X, TPA[I].Y, clBlack);
      end;
      Map:= CopyBitmap(Bmp);
      FreeBitmap(BMP);
    end;

    Function FindBitmapInBitmap(XBMP, YBMP, Tol: Integer): Boolean;
    var
      Similar, NotSimilar, I, J, X: Integer;
      BMPC1, BMPC2: T2DIntegerArray;
    begin
      try
      BMPC1:= GetBitmapAreaColors(XBMP, 0, 0, 150, 150);
      BMPC2:= GetBitmapAreaColors(YBMP, 0, 0, 150, 150);

      X:= High(BMPC1);
      For I:= 0 To 150 do
      begin
        For J:= 0 To 150 do
        begin
          if ((SimilarColors(BMPC1[J][I], 0, 20)) or (SimilarColors(BMPC2[J][I], 0, 20))) then  //If similar to black, ignore it..
            Continue;
          if (SimilarColors(BMPC1[J][I], BMPC2[J][I], Tol)) then
            Inc(Similar)
          else
            Inc(NotSimilar);
        end;
      end;
      Result:= Similar > NotSimilar;
      except
        Result:= False;
      end;
    end;
    I am Ggzz..
    Hackintosher

  2. #2
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Why not use Simba's function?
    Simba Code:
    function FindBmpInBmp(var Find_bmp , SearchIn_bmp ,x ,y) :boolean;
    begin
      SetTargetBitmap(SearchIn_bmp);
      Result := FindBitmap(Find_bmp,x,y) : Boolean;
      {$ifdef SMART}
      SmartSetTarget;
      {$endif}
    end;

  3. #3
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by beginner5 View Post
    Why not use Simba's function?
    Simba Code:
    function FindBmpInBmp(var Find_bmp , SearchIn_bmp ,x ,y) :boolean;
    begin
    SetTargetBitmap(SearchIn_bmp);
    Result := FindBitmap(Find_bmp,x,y) : Boolean;
    {$ifdef SMART}
    SmartSetTarget;
    {$endif}
    end;
    Because that finds a bitmap on the screen.. I want to find a bitmap within another bitmap. It doesn't work finding it on the screen. I tried.
    See how I commented out the FindDeformedBitmap in the actual script? That thing keeps returning true everytime.

    I used:
    Simba Code:
    if (Not FindBitmapToleranceIn(StartingBitmap, X, Y, MMX1, MMY1, MMX2, MMY2, 20)) then

    It Never finds it no matter what.
    I am Ggzz..
    Hackintosher

  4. #4
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Because that finds a bitmap on the screen.. I want to find a bitmap within another bitmap.
    My function does find bitmap in another bitmap , SetTargetBitmap(bmp) changes searching area from screen to bitmap.

    Just checked ,it works:

    Simba Code:
    program new;

       {Put cross on code}
    function FindBmpInBmp(var Find_bmp , SearchIn_bmp ,x ,y : integer) :boolean;
    begin
      SetTargetBitmap(SearchIn_bmp);
      Result := FindBitmap(Find_bmp,x,y);
    end;

    var
     bmp1 ,bmp2 ,w,h ,x,y: integer;

    begin
      GetClientDimensions(w,h);
      bmp1 := BitmapFromClient(1,1,w-1,h-1);

      bmp2 := BitmapFromClient(1,1,200,200);

      wait(5000);
      keydown(17);  // ctrl + a to change client image
      keydown(65);
      keyup(65);
      keyup(17)
      wait(5000);

      writeln(FindBmpInBmp(bmp2,bmp1,x,y ));
    end.
    Last edited by bg5; 05-09-2012 at 07:13 AM.

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
  •