Skip to content

Commit

Permalink
add freenect_map_rgb_to_depth helper function (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
floe authored and fran6co committed Jun 9, 2014
1 parent 9b671cd commit a55cd43
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/libfreenect_registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ FREENECTAPI int freenect_destroy_registration(freenect_registration* reg);
FREENECTAPI void freenect_camera_to_world(freenect_device* dev,
int cx, int cy, int wz, double* wx, double* wy);

// helper function to map one FREENECT_VIDEO_RGB image to a FREENECT_DEPTH_MM
// image (inverse mapping to FREENECT_DEPTH_REGISTERED, which is depth -> RGB)
FREENECTAPI void freenect_map_rgb_to_depth( freenect_device* dev,
uint16_t* depth_mm, uint8_t* rgb_raw, uint8_t* rgb_registered );

#ifdef __cplusplus
}
#endif
29 changes: 29 additions & 0 deletions src/registration.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,35 @@ void freenect_camera_to_world(freenect_device* dev, int cx, int cy, int wz, doub
*wy = (double)(cy - DEPTH_Y_RES/2) * factor;
}

/// RGB -> depth mapping function (inverse of default FREENECT_DEPTH_REGISTERED mapping)
void freenect_map_rgb_to_depth(freenect_device* dev, uint16_t* depth_mm, uint8_t* rgb_raw, uint8_t* rgb_registered)
{
uint32_t target_offset = dev->registration.reg_pad_info.start_lines * DEPTH_Y_RES;
int x,y;

for (y = 0; y < DEPTH_Y_RES; y++) for (x = 0; x < DEPTH_X_RES; x++) {

uint32_t index = y * DEPTH_X_RES + x;
uint32_t cx,cy,cindex;

int wz = depth_mm[index];
//if (wz == 0) continue;

// coordinates in rgb image corresponding to x,y
cx = (dev->registration.registration_table[index][0] + dev->registration.depth_to_rgb_shift[wz]) / REG_X_VAL_SCALE;
cy = dev->registration.registration_table[index][1];

if (cx >= DEPTH_X_RES) continue;

cindex = (cy * DEPTH_X_RES + cx - target_offset) * 3;
index = index*3;

rgb_registered[index+0] = rgb_raw[cindex+0];
rgb_registered[index+1] = rgb_raw[cindex+1];
rgb_registered[index+2] = rgb_raw[cindex+2];
}
}

/// 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 a55cd43

Please sign in to comment.