T O P I C R E V I E W |
AndyColmes |
Posted - Aug 05 2014 : 10:48:23 I have an application that automatically create a lot of small rectangle objects on an image with ImageEn. I am looking for a way to be able to be able to combine the rectangles based on how close they are together with some kind of tolerance I guess to make them into a bigger rectangle. For example, if there are 4 rectangles very close to each other or sometimes even overlapping, I would like to be able to make them into 1 rectangle using the furthest coordinates from the 4 rectangles to create that 1 rectangle.
How would I do this?
Thanks in advance.
Andy
|
8 L A T E S T R E P L I E S (Newest First) |
AndyColmes |
Posted - Aug 13 2014 : 02:29:32 Hi Nigel,
Thanks for InflateRect. That might come in handy.
Andy
|
xequte |
Posted - Aug 10 2014 : 16:00:36 Yes, IntersectRect is good if you are looking for rects that overlap. You could use InflateRect (before calling IntersectRect) to enlarge your source rect if you also want to also find rects that are close but not overlapping.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
AndyColmes |
Posted - Aug 09 2014 : 22:29:24 Hi Roy,
That's an idea. I will give it a shot. Thanks very much, Roy.
Andy
|
rmklever |
Posted - Aug 08 2014 : 15:23:43 Hi Andy,
You can expand all your rectangles with the tollerance and then iterate all recangles with IntersectRect. If they intersect you just combine them.
This is one way of doing it.
Roy M Klever Klever on Delphi - www.rmklever.com |
AndyColmes |
Posted - Aug 06 2014 : 22:37:51 Thanks Nigel. I will do that and maybe report back in case other users are looking for something similar. |
xequte |
Posted - Aug 06 2014 : 18:45:05 Hi Andy
OK, it's not really an ImageEn question, but rather a general programming issue, so you might get better advice from a wider programming audience (say stackoverflow.com).
But in short, you would iterate through all the rectangle objects, for each count the number of objects that are "close" (using whatever overlap function suits) and if the close object count >=4 then remove the objects and create a new object of a size of the outermost bounds of the removed objects. Then iterate through the objects again, repeating until a complete iteration does not generate any new rectangles.
The process itself would not be the complex, with the only real logic going into the "find close objects" routine. That would involve a sub function that iterates through all objects and finds the first object that is within the bounds + threshold of our source object. Of course, because you will call this function repeatedly you would need to have an exclusion list (those already found) or better, commence iteration from the index of the last found. Call this sub-function repeatedly until it does not return any new rectangles.
Anyway, that's just off the top of my head. As mentioned, you may get better advice from some guru on stackoverflow.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
AndyColmes |
Posted - Aug 06 2014 : 11:28:51 Hi Nigel,
Yes, I am using TImageVect with rectangles as vect objects. Is this good?
Thanks Nigel.
Andy
|
xequte |
Posted - Aug 05 2014 : 19:39:14 Hi Andy
Are you using a TImageEnVect, with the rectangles being vect objects?
Nigel Xequte Software www.xequte.com nigel@xequte.com
|