Skip to content

Commit e02a2ec

Browse files
floezarvox
authored andcommitted
add helper function to convert camera coords -> metric world coords
Signed-off-by: Florian Echtler <[email protected]>
1 parent 4feb5e7 commit e02a2ec

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

include/libfreenect-registration.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ typedef struct {
117117
FREENECTAPI freenect_registration freenect_copy_registration(freenect_device* dev);
118118
FREENECTAPI int freenect_destroy_registration(freenect_registration* reg);
119119

120+
// convenience function to convert a single x-y coordinate pair from camera
121+
// to world coordinates
122+
FREENECTAPI void freenect_camera_to_world(freenect_device* dev,
123+
int cx, int cy, int wz, double* wx, double* wy);
120124

121125
#ifdef __cplusplus
122126
}

src/registration.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ static void complete_tables(freenect_registration* reg) {
314314
freenect_init_registration_table( reg->registration_table, &(reg->reg_info) );
315315
}
316316

317+
/// camera -> world coordinate helper function
318+
void freenect_camera_to_world(freenect_device* dev, int cx, int cy, int wz, double* wx, double* wy)
319+
{
320+
double ref_pix_size = dev->registration.zero_plane_info.reference_pixel_size;
321+
double ref_distance = dev->registration.zero_plane_info.reference_distance;
322+
double factor = ref_pix_size * wz / ref_distance;
323+
*wx = (double)(cx - DEPTH_X_RES/2) * factor;
324+
*wy = (double)(cy - DEPTH_Y_RES/2) * factor;
325+
}
326+
317327
/// Allocate and fill registration tables
318328
/// This function should be called every time a new video (not depth!) mode is
319329
/// activated.

0 commit comments

Comments
 (0)