Advertisement
WarPie90

Untitled

Jun 6th, 2014
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.71 KB | None | 0 0
  1. program new;
  2. {$I SimbaExt/SimbaExt.simba}
  3.  
  4. function GetCorrelationInfo(Mat:TFloatMatrix; n:Int32; out midpt:TPoint): Double;
  5. var
  6.   i,j:Int32;
  7.   ATPA:T2DPointArray;
  8.   TPA:TPointArray;
  9.   Sums:TExtArray;
  10. begin
  11.   TPA := Mat.ArgMax(n);
  12.   if (Length(TPA) = 0) then Exit();
  13.   ATPA := TPA.Cluster(4,False);
  14.   SetLength(Sums, Length(ATPA));
  15.   for i:=0 to High(ATPA) do
  16.     for j:=0 to High(ATPA[i]) do
  17.       Sums[i] := Sums[i] + Mat[ATPA[i][j].y, ATPA[i][j].x];
  18.   j := Sums.ArgMax();
  19.   Result := Sums[j];
  20.   midpt := ATPA[j].Mean();
  21. end;
  22.  
  23.  
  24. procedure foo();
  25. const
  26.   m: TPoint = [648, 83];  //Olly: I changed the coords to fit my rs client..
  27.   outer: integer = 68;
  28.   inner: integer = 42;
  29.   angles = [-10, 0, 10];
  30. var
  31.   bmpMap, bmp, canvas: TRafBitmap;
  32.   RotatedBMP:Array [0..3] of TRafBitmap;
  33.   i, t, incX, Size: integer;
  34.   mid,mid1,mid2: TPoint;
  35.   CorrA,CorrB,tmp,tmpB: TFloatMatrix;
  36.   value1,value2:Double;
  37.   TPA1,TPA2:TPointArray;
  38. begin
  39.   bmpMap.Open('C:/Simba/Includes/runescape_surface07/12_9.png');
  40.  
  41.   bmp.FromClient(m.x - outer, m.y - outer, m.x + outer, m.y + outer);
  42.   canvas.Create(600, 600, '');
  43.   incX := 0;
  44.  
  45.   mid := Point(outer, outer);
  46.   Size := inner * 2 + 1;
  47.  
  48.   //step 1 - gather smalls:
  49.     RotatedBMP[0] := bmp.Rotate(radians(angles[0]), false);
  50.     RotatedBMP[0].LazyCrop(mid.x - inner, mid.y - inner, mid.x + inner, mid.y + inner);
  51.  
  52.     RotatedBMP[1] := bmp.Rotate(radians(angles[1]), false);
  53.     RotatedBMP[1].LazyCrop(mid.x - inner, mid.y - inner, mid.x + inner, mid.y + inner);
  54.  
  55.     RotatedBMP[2] := bmp.Rotate(radians(angles[2]), false);
  56.     RotatedBMP[2].LazyCrop(mid.x - inner, mid.y - inner, mid.x + inner, mid.y + inner);
  57.  
  58.   //step 2 - correlate:
  59.     tmp := se.MatchTemplate(bmpMap, RotatedBMP[1], TM_CCOEFF);
  60.  
  61.     tmpB := se.MatchTemplate(bmpMap, RotatedBMP[0], TM_CCOEFF);
  62.     CorrA := tmp.Combine(tmpB);
  63.  
  64.     tmpB := se.MatchTemplate(bmpMap, RotatedBMP[2], TM_CCOEFF);
  65.     CorrB := tmp.Combine(tmpB);
  66.  
  67.   //Debug and Free
  68.     for i:=0 to 2 do begin
  69.       FastDrawTransparent(incX, 0, RotatedBMP[i].bitmap, canvas.Bitmap);
  70.       Inc(IncX, RotatedBMP[i].Width + 5);
  71.       RotatedBMP[i].Free();
  72.     end;
  73.  
  74.   Value1 := GetCorrelationInfo(CorrA, 35, mid1);
  75.   Value2 := GetCorrelationInfo(CorrB, 35, mid2);
  76.   WriteLn(Value1, ', ', Value2);
  77.   if Value1 > Value2 then
  78.     mid := mid1
  79.   else
  80.     mid := mid2;
  81.  
  82.   mid.Offset(Point(inner,inner));
  83.  
  84.   bmpMap.SetPixels(se.TPACross(mid, inner), 255);
  85.   bmpMap.SetPixels(se.ConnectTPA(ToBox(mid.x-inner, mid.y-inner, mid.x+inner, mid.y+inner).ToCoords()), 255);
  86.  
  87.   FastDrawTransparent(0, Size + 5, bmpMap.Bitmap, canvas.Bitmap);
  88.   canvas.Debug();
  89.  
  90.   canvas.Free();
  91.   bmp.Free();
  92.   bmpMap.Free();
  93. end;
  94.  
  95.  
  96. begin
  97.   foo();
  98. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement