Mapping Camera Coordinates to a 2D Floor Plan

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 https://stackoverflow.com/questions/27972703/java-findhomography-transform-image-point-to-ground-plane-point

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