Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- {$I SimbaExt/SimbaExt.simba}
- function GetCorrelationInfo(Mat:TFloatMatrix; n:Int32; out midpt:TPoint): Double;
- var
- i,j:Int32;
- ATPA:T2DPointArray;
- TPA:TPointArray;
- Sums:TExtArray;
- begin
- TPA := Mat.ArgMax(n);
- if (Length(TPA) = 0) then Exit();
- ATPA := TPA.Cluster(4,False);
- SetLength(Sums, Length(ATPA));
- for i:=0 to High(ATPA) do
- for j:=0 to High(ATPA[i]) do
- Sums[i] := Sums[i] + Mat[ATPA[i][j].y, ATPA[i][j].x];
- j := Sums.ArgMax();
- Result := Sums[j];
- midpt := ATPA[j].Mean();
- end;
- procedure foo();
- const
- m: TPoint = [648, 83]; //Olly: I changed the coords to fit my rs client..
- outer: integer = 68;
- inner: integer = 42;
- angles = [-10, 0, 10];
- var
- bmpMap, bmp, canvas: TRafBitmap;
- RotatedBMP:Array [0..3] of TRafBitmap;
- i, t, incX, Size: integer;
- mid,mid1,mid2: TPoint;
- CorrA,CorrB,tmp,tmpB: TFloatMatrix;
- value1,value2:Double;
- TPA1,TPA2:TPointArray;
- begin
- bmpMap.Open('C:/Simba/Includes/runescape_surface07/12_9.png');
- bmp.FromClient(m.x - outer, m.y - outer, m.x + outer, m.y + outer);
- canvas.Create(600, 600, '');
- incX := 0;
- mid := Point(outer, outer);
- Size := inner * 2 + 1;
- //step 1 - gather smalls:
- RotatedBMP[0] := bmp.Rotate(radians(angles[0]), false);
- RotatedBMP[0].LazyCrop(mid.x - inner, mid.y - inner, mid.x + inner, mid.y + inner);
- RotatedBMP[1] := bmp.Rotate(radians(angles[1]), false);
- RotatedBMP[1].LazyCrop(mid.x - inner, mid.y - inner, mid.x + inner, mid.y + inner);
- RotatedBMP[2] := bmp.Rotate(radians(angles[2]), false);
- RotatedBMP[2].LazyCrop(mid.x - inner, mid.y - inner, mid.x + inner, mid.y + inner);
- //step 2 - correlate:
- tmp := se.MatchTemplate(bmpMap, RotatedBMP[1], TM_CCOEFF);
- tmpB := se.MatchTemplate(bmpMap, RotatedBMP[0], TM_CCOEFF);
- CorrA := tmp.Combine(tmpB);
- tmpB := se.MatchTemplate(bmpMap, RotatedBMP[2], TM_CCOEFF);
- CorrB := tmp.Combine(tmpB);
- //Debug and Free
- for i:=0 to 2 do begin
- FastDrawTransparent(incX, 0, RotatedBMP[i].bitmap, canvas.Bitmap);
- Inc(IncX, RotatedBMP[i].Width + 5);
- RotatedBMP[i].Free();
- end;
- Value1 := GetCorrelationInfo(CorrA, 35, mid1);
- Value2 := GetCorrelationInfo(CorrB, 35, mid2);
- WriteLn(Value1, ', ', Value2);
- if Value1 > Value2 then
- mid := mid1
- else
- mid := mid2;
- mid.Offset(Point(inner,inner));
- bmpMap.SetPixels(se.TPACross(mid, inner), 255);
- bmpMap.SetPixels(se.ConnectTPA(ToBox(mid.x-inner, mid.y-inner, mid.x+inner, mid.y+inner).ToCoords()), 255);
- FastDrawTransparent(0, Size + 5, bmpMap.Bitmap, canvas.Bitmap);
- canvas.Debug();
- canvas.Free();
- bmp.Free();
- bmpMap.Free();
- end;
- begin
- foo();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement