Skip to content

Commit a55cd43

Browse files
floefran6co
authored andcommitted
add freenect_map_rgb_to_depth helper function (untested)
1 parent 9b671cd commit a55cd43

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

include/libfreenect_registration.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ FREENECTAPI int freenect_destroy_registration(freenect_registration* reg);
120120
FREENECTAPI void freenect_camera_to_world(freenect_device* dev,
121121
int cx, int cy, int wz, double* wx, double* wy);
122122

123+
// helper function to map one FREENECT_VIDEO_RGB image to a FREENECT_DEPTH_MM
124+
// image (inverse mapping to FREENECT_DEPTH_REGISTERED, which is depth -> RGB)
125+
FREENECTAPI void freenect_map_rgb_to_depth( freenect_device* dev,
126+
uint16_t* depth_mm, uint8_t* rgb_raw, uint8_t* rgb_registered );
127+
123128
#ifdef __cplusplus
124129
}
125130
#endif

src/registration.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,35 @@ void freenect_camera_to_world(freenect_device* dev, int cx, int cy, int wz, doub
329329
*wy = (double)(cy - DEPTH_Y_RES/2) * factor;
330330
}
331331

332+
/// RGB -> depth mapping function (inverse of default FREENECT_DEPTH_REGISTERED mapping)
333+
void freenect_map_rgb_to_depth(freenect_device* dev, uint16_t* depth_mm, uint8_t* rgb_raw, uint8_t* rgb_registered)
334+
{
335+
uint32_t target_offset = dev->registration.reg_pad_info.start_lines * DEPTH_Y_RES;
336+
int x,y;
337+
338+
for (y = 0; y < DEPTH_Y_RES; y++) for (x = 0; x < DEPTH_X_RES; x++) {
339+
340+
uint32_t index = y * DEPTH_X_RES + x;
341+
uint32_t cx,cy,cindex;
342+
343+
int wz = depth_mm[index];
344+
//if (wz == 0) continue;
345+
346+
// coordinates in rgb image corresponding to x,y
347+
cx = (dev->registration.registration_table[index][0] + dev->registration.depth_to_rgb_shift[wz]) / REG_X_VAL_SCALE;
348+
cy = dev->registration.registration_table[index][1];
349+
350+
if (cx >= DEPTH_X_RES) continue;
351+
352+
cindex = (cy * DEPTH_X_RES + cx - target_offset) * 3;
353+
index = index*3;
354+
355+
rgb_registered[index+0] = rgb_raw[cindex+0];
356+
rgb_registered[index+1] = rgb_raw[cindex+1];
357+
rgb_registered[index+2] = rgb_raw[cindex+2];
358+
}
359+
}
360+
332361
/// Allocate and fill registration tables
333362
/// This function should be called every time a new video (not depth!) mode is
334363
/// activated.

0 commit comments

Comments
 (0)