I'm attempting to build a multi-shape index in Python. The shapes are recognized using OpenCV and a CNN, yielding x, y, w, h, class and dominant color of the shape. The shapes move around and position changes are captured in real-time.
In order to work with the shapes, I'm thinking that the coordinates (x,y) might be the best choice for an index. I'm now looking for an updatable data structure with fast lookup by coordinates. The datastructure should have a well-tested Python implementation and support the following operations (fast):
- Store object A with coordinates (x0, y0)
- Retrieve closest object to coordinates (x,y) (returns object O)
- Update object A with previous coordinates (x0,y0) for new position (x1,y1)
- Delete object A with previous coordinates (x1,y1)
I've looked at scipy.spatial.KDTree
but it doesn't support updates. Theoretically R*-Trees would be an adequate choice (correct me if I'm wrong), but I can't find a Python library that explicitely claims to have fast updates.
Which libraries should I look at? Alternative solutions for the given problem are welcome as well.