Results 1 to 16 of 16

Thread: getShiftedPixels();

  1. #1
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,001
    Mentioned
    50 Post(s)
    Quoted
    500 Post(s)

    Default getShiftedPixels();

    AFAIK all of the pixelShift functions just give you an integer. I wanted the actual points (and bitmaps are weird), so I made this.
    It's surprisingly good at finding NPCs when combined with MM2MS().
    Simba Code:
    function getShiftedPixels(b: TBoxArray; time: integer): TPointArray;
    var
      i: integer;
      cols1, cols2: TIntegerArray;
      tpa: TPointArray;
    begin
      tpa := b.toTPA();
      cols1 := getColors(tpa, false);
      wait(time);
      cols2 := getColors(tpa, false);
      for i := 0 to high(tpa) do
        if cols1[i] <> cols2[i] then result.append(tpa[i]);
    end;

  2. #2
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,611
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Nice. You could use inbuilt Simba functions to speed up the process.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  3. #3
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,001
    Mentioned
    50 Post(s)
    Quoted
    500 Post(s)

    Default

    Quote Originally Posted by Daniel View Post
    Nice. You could use inbuilt Simba functions to speed up the process.
    Wait how would that work? There's just one TPA.

  4. #4
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    I actually think this is a really clever idea, never thought of it before, but as with what Daniel said, is it slow? I could see speed being an issue..
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

  5. #5
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,001
    Mentioned
    50 Post(s)
    Quoted
    500 Post(s)

    Default

    Quote Originally Posted by elfyyy View Post
    I actually think this is a really clever idea, never thought of it before, but as with what Daniel said, is it slow? I could see speed being an issue..
    It's plenty fast for me. I'm using 50ms and it feels instant.

    edit: @elfyyy @Daniel
    This is on my crappy laptop using
    Simba Code:
    getShiftedPixels([mainscreen.getBounds()], 100);
    Takes about 40ms to get the entire mainscreen, which is only 222k integers to compare in the WORST possible case. It's very easy to reduce that number.


    The fact that it's so simple makes me feel both very smart and very stupid. @bonsai This will make auto-coloring so easy.

  6. #6
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    769
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    You made a basic motion detector. We had a thread about it a while back.

    That's how the motion detect in bonsaifighter works too but I used bitmaps. I also used the "motion colors" to pre-seed the color list.

  7. #7
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,001
    Mentioned
    50 Post(s)
    Quoted
    500 Post(s)

    Default

    Quote Originally Posted by bonsai View Post
    You made a basic motion detector. We had a thread about it a while back.

    That's how the motion detect in bonsaifighter works too but I used bitmaps. I also used the "motion colors" to pre-seed the color list.
    I saw that you used pixelshift but I didn't look thoroughly enough to see exactly what it was doing. I figured you must have been doing something like this. What are the advantages of bitmaps? I was a little confused when I looked at some of the functions in Simba.
    I've been running a 150-line combat script with this all day and it can compete with my 1k line auto-color script. It kinda feels wrong..
    I'll probably start a new auto-color script using SRL-6 CTS2 functions once I mess with this a bit more.

  8. #8
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    769
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    I saw that you used pixelshift but I didn't look thoroughly enough to see exactly what it was doing. I figured you must have been doing something like this. What are the advantages of bitmaps? I was a little confused when I looked at some of the functions in Simba.
    I've been running a 150-line combat script with this all day and it can compete with my 1k line auto-color script. It kinda feels wrong..
    I'll probably start a new auto-color script using SRL-6 CTS2 functions once I mess with this a bit more.
    It's two ways of getting at the same data. I guess it would come down to performance. getcolors is looking at the screen bitmap too. To get best performance, which may be needed, a plugin would be best. That way it can work outside the interpreter.

    The problem with motion is it requires the npc to move! And you need to filter out the false results like streams or lights.

    For best motion detection you need to look at multiple snaps and keep merging things into a background image. See how cool slacky's demo was in that other thread. That's what you get from background analysis. But of course the second you move it all goes out the window.

    Let me know what problems you're having with bitmaps. Here's a bitmap version of your snip. Start it when already logged in:

    Simba Code:
    program motion;
    {$DEFINE SMART}
    {$include_once srl-6/srl.simba}
    var
       orig, current, diff, w, h, x, y: integer;

    begin
       smartPlugins := ['d3d9.dll'];
       smartEnableDrawing := true;
       SetupSRL();
       GetClientDimensions(w, h);
       SmartSetEnabled(__smartCurrentTarget, false);
       while (true) do
       begin
          orig := BitmapFromClient(0, 0, w-1, h-1);
          wait(60);
          current := BitmapFromClient(0, 0, w-1, h-1);
          diff := CreateBitmap(w, h);
          for x := 0 to w-1 do
             for y := 0 to h-1 do
                if (FastGetPixel(orig, x, y) <> FastGetPixel(current, x, y)) then
                   FastSetPixel(diff, x, y, 255);
                   
          smartImage.drawBitmap(diff, point(0, 0));
          FreeBitmap(orig);
          FreeBitmap(current);
          FreeBitmap(diff);
       end;
    end.
    Last edited by bonsai; 09-20-2015 at 10:45 AM.

  9. #9
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,001
    Mentioned
    50 Post(s)
    Quoted
    500 Post(s)

    Default

    Quote Originally Posted by bonsai View Post
    It's two ways of getting at the same data. I guess it would come down to performance. getcolors is looking at the screen bitmap too. To get best performance, which may be needed, a plugin would be best. That way it can work outside the interpreter.

    The problem with motion is it requires the npc to move! And you need to filter out the false results like streams or lights.

    For best motion detection you need to look at multiple snaps and keep merging things into a background image. See how cool slacky's demo was in that other thread. That's what you get from background analysis. But of course the second you move it all goes out the window.

    Let me know what problems you're having with bitmaps. Here's a bitmap version of your snip. Start it when already logged in:
    Non-movings npcs don't seem to be a problem in RS3. They all move a little even when they're standing still.
    Filtering out non-npcs is easy with MM2MS();

    I was getting confused by calculatePixelShift(), but your code helped. I did a little demo using this:
    Simba Code:
    procedure pixels3(b: TBoxArray; time: integer);
    var
      orig, curr, diff: TIntegerArray;
      w, h, x, y, i: integer;
    begin
      setLength(orig, length(b));
      setLength(curr, length(b));
      setLength(diff, length(b));

      for i := 0 to high(b) do
        orig[i] := bitmapFromClient(b[i]);

      wait(time);

      for i := 0 to high(b) do
        curr[i] := bitmapFromClient(b[i]);

      for i := 0 to high(b) do
      begin
        w := b[i].getWidth();
        h := b[i].getHeight();
        diff[i] := createBitmap(w, h);
        for x := 0 to w-1 do
          for y := 0 to h-1 do
            if (fastGetPixel(orig[i], x, y) <> fastGetPixel(curr[i], x, y)) then
              fastSetPixel(diff[i], x, y, clLime);

        smartImage.drawBitmap(diff[i], point(b[i].x1, b[i].y1));
        smartImage.drawBox(b[i], false, clBlue);
      end;

      freeBitmaps(orig);
      freeBitmaps(curr);
      freeBitmaps(diff);
    end;


  10. #10
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,611
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Wait how would that work? There's just one TPA.
    Disregard what I said. For some reason, I thought GetColors returned a TPA and I didn't bother to check the data types. Geez, it's been a while.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  11. #11
    Join Date
    Oct 2011
    Posts
    804
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    @Citrus @Floor66

    I've made once aplugin for motion detection, doing exactly the same, and it seems I've never published it on SRL :P So here is it:

    CompareBmp.rar

    Simba Code:
    procedure CompareBmp( BitmapAreaColors1, BitmapAreaColors2 : T2dIntegerArray; MaxSize : integer; var _Result : TPointArray );


    Simba Code:
    function GetShiftedTPA ( Box : TBox; WaitTime : integer) : TPointArray;
    var bmp1, bmp2 , w ,h : integer;
    var BAC1,BAC2 :T2dIntArray;
    begin

    w := Box.x2 - Box.x1 - 1;
    h := Box.y2 - Box.y1 - 1;
    bmp1 :=  BitmapFromClient(Box.x1 , Box.y1 , Box.x2 , Box.y2);
    BAC1 :=  GetBitmapAreaColors(bmp1,0,0,w,h);
    wait (WaitTime);
    bmp2 :=  BitmapFromClient(Box.x1 , Box.y1 , Box.x2 , Box.y2);
    BAC2 :=  GetBitmapAreaColors(bmp1,0,0,w,h);

    CompareBmp(BAC1,BAC2,(w*h) div 2,Result);   //  (w*h) div 2  - means MaxSize is a half of box

    FreeBitmap(bmp1);
    FreeBitmap(bmp2);
    end;


    * What is MaxSize parameter? Sometimes it happens that colors in the whole screen are shifted e.x. due to some random overall brightness change. In this erroneousness situation function will detect that number of shifted pixels is too big and it will return an empty array ( of the length of 1 ).s
    Last edited by bg5; 09-22-2015 at 10:10 AM.

  12. #12
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Very interesting! I'm going to do some benchmarking :-)
    Ce ne sont que des gueux


  13. #13
    Join Date
    Oct 2011
    Posts
    804
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

  14. #14
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    968
    Mentioned
    142 Post(s)
    Quoted
    582 Post(s)

    Default

    Quote Originally Posted by bg5 View Post
    @Citrus @Floor66

    I've made once aplugin for motion detection, doing exactly the same, and it seems I've never published it on SRL :P So here is it:

    CompareBmp.rar

    Simba Code:
    procedure CompareBmp( BitmapAreaColors1, BitmapAreaColors2 : T2dIntegerArray; MaxSize : integer; var _Result : TPointArray );
    Simba has bultin function named `CalculatePixelShift` which pretty much just counts the diff pixels between 2 bitmaps (there are a few others methods for this purpose in simba swell). So I am not sure what good this will do.
    !No priv. messages please

  15. #15
    Join Date
    Oct 2011
    Posts
    804
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Quote Originally Posted by slacky View Post
    Simba has bultin function named `CalculatePixelShift` which pretty much just counts the diff pixels between 2 bitmaps (there are a few others methods for this purpose in simba swell). So I am not sure what good this will do.
    It doesn't count pixels, it returns TPA. TPA can be used then for further processing, much better and more flexible option then simple number of pixels on output (as OP mentioned).
    Last edited by bg5; 09-22-2015 at 05:43 PM.

  16. #16
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    968
    Mentioned
    142 Post(s)
    Quoted
    582 Post(s)

    Default

    Quote Originally Posted by bg5 View Post
    It doesn't count pixels, it returns TPA. TPA can be used then for further processing, much better and more flexible option then simple number of pixels on output (as OP mentioned).
    Aha, my bad. Didn't read over your post properly.
    !No priv. messages please

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
  •