Results 1 to 15 of 15

Thread: FindColorSkipBoxArray

  1. #1
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default FindColorSkipBoxArray

    Why won't this work? You color pick the red door color, put in const, and it's supposed to find each door, and display a bitmap of the surrounding area of each door.

    SCAR Code:
    program New;
    {.include SRL/SRL.scar}

    const doorcolor=230;

    var skippingarray:tboxarray;


    procedure DisplayPicture(TheBox:tbox);
    var
      DebugCanvas, ClientCanvas: TCanvas;
      w, h: Integer;

    begin
      w := Thebox.x2 - Thebox.x1;
      h := Thebox.y2 - Thebox.y1;
      ActivateClient;
      DisplayDebugImgWindow(w, h);
      DebugCanvas := GetDebugCanvas;
      ClientCanvas := GetClientCanvas;
      SafeCopyCanvas(ClientCanvas, DebugCanvas, TheBox.x1,TheBox.y1,TheBox.x2,TheBox.y2, 0, 0, w, h);
    end;

    function SurroundBox(px,py:integer):Tbox;
    var Inner,Outer:Tbox;
    PointColor,dx,dy:integer;
    begin
      PointColor:=GetColor(px,py);
      Inner.x1:=px;
      Inner.y1:=py;
      Inner.x2:=px;
      Inner.y2:=py;
      Outer.x1:=px-10;
      Outer.y1:=py-10;
      Outer.x2:=px+10;
      Outer.y2:=py+10;
      repeat
       // Outer.x1:=Outer.x1-1;
        Inner.x1:=Inner.x1-1;
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
      repeat
       // Outer.Y1:=Outer.Y1-1;
        Inner.Y1:=Inner.y1-1;
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
    repeat
        //Outer.x2:=Outer.x2+1;
        Inner.x2:=Inner.x2+1;
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
    repeat
       // Outer.y2:=Outer.y2+1;
        Inner.y2:=Inner.y2+1;
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));

      Result:=Inner;
    end;

    var arraylength,i:integer;

    begin
      SetupSRL;
      // DisplayPicture(657,120,671,129);
      //mybox:=Surroundbox(myx,myy);
      setarraylength(skippingarray,1);
      skippingarray[0].x1:=0;
      skippingarray[0].y1:=0;
      skippingarray[0].x2:=1;
      skippingarray[0].y2:=1;


      repeat
        if FindColorSkipBoxArray(x,y,DoorColor,566,6,730,163,skippingarray) then
        begin
          writeln('found');
          arraylength:= getarraylength(skippingarray);
          arraylength:=arraylength+1;
          setarraylength(skippingarray,arraylength);
          skippingarray[arraylength]:= Surroundbox(x,y);
        end;
        writeln(inttostr(arraylength));
      until not(FindColorSkipBoxArray(x,y,DoorColor,mmx1,mmy1,mmx2,mmy2,skippingarray));
      writeln('done');
      repeat
        repeat
          wait(1000);
        until isfkeydown(12);
        i:=i+1;
        DisplayPicture(Skippingarray[i]);
       until i=arraylength;
    end.


    I guess I could use getpixels, but then I would have to sort through them to make sure each door only gets counted once because each door has more than one pixel. I don't see why I can't get this work, any help please?

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    I know the plugins are installed correctly because the examples work with the example pic. But when I change the color in the pic and in the parameters, the example doesn't work either!

  3. #3
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Is the objective to capture the positions of each door in an x,y array? And you are searching in blocks of 10, right?
    FindColorSkipBoxArray appearantly finds nothing, thus all is skipped. I bam not sure about this one, since I have never actually used FindColorSkipBoxArray, but I presume you are skipping each + 1, so maybe you are actually skipping all pixels... But I dont really know right now, sry.
    Why can it not be done with FindColorTolerance?
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  4. #4
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    The objective is to end up with an array of tboxes, each containing one door, no more no less, and each door being in one box, no more no less.

    FindColorSkipBoxArray should find the top left most pixel of the color, and SurroundBox should expand a box (called Inner) until it contains all of the color with in a 20 by 20 box. This box (Inner) should be added to the array, and contain 1 door. The pixels in this door should now be skipped, to get the next most top left pixel of the color, repeating until all doors are in boxes.

    Thanks for reading. I pmed Freddy, hopefully he can help, at least with why the example in SRL doesn't work with red.

    Tolerance would work, but I can get the color exactly with another function that I haven't included here.

  5. #5
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    your problem is your way of copying rs bitmap to debugwindow.. it should be done this way:
    MyBitmap := GetBitmapFromString(Width, Height, '');
    CopyClientToBitmap(x, y, x + width, y + height, MyBitmap);
    DisplayDebugImgWindow(Width, Height);
    CopyCanvas(GetBitmapCanvas(MyBitmap), GetDebugCanvas, bla bla bla....);

    I'm not sure if the names are correct (made this from my memory)..

  6. #6
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    No I think DisplayPicture (based on RRW) works, I tested it on other stuff. FindColorSkipBoxArray isn't finding the color because

    writeln('found');

    never appears in debug box, that's the problem

  7. #7
    ronny.m.p Guest

    Default

    What exactly happens when you try to run it?

  8. #8
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    nothing, it doesnt find anything

    if FindColorSkipBoxArray(x,y,DoorColor,566,6,730,163, skippingarray) then
    begin
    writeln('found');

    i know because it doesnt say found in debug box

    hopefully freddy can help when hes not busy with divi

  9. #9
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Freddy fixed the plugin, all better now

  10. #10
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Heh, Boreas double posted twice in this thread

    oh, and back ontopic...ehh, sorta; Boreas, I was wondering what the point of this is...sure, its interesting...but what good does it do to open lots of doors?
    Interested in C# and Electrical Engineering? This might interest you.

  11. #11
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Very observant

  12. #12
    Join Date
    Nov 2006
    Location
    California, USA
    Posts
    336
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Smartzkid View Post
    Heh, Boreas double posted twice in this thread
    What the hell does that matter?

    Sorry I'm just a bit upset tonight and that annoyed the hell out of me.

  13. #13
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Goosfraba Nate (just watched anger management lol)

    Quote Originally Posted by Smartzkid View Post
    oh, and back ontopic...ehh, sorta; Boreas, I was wondering what the point of this is...sure, its interesting...but what good does it do to open lots of doors?
    It doesn't open lots of doors, it just finds them all on the minimap. I will use brambles door opener to open doors. It will be used for lumbridge castle, and wizards tower. It can also be used for location detectors.

  14. #14
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Oh, ok, I think I got it now. So this script just finds individual doors; and is going to be part of a bigger script, allowing the bigger script to do things in buildings.
    Interested in C# and Electrical Engineering? This might interest you.

  15. #15
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Yea. Last night I did this

    SCAR Code:
    function BoxArrayToArrayOfTPA(Color:integer; Boxes:array of TBox): array of TPointArray;
    var i:integer;
    begin
      setarraylength(result,getarraylength(boxes));
      for i:=0 to GetArrayLength(Boxes)-1 do
        FindColorsTolerance(result[i],Color,Boxes[i].x1,Boxes[i].y1,Boxes[i].x2,Boxes[i].y2,0);
    end;

    to get the points of the doors. Used with this
    SCAR Code:
    program New;
    {.include SRL/SRL.scar}

    const doorcolor=235;

    var skippingarray:tboxarray;
    AOTPA:array of TpointArray;

                    vx,f,vy:integer;
    function tPtArrayToStr(newTPoint: TPointArray): string;
    var
      i: Integer;
    begin
      for i:=0 to GetArrayLength(newTPoint)-1 do
       begin
       Result := Result + IntToStr(newTPoint[i].x) + ',' +
          IntToStr(newTPoint[i].y);
           if (not (i = (GetArrayLength(newTPoint) - 1))) then
          Result := Result + ' ';
      end;
    end;

    function BoxArrayToArrayOfTPA(Color:integer; Boxes:array of TBox): array of TPointArray;
    var i:integer;
    begin
      setarraylength(result,getarraylength(boxes));
      for i:=0 to GetArrayLength(Boxes)-1 do
        FindColorsTolerance(result[i],Color,Boxes[i].x1,Boxes[i].y1,Boxes[i].x2,Boxes[i].y2,0);
    end;


    procedure DisplayPicture(TheBox:tbox);
    var
      DebugCanvas, ClientCanvas: TCanvas;
      w, h, bmp: Integer;

    begin
      w := Thebox.x2 - Thebox.x1;
      h := Thebox.y2 - Thebox.y1;
      ActivateClient;
      DisplayDebugImgWindow(w, h);
      DebugCanvas := GetDebugCanvas;
      ClientCanvas := GetClientCanvas;
      SafeCopyCanvas(ClientCanvas, DebugCanvas, TheBox.x1,TheBox.y1,TheBox.x2,TheBox.y2, 0, 0, w, h);
    //bmp := BitmapFromString(w, h, '');

    //CopyClientToBitmap(bmp,Thebox.x1, Thebox.y1, Thebox.x1 + w, Thebox.y1 + h);
    //DisplayDebugImgWindow(w, h);
    //CopyCanvas(GetBitmapCanvas(bmp), GetDebugCanvas, TheBox.x1,TheBox.y1,TheBox.x2,TheBox.y2, 0, 0, w, h);

    end;

    function SurroundBox(px,py:integer):Tbox;
    var Inner,Outer:Tbox;
    PointColor,dx,dy:integer;
    begin
      PointColor:=GetColor(px,py);
      Inner.x1:=px;
      Inner.y1:=py;
      Inner.x2:=px;
      Inner.y2:=py;
      Outer.x1:=px-5;
      Outer.y1:=py-5;
      Outer.x2:=px+5;
      Outer.y2:=py+5;    {
      repeat
       // Outer.x1:=Outer.x1-1;
        Inner.x1:=Inner.x1-1;
      //writeln('test3');
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Inner.x1,Outer.y2,Inner)));
      //writeln('test2');
      repeat
       // Outer.Y1:=Outer.Y1-1;
        Inner.Y1:=Inner.y1-1;
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
      //writeln('test1');
    repeat
        //Outer.x2:=Outer.x2+1;
        Inner.x2:=Inner.x2+1;
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
      // writeln('test1');
    repeat
       // Outer.y2:=Outer.y2+1;
        Inner.y2:=Inner.y2+1;
      until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
       //writeln('test1');
      Result:=inner;       }
    result:=outer;
    end;

    var arraylength,i:integer;

    begin
      SetupSRL;
      // DisplayPicture(657,120,671,129);
      //mybox:=Surroundbox(myx,myy);
      setarraylength(skippingarray,1);
      skippingarray[0].x1:=0;
      skippingarray[0].y1:=0;
      skippingarray[0].x2:=1;
      skippingarray[0].y2:=1;

       arraylength:=1;
      repeat                                     {566,6,730,163}
        if FindColorSkipBoxArray(vx,vy,DoorColor,mmx1,mmy1,mmx2,mmy2,skippingarray) then
        begin
          //writeln('found');
          //writeln(inttostr(arraylength));
          //arraylength:= getarraylength(skippingarray);
          arraylength:=arraylength+1;
          setarraylength(skippingarray,arraylength);
          skippingarray[arraylength-1]:= Surroundbox(vx,vy);
          //writeln('test1');
        end;
        writeln(inttostr(arraylength));
        wait(1);
      until ((isfkeydown(11)) or (not(FindColorSkipBoxArray(vx,vy,DoorColor,mmx1,mmy1,mmx2,mmy2,skippingarray))));
      writeln('done');
     { repeat
        repeat
          wait(1000);
        until isfkeydown(12);
        i:=i+1;
        DisplayPicture(Skippingarray[i]);
        repeat
          wait(1000);
        until isfkeydown(11);

       until i=(arraylength-1);   }


    AOTPA:=BoxArrayToArrayOfTPA(doorColor,Skippingarray)
    for f:= 0 to getarraylength(AOTPA)-1 do
    writeln(tPtArrayToStr(AOTPA[f]));
       
    end.
    Look at that output compared to just doing findcolorstolerance for the whole minimap. This was they are separated, 1 list for each door.

    Now I am working on something to get 1 point to represent each door. I started with

    SCAR Code:
    program New;
    {.include SRL/SRL.scar}
    var tpa:tpointarray;
    Tp:tpoint;

    function MidPointOfLine(TheArray:array of Tpoint):Tpoint;
    var
    i,ArrayLength,
    DiffX,TotalX,{AveX,}AverageX,
    DiffY,TotalY,{AveY,}AverageY:integer;
    AveX,AveY:extended;
    begin
      DiffX:=100;
      diffy:=100;
      ArrayLength:=GetArrayLength(TheArray)

      for i:=0 to ArrayLength-1 do
        TotalX:=TotalX+TheArray[i].x;
      AveX:={Round}(TotalX/ArrayLength);

      for i:=0 to ArrayLength-1 do
        TotalY:=TotalY+TheArray[i].y;
      AveY:={Round}(TotalY/ArrayLength);

      for i:=0 to ArrayLength-1 do
      begin
        if (Abs(AveX-TheArray[i].x)) < DiffX then
        begin
          DiffX:=Round(Abs((AveX-TheArray[i].x)*1.0));
          AverageX:=i;
        end;
      end;
     
      for i:=0 to ArrayLength-1 do
      begin
        if (Abs(AveY-TheArray[i].y)) < DiffY then
        begin
          DiffY:=Round(Abs((AveY-TheArray[i].y)*1.0));
          AverageY:=i;
        end;
      end;
     
      i:=(averagex + averagey)/2;
      result:=TheArray[i];
    end;
     
     function strToTPtArray(tPtStr: string): TPointArray;
    var
      i, commaPos, spacePos: Integer;
    begin
      repeat
        SetArrayLength(Result, i + 1);
        commaPos := Pos(',', tPtStr);
        spacePos := Pos(' ', tPtStr);
        Result[i].x := StrToInt(Copy(tPtStr, 1, commaPos - 1));
        if (not (spacePos = 0)) then
        begin
          Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, spacePos - commaPos -
            1));
        end
        else
        begin
          Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, Length(tPtStr)));
          break;
        end;
        Delete(tPtStr, 1, spacePos);
        i := i + 1;
      until (False)
    end;



    begin
      SetupSRL;
      tpa:=strToTPtArray('610,73 610,74 610,75 610,76 610,77 611,77 611,78');
      tp:=MidPointOfLine(TPA);
      writeln(inttostr(tp.x)+','+inttostr(tp.y));
    end.

    but it doesn't work due to the way it finds the closet point to the average of points. I didn't want to have to go this far, but it looks like I will have to determine whether the door is north-south or east-west first. If the x coords are in a close range, pick the middle of the ys, and vice versa. If the door is diagonal, I can use the old method of averaging both x and y.

    Once I have whether they are vertical or horizontal, and a point for each door, I can look at which is the eastern most, second western most, etc, and use this information to get around lumbridge castle (see thread in free scripts section).

    Edit: I overcomplicated things as usual. I don't even need to look at the value of the TPoints.x and y. FindColorsTolerance puts the points in order for me. I need only look at the indexes of the TPoint Array and get the middle one.

    SCAR Code:
    program New;
    {.include SRL/SRL.scar}
    var tpa:tpointarray;
    Tp:tpoint;
    function MidPointOfLine(TheArray:array of Tpoint):Tpoint;
    begin
      result:=TheArray[round(getarraylength(TheArray)/2)-1];
    end;


     function strToTPtArray(tPtStr: string): TPointArray;
    var
      i, commaPos, spacePos: Integer;
    begin
      repeat
        SetArrayLength(Result, i + 1);
        commaPos := Pos(',', tPtStr);
        spacePos := Pos(' ', tPtStr);
        Result[i].x := StrToInt(Copy(tPtStr, 1, commaPos - 1));
        if (not (spacePos = 0)) then
        begin
          Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, spacePos - commaPos -
            1));
        end
        else
        begin
          Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, Length(tPtStr)));
          break;
        end;
        Delete(tPtStr, 1, spacePos);
        i := i + 1;
      until (False)
    end;

    begin
      SetupSRL;
      tpa:=strToTPtArray('610,73 610,74 610,75 610,76 610,77 611,77 611,78');
      tp:=MidPointOfLine(TPA);
      writeln(inttostr(tp.x)+','+inttostr(tp.y));
    end.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [Tut][Vid][SRL3.00] - FindColorSkipBox and FindColorSkipBoxArray
    By Freddy1990 in forum OSR Outdated Tutorials
    Replies: 38
    Last Post: 11-16-2007, 09:49 PM

Posting Permissions

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