Ask Your Question
0

spatial relations between objects in python

asked 2014-01-24 07:14:08 -0600

Francesco Sgaramella gravatar image

updated 2014-01-24 07:37:24 -0600

berak gravatar image

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!

edit retag flag offensive close merge delete

Comments

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-01-24 07:38:47 -0600 )edit

how can I state if a centerpoint is above (or below, next to, inside) another? what should be the condition?

Francesco Sgaramella gravatar imageFrancesco Sgaramella ( 2014-01-24 08:13:38 -0600 )edit

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 ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-01-24 08:22:17 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-01-24 08:25:49 -0600

Francesco Sgaramella gravatar image

I was not gifted like you

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-01-24 07:14:08 -0600

Seen: 375 times

Last updated: Jan 24 '14