Skip to content

Commit

Permalink
add helper function to convert camera coords -> metric world coords
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Echtler <floe@butterbrot.org>
  • Loading branch information
floe authored and zarvox committed Oct 15, 2011
1 parent 4feb5e7 commit e02a2ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/libfreenect-registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ typedef struct {
FREENECTAPI freenect_registration freenect_copy_registration(freenect_device* dev);
FREENECTAPI int freenect_destroy_registration(freenect_registration* reg);

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

#ifdef __cplusplus
}
Expand Down
10 changes: 10 additions & 0 deletions src/registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ static void complete_tables(freenect_registration* reg) {
freenect_init_registration_table( reg->registration_table, &(reg->reg_info) );
}

/// camera -> world coordinate helper function
void freenect_camera_to_world(freenect_device* dev, int cx, int cy, int wz, double* wx, double* wy)
{
double ref_pix_size = dev->registration.zero_plane_info.reference_pixel_size;
double ref_distance = dev->registration.zero_plane_info.reference_distance;
double factor = ref_pix_size * wz / ref_distance;
*wx = (double)(cx - DEPTH_X_RES/2) * factor;
*wy = (double)(cy - DEPTH_Y_RES/2) * factor;
}

/// Allocate and fill registration tables
/// This function should be called every time a new video (not depth!) mode is
/// activated.
Expand Down

0 comments on commit e02a2ec

Please sign in to comment.