Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for matching position and size of two rectangles

I'm looking for a algorithm that computes the following: I have an image with a predefined area (the green one on the attached image). The user draws the red rectangle and the algorithm should compute whether the red rectangle matches approximately the green one. For example the position of the red rectangle on the attached picture would be ok.

What is a good way to compute this? Is there any best practice algorithm?

My idea is to compute the middle of the red rectangle and then to determine whether the middle is inside the green rectangle. In addition, I would calculate if the length and height match approximately the length and height of the green one (25% more or less).

Is this a good idea? Any other suggestion?

enter image description here

like image 230
Rose Nettoyeur Avatar asked Sep 15 '16 08:09

Rose Nettoyeur


1 Answers

Compute the area of the intersection and divide by the average of the areas of the two rectangles (arithmetic or geometric). You will get a fraction. The closer to 1, the better the match.

like image 176
Yves Daoust Avatar answered Sep 22 '22 16:09

Yves Daoust