SRL Archive - OSR Help

Help Finding Two Colors Near Each Other


YoHoJo

2013-03-22 07:22:25

Let's say I have a tree, green on top, brown on bottom, and there is NO OVERLAP of the colors, one ends, the other begins.
Or another example, a reg blob on top of a green blob, they do not overlap at all.

How would I go about finding this object in general, or the section at which the two colors meet.

Ex:

I just want to find the object in general, or where the blue rectangle is.


ACTUAL code along with comments is greatly appreciated!


Guess?
Make a TPA of both, then ATPA of both, then compare distances between ATPAColor1 and ATPAColor2?

J J

2013-03-22 07:31:50

procedure FindObject;
var
TPA1, TPA2, TPA3: TPointArray;
i, L: Integer;

begin
//NearbyPointInArray(Point, Dist, TPA);
for i:=0 to high(TPA1) do
if NearbyPointInArray(TPA1[i], 10, TPA2) then
begin
L := Length(TPA3);
SetLength(TPA3, L+1);
TPA3[L] := TPA1[i];
end;

end;

TPA1: Red color of your drawing found by using FindColorsTolerance blablabla
TPA2: Green color found the same way

TPA3 is the area where they overlap at any points. You can then split TPA3 to find the largest match.
So all in all something like this

procedure FindObject;
var
TPA1, TPA2, TPA3: TPointArray;
i, L: Integer;
ATPA: T2DPointArray;
P: TPoint;

begin
//NearbyPointInArray(Point, Dist, TPA);
for i:=0 to high(TPA1) do
if NearbyPointInArray(TPA1[i], 10, TPA2) then
begin
L := Length(TPA3);
SetLength(TPA3, L+1);
TPA3[L] := TPA1[i];
end;

if L > 0 then
begin
SplitTPAWrap(TPA3, 5, ATPA);
SortATPASize(ATPA, True);
P := MiddleTPA(ATPA[0]);
end;

end;

YoHoJo

2013-03-22 07:34:35

Ahh I sort of see what you are doing there, very neat!
It takes me a few reads/sample scripts/debug screens to understand ATPAs sometimes, but I can see what is going on here!
I'll give that some sample runs tomorrow and report back with results!

Everyone else feel free to add onto/tweak what JJ said or post your own ideas too!

@JJ brilliant! Working perfectly!

litoris

2013-03-22 08:25:52

function AND_TPA (tpa1 , tpa2 :TpointArray ; MinDist ,MaxDist : extended) : TPointArray;
var
a : integer;
temp_tpa1 :TPointarray;
begin
Setlength(Result,0);
for a:=0 to High(tpa2) do
begin
temp_tpa1 := tpa1;

FilterPointsDist(temp_tpa1,MinDist,MaxDist,tpa2[a].x,tpa2[a].y);

CombineTPAWrap(Result,temp_tpa1,Result);
end;
ClearDoubleTPA(Result);
end;
I just copied this off from my miner, This is a version of something beginner5 posted a while ago in the snippets section.
I use this on mining rocks, trees etc. and it works well when there are similar colored objects around. Picking colors is a pain in the ass tough.