Results 1 to 4 of 4

Thread: Find them tree's accurately.

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

    Default Find them tree's accurately.

    Well, I thought I'd share a snippet I made many years ago - Adjusted it for this exact usage right now. Someone might find it useful for their scripts, at least if they are making a WC-script. At least the idea is kinda cool, and might be useful for other shit as well.

    PS: Note that it's for OSRS, and will likely be useless for RS3.

    The snippet looks like this:
    Simba Code:
    function FindTrees(Area:TBox; EdgeDiff, Color, Tolerance:Int32): T2DPointArray;
    var
      i,c,wid,hei: Int32;
      bmp: PtrUInt;
      TPA,tmp: TPointArray;
      pt: TPoint;
      mat: T2DIntArray;
    begin
      bmp := BitmapFromClient(area.x1,area.y1,area.x2,area.y2);
      mat := BitmapToMatrix(bmp);
      FreeBitmap(bmp);

      FindColorsTolerance(tmp, Color, area.x1+1,area.y1+1,area.x2-1,area.y2-1, Tolerance);
      OffsetTPA(tmp, Point(-area.y1,-area.x1));

      hei := High(mat);
      wid := High(mat[0]);
      SetLength(TPA, Length(TMP));
      for i:=0 to High(tmp) do
      begin
        pt := tmp[i];
        if (not SimilarColors(mat[pt.y][pt.x], mat[pt.y][pt.x+1], EdgeDiff)) and
           (not SimilarColors(mat[pt.y][pt.x], mat[pt.y+1][pt.x], EdgeDiff)) and
           (not SimilarColors(mat[pt.y][pt.x], mat[pt.y][pt.x-1], EdgeDiff)) and
           (not SimilarColors(mat[pt.y][pt.x], mat[pt.y-1][pt.x], EdgeDiff)) then
          TPA[Inc(c)-1] := pt;
      end;
      SetLength(TPA, c);
      OffsetTPA(TPA, Point(area.y1,area.x1));
      Result := ClusterTPA(TPA, 2);
    end;

    And as a result using these parameters:
    > SetColorToleranceSpeed(2);
    > ATPA := FindTrees([4,4,515,337], 2, 2586985, 90);
    > FilterTPAsBetween(ATPA, 0, 350);


    Parameters:
    - Area: where to search
    - EdgeDiff: Minimum color-difference between adjacent pixels [a low number]
    - Color: The color of the tree leafs
    - Tolerance: Well, tolerance for searching for them leafs (can be quite high, and is probably preferred)

    The method can be extended on as you see fit, it doesn't allow you to adjust everything. However, you might struggle to specify an exact type of tree, since tree leafs have very similar color, and you kinda wanna keep the "tolerance" parameter high.
    Last edited by slacky; 05-06-2022 at 06:11 PM.
    !No priv. messages please

  2. #2
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default

    This is great. Just tested it and it worked perfectly. Used FilterTPAsBetween to filter the smaller trees from the larger trees. Seems to work well

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

    Default

    Quote Originally Posted by Dan the man View Post
    This is great. Just tested it and it worked perfectly. Used FilterTPAsBetween to filter the smaller trees from the larger trees. Seems to work well
    Aha forgot about that function. Removed the noise parameter, as you can just use that function indeed, and it's more flexible.
    Last edited by slacky; 08-28-2017 at 02:53 AM.
    !No priv. messages please

  4. #4
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default

    Quote Originally Posted by slacky View Post
    Aha forgot about that function. Removed the noise parameter, as you can just use that function indeed, and it's more flexible.
    Edit: NVM you fixed it ^.^

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
  •