spatial relations between objects in python
Hello people, I am here to ask for an advice because, after surfing the web, I could not find myself a strategy.
I have to implement a script in python that states which are the spatial relations between objects (the objects are shapes).
So far I have a script that recognizes shapes in images using findContours() function and now I have to state which are the spatial relations between the object.
An example: I got that a is a triangle and b is a square, what is the realtion between a and b? Inside, Above, Below, NextTo, etc. I do this in order to obtain a graph containing the shapes and the spatial relations between them.
How could I do that? Which strategy would you advice me? Or, which package of python fits better the requirements?
Thanks in advance for your help!
Actually, after performing the contour operation, you can use the boundingRectangle() of each contour to define it's centerpoint and then compare indexes to eachother to define their spatial relation to eachother.
how can I state if a centerpoint is above (or below, next to, inside) another? what should be the condition?
Lets say you have center of object one stated as x1, y1 and center of object 2 as x2, y2. Than above, from the point of object 2 is defined as, if y2 < y1, below as y2 > y1, next to by x2 > or < x1 ... But seriously, if this spatial relation stuff is a problem for you, then I am wondering how you succeeded in getting the code to work up till now ...