SRL Archive - Jr. Member General Help and Discussion

Find boxes in TPA


Bixby Sayz

2013-11-19 11:11:28

Bit difficult to describe. I have a TPA that contains a series of points that make up the borders of 2 overlapping boxes. Something like this:
  +--+
+-++ |
+-++ |
+--+

I want to somehow "find" the 2 boxes in the TPA. Got a few ideas floating around in my head but thought I would "throw it out there" and see what comes back.

Edit: Diagram looks like crap once I posted. Fixed? diagram so it looks better.

footballjds

2013-11-19 11:26:15

From: Bixby Sayz
Bit difficult to describe. I have a TPA that contains a series of points that make up the borders of 2 overlapping boxes. Something like this:
  +--+
+-++ |
+-++ |
+--+

I want to somehow "find" the 2 boxes in the TPA. Got a few ideas floating around in my head but thought I would "throw it out there" and see what comes back.

Edit: Diagram looks like crap once I posted. Fixed? diagram so it looks better.


anymore info? maybe a screenshot of the object?

Bixby Sayz

2013-11-19 11:54:06

[ATTACH=CONFIG]22392[/ATTACH]

These points contain 2 boxes. I need the 2 boxes.

The human eye/brain can do this instantly. Doing it in a script not so much.

footballjds

2013-11-19 13:43:25

From: Bixby Sayz
[ATTACH=CONFIG]22392[/ATTACH]

These points contain 2 boxes. I need the 2 boxes.

The human eye/brain can do this instantly. Doing it in a script not so much.


are these going to be flat 2d boxes like this? if so, its a straightforward solution. the TPA's intersect, so find the boxes and find where they intersect

Olly

2013-11-19 13:43:38

Flood filling pops into my mind

Bixby Sayz

2013-11-19 14:16:58

From: footballjds
are these going to be flat 2d boxes like this? if so, its a straightforward solution. the TPA's intersect, so find the boxes and find where they intersect
I don't follow. Maybe I'm just being dense. I have a single TPA.
so find the boxes
Isn't that what I am trying to do?

footballjds

2013-11-19 14:31:59

From: Bixby Sayz
I don't follow. Maybe I'm just being dense. I have a single TPA.
Isn't that what I am trying to do?


it'd be much easier if you'd give us an actual image.
Based on your image you posted i could EASILY tell you where the boxes are.

Bixby Sayz

2013-11-19 18:40:14

This is all the information I have to work with at this point: A bunch of points (represented by the white line in the image). I got an idea that might work. Thanks anyway.

bg5

2013-11-20 12:24:34




Short algoryth, I was bored for a while…
As Olly suggested I used floodfill.

The only inconvenience is that you need to predefine how many boxes is on the picture, but you haven't said you want to do it dynamically, so it's not a problem I hope?


program new;

var bmp,x,y,i,j,NumberOfBoxes,w,h,t:integer;
var TBA : TBoxArray;
var TPA : TPointArray;
begin

NumberOfBoxes := 2; // amount of boxes to find

bmp := BitmapFromString(445, 346, 'beNrt3FtuIkkQQFHjeq7' +
'C+18jL0+I0ISywe32gNG0K8/5QIw/RiI78pJVYL+8AAAAAAAAAAA' +
'AAAAAAADA9xqGoR7bJ9C5cRzjcZqm3BS73c6acDshy7KIJ9SOyMc' +
'wz3Nk8/X11cqQYhhiJOJdNcuZT6BndbaMI0Q002mTq3fVeg9tD5k' +
'76FhuinVdq5ZxonDaJB0v3huHwyEez9Cx3BR1LeaoSStm43Yq6pY' +
'O9Lw1ciMoJ1fijTWfzPNcHx1aFsjTZvtVE+WknY06XtaQuLtFz2p' +
'rxFEzN4Ubm1xlE/hka2gmsgmyiWyCbCKbIJvIJsgmsgmyiWwCsol' +
'sgmwimyCbyCbIJrIJsolsgmxiNgDZRDZBNpFNkE1kE2QT2QTZRDZ' +
'BNkE2QTaRTZBNZBNkE9kE2UQ2QTaRTbA1ZBPZBNlENkE2kU2QTWQ' +
'TZBPZBNlENgHZRDZBNpFNkE1kE2QT2QTZRDZBNjEbgGwimyCbyCb' +
'IJrIJsolsgmwimyCbIJsgm8gmyCayCbKJbIJsIpsgm8gm2BqyiWy' +
'CbCKbIJvIJsgmsgmyiWyCbCKbgGwimyCbyCbIJrIJsolsgmwimyC' +
'bmA2LALKJbIJsIpsgm8gmyCayCbKJbIJsWhBkE2QT2QTZRDZBNpF' +
'NkE1kE2QT2QRbQzaRTZBNZBNkE9kE2UQ2QTaRTZBNzAYgm8gmyCa' +
'yCbKJbIJsIpsgm3+JYRjqsX3CI7Ox+1c+73AdcpDGcawNMs+zM4a' +
'tsaXTZox3PC7LIp4POp/PVz+pfvZmmqbcIGrJ9rIZLyH2dQ55lDO' +
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AAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'ANu4fb59wOQ==');

GetBitmapSize(bmp,w,h);
i := 0;
while (i < NumberOfBoxes+1) do
begin
x:=random(w);
y:=random(h);
if FastGetPixel(bmp,x,y)=0 then
begin
inc(i);
FloodFillBitmap(bmp,Point(x,y),0,i);
writeln(i);
end;
end;

setlength(TBA,NumberOfBoxes);
t := GetImageTarget();
SetTargetBitmap(bmp);

for i:=0 to NumberOfBoxes do
begin
FindColors(TPA,i+1,0,0,w-1,h-1);
TBA[j] := GetTPABounds(TPA);
writeln((TBA[j].x2-TBA[j].x1));
if (TBA[j].x2-TBA[j].x1)< (w-6) then // this will eliminate background box
inc(j);
end;

SetImageTarget(t);
writeln(TBA);

end.

Bixby Sayz

2013-11-20 14:46:01

And this is why I asked. Knew someone more clever than I would come up with something. Thanks!!!

footballjds

2013-11-20 15:26:29

From: Bixby Sayz
And this is why I asked. Knew someone more clever than I would come up with something. Thanks!!!


i feel like i saw this thread somewhere else… :shifty: :whistling: