SRL Archive - Suggestions

...new TPA function


bg5

2012-05-03 14:03:25

 (* Returns all points from TPA1 ,which are in given distance from any point of TPA2*)

procedure FilterTPADistTPA(var TPA1: TPointArray; const MinDist,
MaxDist: Extended; TPA2 : TPointArray);

I call this method color plaiting ,because it can filter one object ,which contains two or more different colors, from bunch of similar colored pixels. It's very simple ,but efficient. I wish this function to be added into Simba's core ,of course main reason is speed. :stirthepot:

Example:
You want to find upper-right object
  FindColorstolerance(TPA1,2366701,1,1,w-1,h-1,0); //red
FindColorstolerance(TPA2,969215,1,1,w-1,h-1,0); // orange
FilterTPADistTPA(TPA1,0,3,TPA2);
DrawTPABitmap(bmp,TPA1,clwhite);

procedure FilterTPADistTPA(var TPA1: TPointArray; const MinDist,
MaxDist: Extended; TPA2 : TPointArray);
var
c,i,j,h,hh : integer;
d : extended;
mind ,maxd :extended;
begin
h := high(TPA1);
hh := high(TPA2);
c := 0;
mind := sqr(MinDist);
maxd := sqr(MaxDist);
for i := 0 to h do
begin
for j := 0 to hh do
begin
d := sqr(TPA1[i].x - TPA2[j].x) + sqr(TPA1[i].y - TPA2[j].y);
if (d >= mind) and (d <= maxd) then
begin
TPA1[c] := TPA1[i];
inc(c);
break;
end;
end;
end;
setlength(TPA1,c);
end;


Example of ingame use - Lumbridge ducks:

I will combine colors of duck's head and duck's rump. As you see both colors are very popular in this place ( I use CTS 0).

But when I join them together…
    FindColorsTolerance(TPA1,3559229,MSX1,MSY1,MSX2,MSY2,14);
FindColorsTolerance(TPA2,8556950,MSX1,MSY1,MSX2,MSY2,20);
FilterTPADistTPA(TPA1,0,20,TPA2);
SplitTPAWrap(TPA1,30,ATPA);
SMART_ClearCanvas;
for a:= 0 to high(ATPA) do
SMART_DrawCircle(FALSE,MiddleTPA(ATPA[a]),20,FALSE,clred);
…I have 100% accuracy :)


–beginner5




This thread is outdated,because I've made plugin with those functions which is 1001x faster : http://villavu.com/forum/showthread.php?t=83795

begginer

2012-05-03 14:26:44

Very interesting tutorial. It's so helpful. I might try this too

xtrapsp

2012-05-03 14:36:53

Wait so it finds one FindColorsTolerance then another FindColorsTolerance? Can you explain a little more how it works?

Abu

2012-05-03 14:44:56

Wow, that is extremely accurate :blink:

Good job!

Joe

2012-05-03 16:47:48

I've always hated having to find 1 color for a TPA. This would be useful since everything in runescape has some sort of connection to the ground colors

shstiger2009

2012-05-03 16:52:13

So if I'm interpreting this correctly, you're just using 2 colors from 1 object, and the distance between those 2 colors (which on the duck is very small), to return the correct object you're looking for?

Is that correct or…?

ReadySteadyGo

2012-05-03 17:44:06

Like this a lot. I support it being added, may submit a pull request sometime tomorrow if there are no objections.

Edit: you can already do this pretty fast with a loop and NearbyPointInTPA. I think this is probably faster actually because you can break out of it upon finding a decent match.

Something along the lines of:
FindColorsTolerance(TPA1,3559229,MSX1,MSY1,MSX2,MSY2,14);
* * FindColorsTolerance(TPA2,8556950,MSX1,MSY1,MSX2,MSY2,20);

for i := 0 to High(TPA1) do
* if NearbyPointInTPA(TPA1[i], TPA2, 20) then // can't remember this, on phone
* begin
* * Duck := TPA1[i];
* * Break;
* end;

bg5

2012-05-03 18:54:15

So if I'm interpreting this correctly, you're just using 2 colors from 1 object, and the distance between those 2 colors (which on the duck is very small), to return the correct object you're looking for?

Is that correct or…?


Yes

Wait so it finds one FindColorsTolerance then another FindColorsTolerance? Can you explain a little more how it works?


If you don't understand just look into code ,it's quite simple.

Very interesting tutorial. It's so helpful. I might try this too

Thanks ,althougth all in all,it's not tutorial ,but request thread for Simba's devs :P
But I dissuade using this function unless it's not added in Simba (if ever) ,because on script-level it will be slow. If you want try it I recommend using this instead. ( this does exactly the same ,but it's faster from Pascalscript level)

Edit: you can already do this pretty fast with a loop and NearbyPointInTPA. I think this is probably faster actually because you can break out of it upon finding a decent match.


No, you can't do this faster ,unless it does something else.Everything ,which goes throught interpreter will be much slower ,then integral Simba's function.

Your code breaks at first pixel found ,and returns TPoint ,so it can find only first pixel of first object ,so it's very limited.

Narcle

2012-05-03 18:59:19

Instead of 2 TPAs what about a ATPA? Then output a TPA of the matching pixels from the parameters.

ReadySteadyGo

2012-05-03 19:16:16

No, you can't do this faster ,unless it does something else.Everything ,which goes throught interpreter will be much slower ,then integral Simba's function.

Your code breaks at first pixel found ,and returns TPoint ,so it can find only first pixel of first object ,so it's very limited.

I'm not sure I agree. Also, if anything it's a less limiting way of doing it because you can manipulate it how you want, that was just an example. Anyway, I'll write up a version that uses nearbypointintpa to achieve the same as in your example tomorrow and we can test. :)

Sir Ducksworthy

2012-05-04 00:37:17

Nice, even if the same thing can be achieved with Nearby I still think this should be added it would be nice to just have this as 1 function to cut down on code.

Paradoxium

2012-05-05 07:16:47

I love this on so many levels, great job!

Shatterhand

2012-05-05 07:40:16

Very nice, will try this out when Ill have some time. :)

Sir Ducksworthy

2012-05-07 04:57:51

It's very similar to one of my TPA method's, mine's a bit more complex tho.
I think it is effective how the orange and red are combined but the only downfall is when your dealing with a multitude of colors.
You see mine split's each color entered with RAaSTPA, Add the point's separately for each color into the array, Then the points for each end up in bunches depending on how far they are separated by RAasTPA, So It sorts everything by size from the biggest Multi SplitCluster of Colors and can also take into account a probability depending on selected colors such as red or yellow for example a chicken would need to have Red and white so red would need to be detected within a certain radius of the white to be counted as a probable Target otherwise it doesn't add the cluster into the array.



What I would like to do now I think would be to Mix mine with your's by doing all of the actions to get the specified radius's generated by the SortATPAFromSize function and then un split everything only in those area's to revert them to clusters so I can find the exact Middle of them efficiently with MiddleTPAEx! It's Brilliant

function FindTpa(HueModifier, SatModifier:TExtendedArray; Color, Tol, ColorCombo:TIntegerArray; Length1, Length2, xx1, yy1, xx2, yy2:Integer; Text, Option:TstringArray; RandomClicking, MakeShort:Boolean): Boolean;
var
Probability, ArrayLength, CTS, I,II: Integer;
TPA,StoreTPA: TPointArray;
ATPA: Array of TPointArray;
Uptextfound:boolean;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
For i := 0 to High(Color) do
begin
SetColorSpeed2Modifiers(HueModifier[i], SatModifier[i]);
if(FindColorsSpiralTolerance(x, y, StoreTPA, Color[i], xx1, yy1, xx2, yy2, Tol[i]))then
begin
RAaSTPA(StoreTPA, 60);
//Splitting Points once per Color Works best Because you have a higher probability of finding something with 2 colors on the same Area within a range
TPA := TPA+StoreTPA;
StoreTPA:=[];
end else
{*Color Combinations if we do not find for example the red on a chicken or the yellow on the feet inside a TPA it lowers the probability that the rest of the colors relate to a chicken and more likely
A hay bale or something this allows me to very accurately find Creatures or people or basically any item its sort of like TPA DTM Detection*}
For II:=0 to High(ColorCombo) do
if(i=ColorCombo[II])then
begin
Probability:=Probability+1;
if(Probability=High(ColorCombo)+1)then
begin
ColorComboDetected:=False;
Writeln('Didnt Find any Probable Color Combinations Exiting');
Exit;
end else
ColorComboDetected:=True;
break;
end;
end;
ATPA := TPAToATPA(TPA, 40);
SortATPAFromSize(ATPA, 40, true);
ColorToleranceSpeed(CTS);
DebugATPABounds(ATPA);
if(MakeShort)then
ArrayLength:= 2
else
ArrayLength:=High(ATPA);
For I := 0 to ArrayLength do
begin
Try
MiddleTPAEx(ATPA[i], x, y);
Except
//writeln('Something ****** up with middleTPAEx');
End;
mousespeed:=Randomrange(10,35);
MMouse(x, y, 0, 0);
mousespeed:=Randomrange(10,35);
GetMousePos(x, y);
For II := 0 to High(Text) do
If(WaitUpText(Text[II],200-(II*200)))then
begin
Uptextfound:=true;
break;
end;
if(Uptextfound)then
begin
if(RandomClicking)then
begin
Case Random(9) of
0..2: begin //**30% Right Click Chance**\\
Mouse(x,y,0,0,false);
if(WaitoptionMulti(Option, 200))then
begin
Result := True;
Break;
end;
end;
3..9: begin //**70% Left Click Chance**\\
Mouse(x,y,0,0,True);
Result := True;
Break;
end;
END;
end else
begin
Mouse(x,y,0,0,false);
if(WaitoptionMulti(Option, 200))then
begin
Result := True;
Break;
end;
Uptextfound:=false;
end;
end;
end;
end;

Abu

2012-05-07 07:28:41

Wow! That looks smexy leet!

One of you should make tutorials on this whether or not it gets in the SRL Include. I'd definitely want to see more examples of this 'in action' :D

Gala

2012-05-07 09:03:50

From: abu_jwka
Wow! That looks smexy leet!

One of you should make tutorials on this whether or not it gets in the SRL Include. I'd definitely want to see more examples of this 'in action' :D


If I am not wrong, he integrated this one in his ChickenKiller script. :)
(I mean leetsxc)

@topic
like your snippet. :)

bg5

2012-05-12 09:16:23

Thanks all for feedback ,if you want to try usage of this function ,please use this code: http://villavu.com/forum/showpost.php?p=1004359&postcount=10
This code doing exactly the same ,but is based on native simba's functions. FilterTPADistTPA is intended to be in core ,running this in interpreter will be extremely slow. This method process a bulk of iterations ,so must be done in fastest possible way.

@Narcle
Instead of 2 TPAs what about a ATPA? Then output a TPA of the matching pixels from the parameters.


You can easyly built that function just adding one line above:

for a := 0 to High(ATPA)-1 do
FilterTPADistTPA(ATPA[a],0,10,ATPA[a+1];
Result := ATPA[0];

@leetsxc nice work ,it's interesting and also quite complex ,so I need some time to undestand:)

Just little suggestion, instead of
    if(MakeShort)then
ArrayLength:= 2
else
ArrayLength:=High(ATPA);

    if(MakeShort) and (High(ATPA)>=1)then
ArrayLength:= 2
else
ArrayLength:=High(ATPA);
so you don't need try except block.


*******************************************************************************

Just for coherence with other TPA functions ,the one which uses rectangle:

procedure FilterTPADistTPAEx(var TPA1: TPointArray; const w,h: integer; TPA2 : TPointArray);
var
c,i,j,h1,h2 : integer;
d : extended;
begin
h1 := high(TPA1);
h2 := high(TPA2);
c := 0;

for i := 0 to h1 do
begin
for j := 0 to h2 do
begin
if (abs(TPA1[i].x - TPA2[j].x) <= w ) and (abs(TPA1[i].y - TPA2[j].y) <= h ) then
begin
TPA1[c] := TPA1[i];
inc(c);
break;
end;
end;
end;
setlength(TPA1,c);
end;

Maybe shorter name will be better? FilterTdT and FilterTdTEx ?

masterBB

2012-05-12 11:43:18

added FilterTPADistTPA:

simba.exe


If people will test this I can make a pull request to the simba main branch.

litoris

2012-05-12 12:11:55

@beginner5
I used the code here, there doesn't seem to be a procedure called ClearSamePoints. Are there any alternatives for that? ClearSameIntegersAndTPA perhaps?

bg5

2012-05-12 12:50:04

From: litoris
@beginner5
I used the code here, there doesn't seem to be a procedure called ClearSamePoints. Are there any alternatives for that? ClearSameIntegersAndTPA perhaps?


ClearDoubleTPA. I made this snippet before this was added.

But better try Simba with inbuild FilterTPADistTPA ,which MasterBB posted above :)

masterBB

2012-05-12 12:50:55

No one tried my simba version yet?

From: litoris
@beginner5
I used the code here, there doesn't seem to be a procedure called ClearSamePoints. Are there any alternatives for that? ClearSameIntegersAndTPA perhaps?


ClearDoubleTPA(Result);

edit:
ninja'd

litoris

2012-05-19 11:05:01

From: masterBB
No one tried my simba version yet?



I replace every single color finding function in the scripts I use with that, I would like to have the function added.

Enslaved

2012-10-28 05:10:43

From: xtrapsp
Wait so it finds one FindColorsTolerance then another FindColorsTolerance? Can you explain a little more how it works?


itis using pythagoras' therom to work out the distance - (co-ord geometry) then checking if they are close to each other, this is worked on every point and other point- the double for loop covers all combinations. if it is within distance, it is then stuck in the TPA to be outputted

footballjds

2014-01-03 15:41:04

i've accomplished the same thing in a different way in my scripts. instead of checking distance from points I create a box around a point and count the points in the box so it is more accurate in my mind. 0-16ms
what did i miss?