Mapping Camera Coordinates to a 2D Floor Plan

Hey everyone, I’m using openCV for processing to track human movements in a camera scene and Im struggling to translate the tracked coordinates caught in the camera scene onto a 2D floorplane.

I found this link: that shows how to do it in python, i was wondering anyone know how to do this using only processing?

Many thanks in advance!

1 Like

What are your input points? Are they taken from the base of the feet, or the centroid of the silhouette, or is this an overhead camera and you are tracking the tops of heads?

Thanks for replying, they are taken from the base of the feet

Great! There are many ways of tackling this problem – in OpenCV for Processing, or BoofCV, or using an existing third party library, or rolling your own.

1. Perspective

If you want the simplest way, just preprocess your image with WarpPerspective. Note that in openCV, warpPerspective is the same as projective transformation / homography – it is a transform of any quad into any other quad.

Now you can run openCV on a 2D representation of the image data, and the coordinates of what you detect will automatically be in the floor plan space.

You can also do this using BoofCV with RemovePerspective (“Given 4 corners of a shape which is known to be rectangular, remove the perspective distortion from it”):

2. Compute points for homography

If, on the other hand, you want to run detection on the raw uncorrected feed and then convert points to floor plan space after the fact, then you want to create a projective homography between quad A and B, and use point-in, point-out.

In OpenCV for Processing, creating the homography itself is accessed through

import org.opencv.calib3d.Calib3d;
Calib3d.findHomography( ... )

For discussion of the implementation, see

But if you just want a pre-written implementation that should work, download and install the Laserschein library (untested!), and import the two classes Homography and HomographyMatrix. A Homography object will give you 4 + 4 points for a matrix, and then a point and inverse point mapping method – exactly what you want, all done with PVectors.

It might also be worth checking out the Keystone Library for Processing.

See also related pasts discussions:

1 Like

Thank you so much this is really helpful! The WarpPerspective seems to be the one I need since I’m not aiming for an accurate translation