# Mapping Camera Coordinates to a 2D Floor Plan

**URL:** https://discourse.processing.org/t/mapping-camera-coordinates-to-a-2d-floor-plan/16539
**Category:** Libraries
**Created:** [December 20, 2019, 4:06pm UTC](https://discourse.processing.org/t/mapping-camera-coordinates-to-a-2d-floor-plan/16539 "2019-12-20T16:06:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ql\_tan](https://avatars.discourse-cdn.com/v4/letter/q/2bfe46/32.png) [@ql\_tan](https://discourse.processing.org/u/ql_tan)
#### Post date: [December 20, 2019, 4:06pm UTC](https://discourse.processing.org/t/mapping-camera-coordinates-to-a-2d-floor-plan/16539/1 "2019-12-20T16:06:32Z")

</div>

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: [https://zbigatron.com/mapping-camera-coordinates-to-a-2d-floor-plan/](https://zbigatron.com/mapping-camera-coordinates-to-a-2d-floor-plan/) that shows how to do it in python, i was wondering anyone know how to do this using only processing?

Many thanks in advance!

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [December 20, 2019, 5:29pm UTC](https://discourse.processing.org/t/mapping-camera-coordinates-to-a-2d-floor-plan/16539/2 "2019-12-20T17:29:07Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ql\_tan](https://avatars.discourse-cdn.com/v4/letter/q/2bfe46/32.png) [@ql\_tan](https://discourse.processing.org/u/ql_tan)
#### Post date: [December 20, 2019, 5:47pm UTC](https://discourse.processing.org/t/mapping-camera-coordinates-to-a-2d-floor-plan/16539/3 "2019-12-20T17:47:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [December 20, 2019, 8:28pm UTC](https://discourse.processing.org/t/mapping-camera-coordinates-to-a-2d-floor-plan/16539/4 "2019-12-20T20:28:07Z")

</div>

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.

- [WarpPerspective.pde](https://github.com/atduskgreg/opencv-processing/blob/master/examples/WarpPerspective/WarpPerspective.pde) … you can also check out the MarkerDetection example
  - OpenCV docs: [warpPerspective](https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#warpperspective)
  - optionally, further past discussion of [using warpPrespective directly](https://forum.processing.org/two/discussion/26107/opencv-perspective-transformation-and-region-of-interest)

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”):

- BoofCV for Processing [RemovePerspective.pde](https://github.com/lessthanoptimal/BoofProcessing/blob/master/examples/RemovePerspective/RemovePerspective.pde)
  - BoofCV docs: [Remove Perspective Distortion](https://boofcv.org/index.php?title=Example_Remove_Perspective_Distortion) | [RemovePerspectiveDistortion](http://boofcv.org/javadoc/boofcv/alg/distort/RemovePerspectiveDistortion.html)

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

```auto
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](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.

> **[allesblinkt/Laserschein](https://github.com/allesblinkt/Laserschein/)**
>
> A Processing library for controlling laser projectors (ILDA) - allesblinkt/Laserschein

- [https://github.com/allesblinkt/Laserschein/blob/master/src/laserschein/Homography.java](https://github.com/allesblinkt/Laserschein/blob/master/src/laserschein/Homography.java)

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

- [https://github.com/davidbouchard/keystone](https://github.com/davidbouchard/keystone)
  - [Urgent help using Keystone Library](https://discourse.processing.org/t/urgent-help-using-keystone-library/2758/7)

* * *

See also related pasts discussions:

- [Tracking user location in a physical grid using a webcam?](https://discourse.processing.org/t/tracking-user-location-in-a-physical-grid-using-a-webcam/14607)
- [Planar equation from camera image](https://discourse.processing.org/t/planar-equation-from-camera-image/8164)

---

<div class="post-metadata">

### Author: ![ql\_tan](https://avatars.discourse-cdn.com/v4/letter/q/2bfe46/32.png) [@ql\_tan](https://discourse.processing.org/u/ql_tan)
#### Post date: [December 21, 2019, 12:24pm UTC](https://discourse.processing.org/t/mapping-camera-coordinates-to-a-2d-floor-plan/16539/5 "2019-12-21T12:24:33Z")

</div>

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
