Advertisement
WarPie90

Example for PointsInRangeOf

May 14th, 2023 (edited)
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.64 KB | None | 0 0
  1. program new;
  2. {$DEFINE SRL_USE_REMOTEINPUT}
  3. {$I srl/osr.simba}
  4.  
  5. function FilterThing(sum, ref: TPointArray; splitdist: Int32): T2DPointArray;
  6. var
  7.   i,j: Int32;
  8.   refs, clusters: T2DPointArray;
  9. begin
  10.   clusters := sum.Cluster(splitdist);
  11.   refs     := ref.Cluster(splitdist);
  12.  
  13.   for i:=0 to High(clusters) do
  14.     for j:=0 to High(refs) do
  15.       if clusters[i].Find(refs[j][0]) <> -1 then
  16.         Result += clusters[i];
  17. end;
  18.  
  19.  
  20. var
  21.   i: Int32;
  22.   sum, pts1, pts2: TPointArray;
  23.   res: T2DPointArray;
  24. begin
  25.   RSClient.Image.Clear();
  26.   while True do
  27.   begin
  28.     //pts1 contains their red thingy on helment
  29.     srl.FindColors(pts1, CTS2(661879, 11, 0.12, 1.50), MainScreen.Bounds());
  30.  
  31.     //white body
  32.     srl.FindColors(pts2, CTS2(9475995, 30, 0.12, 0.09), MainScreen.Bounds());
  33.  
  34.     //get the helmet that is near a white body [within 10px distance]
  35.     //10px because distance to nearest part of body (white helmet part), it's not a long distance
  36.     pts1 := pts1.PointsInRangeOf(pts2, 0, 10);
  37.  
  38.     //get the body that is near a red helment [within 70px distance]
  39.     //70px because distance from feet to helmet may be large-ish.
  40.     pts2 := pts2.PointsInRangeOf(pts1, 0, 70);
  41.  
  42.     //combine body and helmet
  43.     sum  := pts1 + pts2;
  44.  
  45.     // magic to filter out shit that is not of part the body and helmet
  46.     // but can still be considered within 70px of the helment.
  47.     res := FilterThing(sum, pts1, 3);
  48.  
  49.     //draw to RSClient
  50.     RSClient.Image.Clear();
  51.     for i:=0 to High(res) do
  52.     begin
  53.       RSClient.Image.DrawTPA(res[i], 255);
  54.       RSClient.Image.DrawTPA(res[i].ConvexHull().Connect(), $FFFF00);
  55.     end;
  56.   end;
  57. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement