Skip to content

Commit 405c206

Browse files
committed
Switch depth buffer to unshifted and add correction
This uses some gamma correction and an offset to better map the depth values to a nice heat map style image.
1 parent 7cdeab7 commit 405c206

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ include_directories(${USB_INCLUDE_DIRS})
1111

1212
add_executable(glview glview.c)
1313
find_library (PTHREAD pthread)
14-
target_link_libraries(glview freenect GL GLU glut)
14+
target_link_libraries(glview freenect GL GLU glut m)

examples/glview.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This code is licensed to you under the terms of the GNU GPL, version 2 or versio
1111

1212
#include <stdio.h>
1313
#include <string.h>
14+
#include <math.h>
1415
#include <libusb.h>
1516
#include "libfreenect.h"
1617

@@ -139,6 +140,8 @@ void *gl_threadfunc(void *arg)
139140
return NULL;
140141
}
141142

143+
uint16_t t_gamma[2048];
144+
142145
void depthimg(uint16_t *buf, int width, int height)
143146
{
144147
/* FILE *f = fopen("depth.bin", "w");
@@ -149,13 +152,13 @@ void depthimg(uint16_t *buf, int width, int height)
149152

150153
pthread_mutex_lock(&gl_backbuf_mutex);
151154
for (i=0; i<640*480; i++) {
152-
int pval = (buf[i]*8)/256;
155+
int pval = t_gamma[buf[i]];
153156
int lb = pval & 0xff;
154157
switch (pval>>8) {
155158
case 0:
156159
gl_depth_back[3*i+0] = 255;
157-
gl_depth_back[3*i+1] = lb;
158-
gl_depth_back[3*i+2] = lb;
160+
gl_depth_back[3*i+1] = 255-lb;
161+
gl_depth_back[3*i+2] = 255-lb;
159162
break;
160163
case 1:
161164
gl_depth_back[3*i+0] = 255;
@@ -208,6 +211,13 @@ int main(int argc, char **argv)
208211
libusb_device_handle *dev;
209212
printf("Kinect camera test\n");
210213

214+
int i;
215+
for (i=0; i<2048; i++) {
216+
float v = i/2048.0;
217+
v = powf(v, 2)* 3;
218+
t_gamma[i] = v*6*256;
219+
}
220+
211221
g_argc = argc;
212222
g_argv = argv;
213223

lib/cameras.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void depth_process(uint8_t *buf, size_t len)
8484
for (i=0; i<(640*480); i++) {
8585
int idx = (i*11)/8;
8686
uint32_t word = (depth_buf[idx]<<16) | (depth_buf[idx+1]<<8) | depth_buf[idx+2];
87-
depth_frame[i] = ((word >> (13-bitshift)) & 0x7ff) << 5;
87+
depth_frame[i] = ((word >> (13-bitshift)) & 0x7ff);
8888
bitshift = (bitshift + 11) % 8;
8989
}
9090

0 commit comments

Comments
 (0)