Kinect Depth Calculation

586 views
Skip to first unread message

lakshmen

unread,
Jun 8, 2011, 4:55:06 AM6/8/11
to OpenKinect
Hi guys, like to check with you guys what is the correct method for
depth calibration? Is this method below correct?I am using glview.

float cx = 320.0;
float cy = 240.0;
float minDistance = -10;
float scaleFactor = 0.0021;
for (i=0; i<2048; i++) {
const float k1 = 1.1863;
const float k2 = 2842.5;
const float k3 = 0.1236;
const float depth = k3 * tanf(i/k2 + k1);
t_gamma[i] = depth;
for (int v=0, n=0 ; v<480 ; v++)
{
for ( int u=0 ; u<640 ; u++, n++)
{
Vec3f result;
result.x = float(((u - cx) * depth+ minDistance) *
scaleFactor * (cx/cy));
result.y = float(((v - cy) * depth+ minDistance) *
scaleFactor);
result.z = float(depth);
outf << result.z;

}

}

}

Gabriele

unread,
Jun 9, 2011, 7:13:25 AM6/9/11
to OpenKinect
I am also very interested about depth to world calibration (not RGB).
Unfortunately it is not a very much debated topic..
:(

Daniel Johnson

unread,
Jun 9, 2011, 3:16:41 PM6/9/11
to openk...@googlegroups.com
> On 8 Giu, 10:55, lakshmen <lakshme...@gmail.com> wrote:
>> Hi guys, like to check with you guys what is the correct method for
>> depth calibration? Is this method below correct?I am using glview.

This

>>     const float depth = k3 * tanf(i/k2 + k1);

Looks the same as

"Depth is grabbed in 10bit depth, and a range N it's converted to
meters as: range(m) = 0.1236 * tan(N/2842.5 + 1.1863)"

which I found in the mrpt.org project in
libs/hwdrivers/include/mrpt/hwdrivers/CKinect.h
which uses libfreenect to talk to the hardware

So that calculation looks right, I'm not sure that you are iterating
through your data right though. It seems to be be hitting every pixel
2048 times...

Daniel

unread,
Jun 9, 2011, 5:51:27 PM6/9/11
to OpenKinect
I checked mpt.org and they have two functions coded in there.

#ifdef MRPT_KINECT_DEPTH_10BIT
... m_range2meters[i] = k3 * tanf(i/k2 + k1);
#else
... m_range2meters[i] = 1.0f / (i * (-0.0030711016) + 3.3309495161);
#endif

Both functions are very similar (plot here: http://i.imgur.com/CtW1d.jpg)
but they can vary by tens of centimeters. I don't see how the macro
chooses between the two, use tan() when it is 10bits and the other
when it is 8bits? But the range is the same, only the accuracy varies.
Shouldn't these values be calibrated anyway?

DHC

lakshmen

unread,
Jun 9, 2011, 6:05:26 PM6/9/11
to OpenKinect
Hi ppl,

like to ask which is the function that calls back the depth?Because,
the whole day yesterday i was trying and i got only a bunch of zeros.

By the way, the code above is wrong...

int i;
for (i=0; i<2048; i++) {
const float k1 = 1.1863;
const float k2 = 2842.5;
const float k3 = 0.1236;
t_gamma[i] = k3 * tanf(i/k2 + k1);
}

float cx = 320.0;
float cy = 240.0;
float minDistance = -10;
float scaleFactor = 0.0021;

FILE *pfLog = fopen("Sample.dat", "wb");
for (int v=0, n=0 ; v<480 ; v++)
{
for (int u=0 ; u<640 ; u++, n++)
{
Vec3f result;
result.x = float(((u - cx) * t_gamma[depth[n]]+
minDistance) * scaleFactor * (cx/cy));
result.y = float(((v - cy) * t_gamma[depth[n]]+
minDistance) * scaleFactor);
result.z = float(t_gamma[depth[n]]);
fprintf(pfLog, "%.3g\t", result.z);

}
fprintf(pfLog, "\r\n");
}
fclose(pfLog);

I think this is a far more better code.

I would like the help of the experts of this group because the kinect
depth calculation is the most basic and once
a person can master it, he/she can go on to do many things with it..
PLEASE HELP..


On Jun 10, 5:51 am, Daniel <daniel.herrera.cas...@googlemail.com>
wrote:

Daniel Johnson

unread,
Jun 9, 2011, 6:07:33 PM6/9/11
to openk...@googlegroups.com
On Thu, Jun 9, 2011 at 2:51 PM, Daniel
<daniel.her...@googlemail.com> wrote:
> I checked mpt.org and they have two functions coded in there.
>
> #ifdef MRPT_KINECT_DEPTH_10BIT
>  ...            m_range2meters[i] = k3 * tanf(i/k2 + k1);
> #else
>  ...            m_range2meters[i] = 1.0f / (i * (-0.0030711016) + 3.3309495161);
> #endif
>
> Both functions are very similar (plot here: http://i.imgur.com/CtW1d.jpg)
> but they can vary by tens of centimeters. I don't see how the macro
> chooses between the two, use tan() when it is 10bits and the other
> when it is 8bits? But the range is the same, only the accuracy varies.
> Shouldn't these values be calibrated anyway?

I think the other option is 11 bit

cnn lakshmen

unread,
Jun 9, 2011, 6:20:11 PM6/9/11
to openk...@googlegroups.com
How do u get the 11bit data out?

cnn lakshmen

unread,
Jun 9, 2011, 6:30:31 PM6/9/11
to openk...@googlegroups.com

is FREENECT_DEPTH_11BIT the one that gets the 11 bit pixel data ?

i am not sure ...

lakshmen

unread,
Jun 9, 2011, 10:19:59 PM6/9/11
to OpenKinect
Hi guys,
is this function that gets the depth value?

int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int
index, freenect_depth_format fmt);

for the libfreenect driver.

On Jun 10, 6:30 am, cnn lakshmen <lakshme...@gmail.com> wrote:
> is FREENECT_DEPTH_11BIT the one that gets the 11 bit pixel data ?
>
> i am not sure ...
>
> On Fri, Jun 10, 2011 at 6:20 AM, cnn lakshmen <lakshme...@gmail.com> wrote:
> > How do u get the 11bit data out?
>

Carlos Roberto

unread,
Jun 9, 2011, 10:44:30 PM6/9/11
to openk...@googlegroups.com
You can use freenect_sync_get_depth to get access to depth buffer. More details, take a look the libfreenect_sync.h file.
Cheers.

Carlos Roberto, MSc
Software Eng. Consultant @ IBM

My profiles: LinkedIn Twitter Blogger
--
Carlos Roberto
Software Eng. Consultant @ IBM
My Blog
My LinkedIn
follow me @ twitter

lakshmen

unread,
Jun 9, 2011, 11:09:45 PM6/9/11
to OpenKinect
Hi,

Am i right to say that the (void**)&depth gives the depth in the code
below?

short *depth = 0;
uint32_t ts;
freenect_sync_get_depth((void**)&depth, &ts, 0,
FREENECT_DEPTH_11BIT);

On Jun 10, 10:44 am, Carlos Roberto <carlo...@gmail.com> wrote:
> You can use freenect_sync_get_depth to get access to depth buffer. More
> details, take a look the libfreenect_sync.h file.
> Cheers.
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:
> LinkedIn]<http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378>
> [image:
> Twitter] <http://twitter.com/#%21/ze_tech> [image:
> Blogger]<http://kinect-i.blogspot.com/>
> Signature powered by
> <http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu...>
> WiseStamp<http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu...>
> My Blog <http://kinect-i.blogspot.com/>
> My LinkedIn <http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378>
> follow me @ twitter <http://twitter.com/#%21/ze_tech>

Carlos Roberto

unread,
Jun 10, 2011, 7:00:10 AM6/10/11
to openk...@googlegroups.com
Yes, depth variable gives the depth code. You can take a look the cvdemo.c sample that handle depth data.
Cheers.

Carlos Roberto, MSc
Software Eng. Consultant @ IBM

My profiles: LinkedIn Twitter Blogger

lakshmen

unread,
Jun 10, 2011, 7:05:41 AM6/10/11
to OpenKinect
must i use the opencv? what if i dont want to use open cv?


On Jun 10, 7:00 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> Yes, depth variable gives the depth code. You can take a look the cvdemo.c
> sample that handle depth data.
> Cheers.
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:

Carlos Roberto

unread,
Jun 10, 2011, 8:15:03 AM6/10/11
to openk...@googlegroups.com
You dont need to user OpenCV. Just use libfreenect_sync.c, record.c, cvdemo.c as guideline about how to to handle data from depth device.
Cheers.


Carlos Roberto, MSc
Software Eng. Consultant @ IBM

My profiles: LinkedIn Twitter Blogger

lakshmen

unread,
Jun 10, 2011, 8:30:52 AM6/10/11
to OpenKinect
hey,

really sorry. can u show me how it is done? really sorry.. have been
trying for the past two weeks, i cant get the values.

On Jun 10, 8:15 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> You dont need to user OpenCV. Just use libfreenect_sync.c, record.c,
> cvdemo.c as guideline about how to to handle data from depth device.
> Cheers.
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:
> LinkedIn]<http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378>
> [image:
> Twitter] <http://twitter.com/#%21/ze_tech> [image:
> Blogger]<http://kinect-i.blogspot.com/>
> Signature powered by
> <http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu...>
> WiseStamp<http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu...>
>
>
>
> On Fri, Jun 10, 2011 at 8:05 AM, lakshmen <lakshme...@gmail.com> wrote:
> > must i use the opencv? what if i dont want to use open cv?
>
> > On Jun 10, 7:00 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> > > Yes, depth variable gives the depth code. You can take a look the
> > cvdemo.c
> > > sample that handle depth data.
> > > Cheers.
>
> > > Carlos Roberto, MSc
> > > Software Eng. Consultant @ IBM
> > > My profiles: [image:
> > > LinkedIn]<http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378>
> > > [image:
> > > Twitter] <http://twitter.com/#%21/ze_tech> [image:
> > > Blogger]<http://kinect-i.blogspot.com/>
> > > Signature powered by

lakshmen

unread,
Jun 10, 2011, 9:07:37 AM6/10/11
to OpenKinect
there is this function glutMainloop(); which continues to run and once
called it will never return...

because of this function, i can't get the data...

how to solve the problem??

lakshmen

unread,
Jun 10, 2011, 11:20:30 AM6/10/11
to OpenKinect
this is the code i have written. can help me whether this is correct?


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libfreenect.h"
#include "Vec3f.h"
#include <fstream>
#include <pthread.h>
#include <iostream>
#include "libfreenect_sync.h"


#if defined(__APPLE__)
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif

#include <math.h>

pthread_t freenect_thread;
volatile int die = 0;

int g_argc;
char **g_argv;

int window;

pthread_mutex_t gl_backbuf_mutex = PTHREAD_MUTEX_INITIALIZER;

// back: owned by libfreenect (implicit for depth)
// mid: owned by callbacks, "latest frame ready"
// front: owned by GL, "currently being drawn"
uint8_t *depth_mid, *depth_front;
uint8_t *rgb_back, *rgb_mid, *rgb_front;

GLuint gl_depth_tex;
GLuint gl_rgb_tex;

freenect_context *f_ctx;
freenect_device *f_dev;
int freenect_angle = 0;
int freenect_led;

freenect_video_format requested_format = FREENECT_VIDEO_RGB;
freenect_video_format current_format = FREENECT_VIDEO_RGB;

pthread_cond_t gl_frame_cond = PTHREAD_COND_INITIALIZER;
int got_rgb = 0;
int got_depth = 0;

uint16_t t_gamma[2048];
static uint16_t depth[640*480];
//static float xrgb;
//freenect_sync_get_depth((void**)&depth, &ts, 0,
FREENECT_DEPTH_11BIT);

void DrawGLScene()
{
pthread_mutex_lock(&gl_backbuf_mutex);

// When using YUV_RGB mode, RGB frames only arrive at 15Hz, so we
shouldn't force them to draw in lock-step.
// However, this is CPU/GPU intensive when we are receiving frames in
lockstep.
if (current_format == FREENECT_VIDEO_YUV_RGB) {
while (!got_depth && !got_rgb) {
pthread_cond_wait(&gl_frame_cond, &gl_backbuf_mutex);
}
} else {
while ((!got_depth || !got_rgb) && requested_format !=
current_format) {
pthread_cond_wait(&gl_frame_cond, &gl_backbuf_mutex);
}
}

if (requested_format != current_format) {
pthread_mutex_unlock(&gl_backbuf_mutex);
return;
}

uint8_t *tmp;

if (got_depth) {
tmp = depth_front;
depth_front = depth_mid;
depth_mid = tmp;
got_depth = 0;
}
if (got_rgb) {
tmp = rgb_front;
rgb_front = rgb_mid;
rgb_mid = tmp;
got_rgb = 0;
}

pthread_mutex_unlock(&gl_backbuf_mutex);

glBindTexture(GL_TEXTURE_2D, gl_depth_tex);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB,
GL_UNSIGNED_BYTE, depth_front);

glBegin(GL_TRIANGLE_FAN);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0, 0); glVertex3f(0,0,0);
glTexCoord2f(1, 0); glVertex3f(640,0,0);
glTexCoord2f(1, 1); glVertex3f(640,480,0);
glTexCoord2f(0, 1); glVertex3f(0,480,0);
glEnd();

glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
if (current_format == FREENECT_VIDEO_RGB || current_format ==
FREENECT_VIDEO_YUV_RGB)
glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB,
GL_UNSIGNED_BYTE, rgb_front);
else
glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE,
GL_UNSIGNED_BYTE, rgb_front+640*4);

glBegin(GL_TRIANGLE_FAN);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0, 0); glVertex3f(640,0,0);
glTexCoord2f(1, 0); glVertex3f(1280,0,0);
glTexCoord2f(1, 1); glVertex3f(1280,480,0);
glTexCoord2f(0, 1); glVertex3f(640,480,0);
glEnd();

glutSwapBuffers();
}

void keyPressed(unsigned char key, int x, int y)
{
if (key == 27) {
die = 1;
pthread_join(freenect_thread, NULL);
glutDestroyWindow(window);
free(depth_mid);
free(depth_front);
free(rgb_back);
free(rgb_mid);
free(rgb_front);
pthread_exit(NULL);
}
if (key == 'w') {
freenect_angle++;
if (freenect_angle > 30) {
freenect_angle = 30;
}
}
if (key == 's') {
freenect_angle = 0;
}
if (key == 'f') {
if (requested_format == FREENECT_VIDEO_IR_8BIT)
requested_format = FREENECT_VIDEO_RGB;
else if (requested_format == FREENECT_VIDEO_RGB)
requested_format = FREENECT_VIDEO_YUV_RGB;
else
requested_format = FREENECT_VIDEO_IR_8BIT;
}
if (key == 'x') {
freenect_angle--;
if (freenect_angle < -30) {
freenect_angle = -30;
}
}
if (key == '1') {
freenect_set_led(f_dev,LED_GREEN);
}
if (key == '2') {
freenect_set_led(f_dev,LED_RED);
}
if (key == '3') {
freenect_set_led(f_dev,LED_YELLOW);
}
if (key == '4') {
freenect_set_led(f_dev,LED_BLINK_GREEN);
}
if (key == '5') {
// 5 is the same as 4
freenect_set_led(f_dev,LED_BLINK_GREEN);
}
if (key == '6') {
freenect_set_led(f_dev,LED_BLINK_RED_YELLOW);
}
if (key == '0') {
freenect_set_led(f_dev,LED_OFF);
}
freenect_set_tilt_degs(f_dev,freenect_angle);
}

void ReSizeGLScene(int Width, int Height)
{
glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0, 1280, 480, 0, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void InitGL(int Width, int Height)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_FLAT);

glGenTextures(1, &gl_depth_tex);
glBindTexture(GL_TEXTURE_2D, gl_depth_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glGenTextures(1, &gl_rgb_tex);
glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

ReSizeGLScene(Width, Height);
}

void *gl_threadfunc(void *arg)
{
printf("GL thread\n");


glutInit(&g_argc, g_argv);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA |
GLUT_DEPTH);
glutInitWindowSize(1280, 480);
glutInitWindowPosition(0, 0);

window = glutCreateWindow("LibFreenect");

glutDisplayFunc(&DrawGLScene);
glutIdleFunc(&DrawGLScene);
glutReshapeFunc(&ReSizeGLScene);
glutKeyboardFunc(&keyPressed);

InitGL(1280, 480);

// int depth[640*480];
// short *depth = 0;
uint32_t ts;
freenect_sync_get_depth((void**)&depth, &ts, 0,
FREENECT_DEPTH_11BIT);

FILE *pfLog = fopen("Sample.dat", "wb");

int w =480;
int h = 640;
for(int x = 0; x < w; x ++) {
for(int y = 0,n = 0; y < h; y++, n++) {

float rawDepth = t_gamma[depth[n]];

if (x >= 100 && x <= 120 && y >= 100 && y <= 102) {
printf("%d\t",depth[n]);
}

fprintf(pfLog, "%f\t", rawDepth);
}
fprintf(pfLog, "\r\n");
}
fclose(pfLog);

glutMainLoop();

return NULL;
}


void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
{
int i;
uint16_t *depth = (uint16_t*)v_depth;

pthread_mutex_lock(&gl_backbuf_mutex);

//double fx_d = 5.9421434211923247e+02;
//double fy_d = 5.9104053696870778e+02;
//double cx_d = 3.3930780975300314e+02;
//double cy_d = 2.4273913761751615e+02;
/*

float cx = 320.0;
float cy = 240.0;
float minDistance = -10;
float scaleFactor = 0.0021;


for(int u = 0; u < 480;u++) {
for(int v= 0; v < 640; v++) {


// float rawDepth = t_gamma[depth[depth_offset]];
float xrgb = float(((u - cx) * t_gamma[(void**)&depth]+
minDistance) * scaleFactor * (cx/cy));
//float y = float(((v - cy) * t_gamma[depth[depth_offset]]+
minDistance) * scaleFactor);

/*double xrgb = ((((double)x - cx_d)*dxy)+(ox*fx_d)) * (fx_rgb/((dxy
+oz)*fx_d)) + cx_rgb;
double yrgb = ((((double)y - cy_d)*dxy)+(oy*fy_d)) * (fy_rgb/((dxy
+oz)*fy_d)) + cy_rgb;
*/
/* if (v>= 100 && v<= 120 && u>= 100 && u <= 102) {
printf("%f\t",xrgb);
}

}

}
*/

for (i=0; i<640*480; i++) {
int pval = t_gamma[depth[i]];
int lb = pval & 0xff;
switch (pval>>8) {
case 0:
depth_mid[3*i+0] = 255;
depth_mid[3*i+1] = 255-lb;
depth_mid[3*i+2] = 255-lb;
break;
case 1:
depth_mid[3*i+0] = 255;
depth_mid[3*i+1] = lb;
depth_mid[3*i+2] = 0;
break;
case 2:
depth_mid[3*i+0] = 255-lb;
depth_mid[3*i+1] = 255;
depth_mid[3*i+2] = 0;
break;
case 3:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 255;
depth_mid[3*i+2] = lb;
break;
case 4:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 255-lb;
depth_mid[3*i+2] = 255;
break;
case 5:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 0;
depth_mid[3*i+2] = 255-lb;
break;
default:
depth_mid[3*i+0] = 0;
depth_mid[3*i+1] = 0;
depth_mid[3*i+2] = 0;
break;
}
}
got_depth++;
pthread_cond_signal(&gl_frame_cond);
pthread_mutex_unlock(&gl_backbuf_mutex);
}

void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp)
{
pthread_mutex_lock(&gl_backbuf_mutex);

// swap buffers
assert (rgb_back == rgb);
rgb_back = rgb_mid;
freenect_set_video_buffer(dev, rgb_back);
rgb_mid = (uint8_t*)rgb;

got_rgb++;
pthread_cond_signal(&gl_frame_cond);
pthread_mutex_unlock(&gl_backbuf_mutex);
}

void *freenect_threadfunc(void *arg)
{
int accelCount = 0;

freenect_set_tilt_degs(f_dev,freenect_angle);
freenect_set_led(f_dev,LED_RED);
freenect_set_depth_callback(f_dev, depth_cb);
freenect_set_video_callback(f_dev, rgb_cb);
freenect_set_video_mode(f_dev,
freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, current_format));
freenect_set_depth_mode(f_dev,
freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM,
FREENECT_DEPTH_11BIT));
freenect_set_video_buffer(f_dev, rgb_back);

freenect_start_depth(f_dev);
freenect_start_video(f_dev);

printf("'w'-tilt up, 's'-level, 'x'-tilt down, '0'-'6'-select LED
mode, 'f'-video format\n");

while (!die && freenect_process_events(f_ctx) >= 0) {
//Throttle the text output
if (accelCount++ >= 2000)
{
accelCount = 0;
freenect_raw_tilt_state* state;
freenect_update_tilt_state(f_dev);
state = freenect_get_tilt_state(f_dev);
double dx,dy,dz;
freenect_get_mks_accel(state, &dx, &dy, &dz);
printf("\r raw acceleration: %4d %4d %4d mks acceleration: %4f %4f
%4f", state->accelerometer_x, state->accelerometer_y, state-
>accelerometer_z, dx, dy, dz);
fflush(stdout);
}

if (requested_format != current_format) {
freenect_stop_video(f_dev);
freenect_set_video_mode(f_dev,
freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM,
requested_format));
freenect_start_video(f_dev);
current_format = requested_format;
}
}

printf("\nshutting down streams...\n");

freenect_stop_depth(f_dev);
freenect_stop_video(f_dev);

freenect_close_device(f_dev);
freenect_shutdown(f_ctx);

printf("-- done!\n");
return NULL;
}

int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int
index, freenect_depth_format fmt);

/*double raw2depth( int raw_d ) {
//int raw_d = buf[row*width+col];
if (raw_d < 2047) {
return t_gamma(i);
}
return 0.0;
}
*/

int main(int argc, char **argv)
{
using namespace std;
int res;

depth_mid = (uint8_t*)malloc(640*480*3);
depth_front = (uint8_t*)malloc(640*480*3);
rgb_back = (uint8_t*)malloc(640*480*3);
rgb_mid = (uint8_t*)malloc(640*480*3);
rgb_front = (uint8_t*)malloc(640*480*3);

printf("Kinect camera test\n");

int i;
for (i=0; i<2048; i++) {
float v = i/2048.0;
v = powf(v, 3)* 6;
t_gamma[i] = v*6*256;
}

/*float v = i/2048.0;
v = powf(v, 3)* 6;
t_gamma[i] = v*6*256;*/

/* const float k1 = 1.1863;
const float k2 = 2842.5;
const float k3 = 0.1236;
t_gamma[i] = k3 * tanf(i/k2 + k1);
*/
/*for (int i = 0; i < 2048; i++) {
t_gamma[i] = (float)(1.0 / ((double)(i) * -0.0030711016 +
3.3309495161));
}*/


g_argc = argc;
g_argv = argv;

if (freenect_init(&f_ctx, NULL) < 0) {
printf("freenect_init() failed\n");
return 1;
}

freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);

int nr_devices = freenect_num_devices (f_ctx);
printf ("Number of devices found: %d\n", nr_devices);

int user_device_number = 0;
if (argc > 1)
user_device_number = atoi(argv[1]);

if (nr_devices < 1)
return 1;

printf ("Open device ...\n");

if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
printf("Could not open device\n");
return 1;
}

printf ("Create thread...\n");
res = pthread_create(&freenect_thread, NULL, freenect_threadfunc,
NULL);
if (res) {
printf("pthread_create failed\n");
return 1;
}

printf ("gl_threadfunc...\n");

// OS X requires GLUT to run on the main thread
gl_threadfunc(NULL);

printf ("Get depth...\n");

// int depth[640*480];
// short *depth = 0;
uint32_t ts;
freenect_sync_get_depth((void**)&depth, &ts, 0,
FREENECT_DEPTH_11BIT);

FILE *pfLog = fopen("Sample.dat", "wb");

int w =480;
int h = 640;
for(int x = 0; x < w; x ++) {
for(int y = 0,n = 0; y < h; y++, n++) {

float rawDepth = t_gamma[depth[n]];

if (x >= 100 && x <= 120 && y >= 100 && y <= 102) {
printf("%d\t",depth[n]);
}

fprintf(pfLog, "%f\t", rawDepth);
}
fprintf(pfLog, "\r\n");
}
fclose(pfLog);

return 0;

Carlos Roberto

unread,
Jun 10, 2011, 12:38:48 PM6/10/11
to openk...@googlegroups.com
Hi,
Please check the record.c project that is ready to collect and save data from depth device. You can run it under debug mode and see how it works.
Cheers.


Carlos Roberto, MSc
Software Eng. Consultant @ IBM

My profiles: LinkedIn Twitter Blogger

lakshmen

unread,
Jun 14, 2011, 1:48:00 AM6/14/11
to OpenKinect
Hi,

i am really need help.. i can't still get the values. really sorry
about it.... As i said earlier, the function gets stuck in the
glutMainloop...

On Jun 11, 12:38 am, Carlos Roberto <carlo...@gmail.com> wrote:
> Hi,
> Please check the record.c project that is ready to collect and save data
> from depth device. You can run it under debug mode and see how it works.
> Cheers.
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:

lakshmen

unread,
Jun 14, 2011, 2:58:50 AM6/14/11
to OpenKinect
Someone told me to avoid the glutMainloop, i can implement my
rawdistance conversion to length in the DrawGLScene function above? is
that correct?? have any of you tried that?

lakshmen

unread,
Jun 14, 2011, 4:37:52 AM6/14/11
to OpenKinect
Am I right to say that i am use glutLeaveMainLoop or
glutmainLoopEvent?

Carlos Roberto

unread,
Jun 14, 2011, 8:02:49 AM6/14/11
to openk...@googlegroups.com
You can just run the record project to get depth data.

http://openkinect.org/wiki/Fakenect#Record


Carlos Roberto, MSc
Software Eng. Consultant @ IBM

My profiles: LinkedIn Twitter Blogger

lakshmen

unread,
Jun 14, 2011, 8:13:55 AM6/14/11
to OpenKinect
depth is in the dump_depth function.. am i right?

On Jun 14, 8:02 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> You can just run the record project to get depth data.
>
> http://openkinect.org/wiki/Fakenect#Record
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:

lakshmen

unread,
Jun 14, 2011, 8:15:36 AM6/14/11
to OpenKinect
depth is in the dump_depth function.. am i right?

On Jun 14, 8:02 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> You can just run the record project to get depth data.
>
> http://openkinect.org/wiki/Fakenect#Record
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:

lakshmen

unread,
Jun 14, 2011, 8:15:46 AM6/14/11
to OpenKinect
depth is in the dump_depth function.. am i right?

On Jun 14, 8:02 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> You can just run the record project to get depth data.
>
> http://openkinect.org/wiki/Fakenect#Record
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:

lakshmen

unread,
Jun 14, 2011, 8:16:46 AM6/14/11
to OpenKinect
depth is in the dump_depth function.. am i right?

On Jun 14, 8:02 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> You can just run the record project to get depth data.
>
> http://openkinect.org/wiki/Fakenect#Record
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:

Carlos Roberto

unread,
Jun 14, 2011, 2:18:33 PM6/14/11
to openk...@googlegroups.com
Yes, you are right.
You can read here about how it works.
https://github.com/OpenKinect/libfreenect/tree/master/fakenect

Cheers.

Carlos Roberto, MSc
Software Eng. Consultant @ IBM

My profiles: LinkedIn Twitter Blogger

lakshmen

unread,
Jun 14, 2011, 10:47:40 PM6/14/11
to OpenKinect
where does it save the data, i cant find the file

On Jun 15, 2:18 am, Carlos Roberto <carlo...@gmail.com> wrote:
> Yes, you are right.
> You can read here about how it works.https://github.com/OpenKinect/libfreenect/tree/master/fakenect
>
> Cheers.
>
> Carlos Roberto, MSc
> Software Eng. Consultant @ IBM
> My profiles: [image:
> On Tue, Jun 14, 2011 at 9:16 AM, lakshmen <lakshme...@gmail.com> wrote:
> > depth is in the dump_depth function.. am i right?
>
> > On Jun 14, 8:02 pm, Carlos Roberto <carlo...@gmail.com> wrote:
> > > You can just run the record project to get depth data.
>
> > >http://openkinect.org/wiki/Fakenect#Record
>
> > > Carlos Roberto, MSc
> > > Software Eng. Consultant @ IBM
> > > My profiles: [image:
> > > LinkedIn]<http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378>
> > > [image:
> > > Twitter] <http://twitter.com/#%21/ze_tech> [image:
> > > Blogger]<http://kinect-i.blogspot.com/>
> > > Signature powered by
> > .>
> > > > > > > WiseStamp<
> > > >http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu..
> > .>
>
> > .>
> > > > > > > > > > WiseStamp<
>
> > > >http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu..
> > .>
>
> ...
>
> read more »

lakshmen

unread,
Jun 14, 2011, 11:04:53 PM6/14/11
to OpenKinect
sorry i can save the data already
> ...
>
> read more »

lakshmen

unread,
Jun 15, 2011, 5:21:18 AM6/15/11
to OpenKinect
But how do u extract out the depth data?
> ...
>
> read more »

Carlos Roberto

unread,
Jun 15, 2011, 3:02:37 PM6/15/11
to openk...@googlegroups.com
Hi,
The depth buffer is in files where the names are saved as the example d--1096783991.813490-1844861182.pgm
You can check in index.txt file about all files saved in the disk.
Cheers.


Carlos Roberto, MSc
Software Eng. Consultant @ IBM

My profiles: LinkedIn Twitter Blogger
--
Carlos Roberto

Software Eng. Consultant @ IBM

cnn lakshmen

unread,
Jun 15, 2011, 9:41:26 PM6/15/11
to openk...@googlegroups.com
but the data is encrypted, can't see..

cnn lakshmen

unread,
Jun 15, 2011, 10:31:30 PM6/15/11
to openk...@googlegroups.com
sorry to ask u all the stupid qns.. i really can't get the answer.. thats why...

cnn lakshmen

unread,
Jun 15, 2011, 10:36:04 PM6/15/11
to openk...@googlegroups.com
i want to see the value between 0-2048... how to see that??

肖玉连

unread,
Jun 15, 2011, 11:40:03 PM6/15/11
to openk...@googlegroups.com
The raw depth data (FREENECT_DEPTH_11BIT)is 0--2048 and you can transfer it to meters by the following function
float RawDepthToMeters(int depthValue)
{
    if (depthValue < 2047)
    {
        return float(1.0 / (double(depthValue) * -0.0030711016 + 3.3309495161));
    }
    return 0.0f;
}

BR
--
肖玉连(Shorn)
------------------------------------------------------------------
北京联合绿动科技有限公司
Mobile: 13811278218

cnn lakshmen

unread,
Jun 15, 2011, 11:45:57 PM6/15/11
to openk...@googlegroups.com

hi,

thanks for replying... what i want to do is to print the Freenect_depth_11bit value between the 0-2048. i know how to do the conversion but what i want to print out is the raw depth data to ensure that the value is the one i can manipulate.....when i print out the raw depth data i get all zeros.

thanks,
lakshmen
2011/6/16 肖玉连 <xia...@eboxdeveloper.com>

肖玉连

unread,
Jun 15, 2011, 11:50:47 PM6/15/11
to openk...@googlegroups.com
Have u call the following function successfully? 
 Have u install the libfreenect driver?
freenect_set_depth_callback(f_dev, depth_cb);
void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)

2011/6/16 cnn lakshmen <laksh...@gmail.com>

cnn lakshmen

unread,
Jun 15, 2011, 11:55:30 PM6/15/11
to openk...@googlegroups.com
I have installed libfreenect driver... but i cant call the data out... I have attached the file for your info.

2011/6/16 肖玉连 <xia...@eboxdeveloper.com>
cppview.cpp.today

cnn lakshmen

unread,
Jun 15, 2011, 11:57:02 PM6/15/11
to openk...@googlegroups.com
i am just trying to get the data out.. and plotting the data out... i am using glview.c as the basis...

2011/6/16 cnn lakshmen <laksh...@gmail.com>

肖玉连

unread,
Jun 15, 2011, 11:59:21 PM6/15/11
to openk...@googlegroups.com
I will run it on my pc and test it for you

2011/6/16 cnn lakshmen <laksh...@gmail.com>

cnn lakshmen

unread,
Jun 16, 2011, 12:02:58 AM6/16/11
to openk...@googlegroups.com
sure thanks...


2011/6/16 肖玉连 <xia...@eboxdeveloper.com>

肖玉连

unread,
Jun 16, 2011, 12:13:52 AM6/16/11
to openk...@googlegroups.com
change the printf code like this in the visualizeDepthData()
for ( int i = 0; i<1024; i++)
{
printf("VizDepth %d, %d\n", i, depth_mid[i]);
}

You just printf the first 8 pixels, which is just from 0- 8, usually it the the edge of the depth image and the usually will be 0.

2011/6/16 cnn lakshmen <laksh...@gmail.com>

lakshmen

unread,
Jun 16, 2011, 12:20:16 AM6/16/11
to OpenKinect
thanks alot but the value should be between 0 to 2048 right?? i can
get only between 0 to 255??

On Jun 16, 12:13 pm, 肖玉连 <xia...@eboxdeveloper.com> wrote:
> change the printf code like this in the visualizeDepthData()
> for ( int i = 0; i<1024; i++)
> {
> printf("VizDepth %d, %d\n", i, depth_mid[i]);
>
> }
>
> You just printf the first 8 pixels, which is just from 0- 8, usually it the
> the edge of the depth image and the usually will be 0.
>
> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> > sure thanks...
>
> > 2011/6/16 肖玉连 <xia...@eboxdeveloper.com>
>
> >> I will run it on my pc and test it for you
>
> >> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> >>> I have installed libfreenect driver... but i cant call the data out... I
> >>> have attached the file for your info.
>
> >>> 2011/6/16 肖玉连 <xia...@eboxdeveloper.com>
>
> >>>> Have u call the following function successfully?
> >>>> Have u install the libfreenect driver?
> >>>> freenect_set_depth_callback(f_dev, depth_cb);
> >>>> void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
>
> >>>> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> >>>>> hi,
>
> >>>>> thanks for replying... what i want to do is to print the
> >>>>> Freenect_depth_11bit value between the 0-2048. i know how to do the
> >>>>> conversion but what i want to print out is the raw depth data to ensure that
> >>>>> the value is the one i can manipulate.....when i print out the raw depth
> >>>>> data i get all zeros.
>
> >>>>> thanks,
> >>>>> lakshmen
>
> >>>>> 2011/6/16 肖玉连 <xia...@eboxdeveloper.com>
>
> >>>>>> The raw depth data (FREENECT_DEPTH_11BIT)is 0--2048 and you can
> >>>>>> transfer it to meters by the following function
> >>>>>> float RawDepthToMeters(int depthValue)
> >>>>>> {
> >>>>>> if (depthValue < 2047)
> >>>>>> {
> >>>>>> return float(1.0 / (double(depthValue) * -0.0030711016 +
> >>>>>> 3.3309495161));
> >>>>>> }
> >>>>>> return 0.0f;
> >>>>>> }
>
> >>>>>> BR
>
> >>>>>> On Thu, Jun 16, 2011 at 10:36 AM, cnn lakshmen <lakshme...@gmail.com>wrote:
>
> >>>>>>> i want to see the value between 0-2048... how to see that??
>
> >>>>>>> On Thu, Jun 16, 2011 at 10:31 AM, cnn lakshmen <lakshme...@gmail.com
> >>>>>>> > wrote:
>
> >>>>>>>> sorry to ask u all the stupid qns.. i really can't get the answer..
> >>>>>>>> thats why...
>
> >>>>>>>> On Thu, Jun 16, 2011 at 9:41 AM, cnn lakshmen <lakshme...@gmail.com
> >>>>>>>> > wrote:
>
> >>>>>>>>> but the data is encrypted, can't see..
>
> >>>>>>>>> On Thu, Jun 16, 2011 at 3:02 AM, Carlos Roberto <
> >>>>>>>>> carlo...@gmail.com> wrote:
>
> >>>>>>>>>> Hi,
> >>>>>>>>>> The depth buffer is in files where the names are saved as the
> >>>>>>>>>> example d--1096783991.813490-1844861182.pgm
> >>>>>>>>>> You can check in index.txt file about all files saved in the disk.
> >>>>>>>>>> Cheers.
>
> >>>>>>>>>> Carlos Roberto, MSc
> >>>>>>>>>> Software Eng. Consultant @ IBM
> >>>>>>>>>> My profiles: [image: LinkedIn]<http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378> [image:
> >>>>>>>>>> On Wed, Jun 15, 2011 at 6:21 AM, lakshmen <lakshme...@gmail.com>wrote:
>
> >>>>>>>>>>> But how do u extract out the depth data?
>
> >>>>>>>>>>> On Jun 15, 11:04 am, lakshmen <lakshme...@gmail.com> wrote:
> >>>>>>>>>>> > sorry i can save the data already
>
> >>>>>>>>>>> > On Jun 15, 10:47 am, lakshmen <lakshme...@gmail.com> wrote:
>
> >>>>>>>>>>> > > where does it save the data, i cant find the file
>
> >>>>>>>>>>> > > On Jun 15, 2:18 am, Carlos Roberto <carlo...@gmail.com>
> >>>>>>>>>>> wrote:
>
> >>>>>>>>>>> > > > Yes, you are right.
> >>>>>>>>>>> > > > You can read here about how it works.
> >>>>>>>>>>>https://github.com/OpenKinect/libfreenect/tree/master/fakenect
>
> >>>>>>>>>>> > > > Cheers.
>
> >>>>>>>>>>> > > > Carlos Roberto, MSc
> >>>>>>>>>>> > > > Software Eng. Consultant @ IBM
> >>>>>>>>>>> > > > My profiles: [image:
> >>>>>>>>>>> > > > LinkedIn]<
> >>>>>>>>>>>http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378>
> >>>>>>>>>>> > > > [image:
> >>>>>>>>>>> > > > Twitter] <http://twitter.com/#%21/ze_tech> [image:
> >>>>>>>>>>> > > > Blogger]<http://kinect-i.blogspot.com/>
> >>>>>>>>>>> > > > Signature powered by
> >>>>>>>>>>> > > > <
> >>>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu..
> >>>>>>>>>>> .>
> >>>>>>>>>>> > > > WiseStamp<
> >>>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu..
> >>>>>>>>>>> .>
>
> >>>>>>>>>>> > > > On Tue, Jun 14, 2011 at 9:16 AM, lakshmen <
> >>>>>>>>>>> lakshme...@gmail.com> wrote:
> >>>>>>>>>>> > > > > depth is in the dump_depth function.. am i right?
>
> >>>>>>>>>>> > > > > On Jun 14, 8:02 pm, Carlos Roberto <carlo...@gmail.com>
> >>>>>>>>>>> wrote:
> >>>>>>>>>>> > > > > > You can just run the record project to get depth data.
>
> >>>>>>>>>>> > > > > >http://openkinect.org/wiki/Fakenect#Record
>
> >>>>>>>>>>> > > > > > Carlos Roberto, MSc
> >>>>>>>>>>> > > > > > Software Eng. Consultant @ IBM
> >>>>>>>>>>> > > > > > My profiles: [image:
> >>>>>>>>>>> > > > > > LinkedIn]<
> >>>>>>>>>>>http://br.linkedin.com/pub/carlos-lacerda-msc/5/964/378>
> >>>>>>>>>>> > > > > > [image:
> >>>>>>>>>>> > > > > > Twitter] <http://twitter.com/#%21/ze_tech> [image:
> >>>>>>>>>>> > > > > > Blogger]<http://kinect-i.blogspot.com/>
> >>>>>>>>>>> > > > > > Signature powered by
> >>>>>>>>>>> > > > > > <
> >>>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu
> >>>>>>>>>>> ..
> >>>>>>>>>>> > > > > .>
> >>>>>>>>>>> > > > > > WiseStamp<
>
> >>>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu..
> >>>>>>>>>>> .>
>
> >>>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu
> >>>>>>>>>>> ..
> >>>>>>>>>>> > > > > .>
> >>>>>>>>>>> > > > > > > > > > WiseStamp<
>
> >>>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu
> >>>>>>>>>>> ..
> ...
>
> read more >>

肖玉连

unread,
Jun 16, 2011, 12:24:36 AM6/16/11
to openk...@googlegroups.com
Just see the following code in your cpp file. data in the depth_mid buffer has been transfered  to 0-255 which you called Pseudo-color. 

void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
switch (pval>>8) {
case 0:
depth_mid[3*i+0] = 255;
depth_mid[3*i+1] = 255-lb;
depth_mid[3*i+2] = 255-lb;
break;
case 1:
depth_mid[3*i+0] = 255;
depth_mid[3*i+1] = lb;
depth_mid[3*i+2] = 0;
break;


2011/6/16 lakshmen <laksh...@gmail.com>

cnn lakshmen

unread,
Jun 16, 2011, 12:28:54 AM6/16/11
to openk...@googlegroups.com
yes, i understand that, that just give the color but i am looking for depth... Or how is that related to depth? i am not getting the link...

2011/6/16 肖玉连 <xia...@eboxdeveloper.com>

肖玉连

unread,
Jun 16, 2011, 12:36:41 AM6/16/11
to openk...@googlegroups.com
void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)

data in the buffer v_depth will be 0-2048.
Since our eyes are more sensitive to color。
Preudo-color is just a method to show the image or picture of the data  which make us know what is in the data.
Usually, there will be a lookup table(LUT) to transform the data just like the following. 
case 0:
depth_mid[3*i+0] = 255;
depth_mid[3*i+1] = 255-lb;
depth_mid[3*i+2] = 255-lb;
break;



2011/6/16 cnn lakshmen <laksh...@gmail.com>

cnn lakshmen

unread,
Jun 16, 2011, 12:38:52 AM6/16/11
to openk...@googlegroups.com
how do u print out the v_depth value?? i want to print the v_depth value to see it...

2011/6/16 肖玉连 <xia...@eboxdeveloper.com>

cnn lakshmen

unread,
Jun 16, 2011, 12:40:22 AM6/16/11
to openk...@googlegroups.com
i can't seem to print the value of v_depth...

2011/6/16 cnn lakshmen <laksh...@gmail.com>

肖玉连

unread,
Jun 16, 2011, 2:00:25 AM6/16/11
to openk...@googlegroups.com
print in the depth callback function 
oid depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
{
int i;
uint16_t *depth = (uint16_t*)v_depth;
        for(int i = 0; i<640*480; i++)
  {
printf("%d", depth [i]);
)
  }
}

2011/6/16 cnn lakshmen <laksh...@gmail.com>

cnn lakshmen

unread,
Jun 16, 2011, 2:25:00 AM6/16/11
to openk...@googlegroups.com
thanks alot....

2011/6/16 肖玉连 <xia...@eboxdeveloper.com>

cnn lakshmen

unread,
Jun 16, 2011, 3:01:43 AM6/16/11
to openk...@googlegroups.com
have a look at this code, is it better now...is it doing the correct conversion?

2011/6/16 cnn lakshmen <laksh...@gmail.com>
cppview.cpp

cnn lakshmen

unread,
Jun 16, 2011, 3:10:49 AM6/16/11
to openk...@googlegroups.com
the code is doing plotting the depth data into point cloud... is it being done correctly?

2011/6/16 cnn lakshmen <laksh...@gmail.com>

cnn lakshmen

unread,
Jun 16, 2011, 6:05:54 AM6/16/11
to openk...@googlegroups.com
 the value 2047 shows that the object is far away and the value 0 shows the object is very close.. Am i right to say this?

2011/6/16 cnn lakshmen <laksh...@gmail.com>

lakshmen

unread,
Jun 20, 2011, 5:46:53 AM6/20/11
to OpenKinect

Just like to clarify something..

The forumla given by nicolas.burrus:

P3D.x = (x_d - cx_d) * depth(x_d,y_d) / fx_d
P3D.y = (y_d - cy_d) * depth(x_d,y_d) / fy_d
P3D.z = depth(x,y)

All the values given above are all in meters(both for x and y are in
meters). Am I right to say that?

On Jun 16, 6:05 pm, cnn lakshmen <lakshme...@gmail.com> wrote:
> the value 2047 shows that the object is far away and the value 0 shows the
> object is very close.. Am i right to say this?
>
> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> > the code is doing plotting the depth data into point cloud... is it being
> > done correctly?
>
> > 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> >> have a look at this code, is it better now...is it doing the correct
> >> conversion?
>
> >> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> >>> thanks alot....
>
> >>> 2011/6/16 肖玉连 <xia...@eboxdeveloper.com>
>
> >>>> print in the depth callback function
> >>>> oid depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
> >>>> {
> >>>> int i;
> >>>> uint16_t *depth = (uint16_t*)v_depth;
> >>>> for(int i = 0; i<640*480; i++)
> >>>> {
> >>>> printf("%d", depth [i]);
> >>>> )
> >>>> }
> >>>> }
>
> >>>> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> >>>>> i can't seem to print the value of v_depth...
>
> >>>>> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> >>>>>> how do u print out the v_depth value?? i want to print the v_depth
> >>>>>> value to see it...
>
> >>>>>> 2011/6/16 肖玉连 <xia...@eboxdeveloper.com>
>
> >>>>>>> void depth_cb(freenect_device *dev, void *v_depth, uint32_t
> >>>>>>> timestamp)
>
> >>>>>>> data in the buffer *v_depth *will be 0-2048.
> >>>>>>> Since our eyes are more sensitive to color。
> >>>>>>> Preudo-color is just a method to show the image or picture of the
> >>>>>>> data which make us know what is in the data.
> >>>>>>> Usually, there will be a lookup table(LUT) to transform the data just
> >>>>>>> like the following.
> >>>>>>> case 0:
> >>>>>>> depth_mid[3*i+0] = 255;
> >>>>>>> depth_mid[3*i+1] = 255-lb;
> >>>>>>> depth_mid[3*i+2] = 255-lb;
> >>>>>>> break;
>
> >>>>>>> 2011/6/16 cnn lakshmen <lakshme...@gmail.com>
>
> >>>>>>>> yes, i understand that, that just give the color but i am looking
> >>>>>>>> for depth... Or how is that related to depth? i am not getting the link...
>
> >>>>>>>> 2011/6/16 肖玉连 <xia...@eboxdeveloper.com>
>
> >>>>>>>>> Just see the following code in your cpp file. data in the depth_mid
> >>>>>>>>> buffer has been transfered to 0-255 which you called
> >>>>>>>>> Pseudo-color.
>
> >>>>>>>>> void depth_cb(freenect_device *dev, void *v_depth, uint32_t
> >>>>>>>>> timestamp)
> >>>>>>>>> switch (pval>>8) {
> >>>>>>>>> case 0:
> >>>>>>>>> depth_mid[3*i+0] = 255;
> >>>>>>>>> depth_mid[3*i+1] = 255-lb;
> >>>>>>>>> depth_mid[3*i+2] = 255-lb;
> >>>>>>>>> break;
> >>>>>>>>> case 1:
> >>>>>>>>> depth_mid[3*i+0] = 255;
> >>>>>>>>> depth_mid[3*i+1] = lb;
> >>>>>>>>> depth_mid[3*i+2] = 0;
> >>>>>>>>> break;
>
> >>>>>>>>> 2011/6/16 lakshmen <lakshme...@gmail.com>
> >>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu
> >>>>>>>>>> ..
> >>>>>>>>>> > >>>>>>>>>>> .>
> >>>>>>>>>> > >>>>>>>>>>> > > > WiseStamp<
>
> >>>>>>>>>>http://www.wisestamp.com/email-install?utm_source=extension&utm_mediu
> >>>>>>>>>> ..
> >>>>>>>>>> > >>>>>>>>>>> .>
>
> >>>>>>>>>> > >>>>>>>>>>> > > > On Tue, Jun 14, 2011 at 9:16 AM, lakshmen <
> >>>>>>>>>> > >>>>>>>>>>> lakshme...@gmail.com> wrote:
> >>>>>>>>>> > >>>>>>>>>>> > > > > depth is in the dump_depth function.. am i
> >>>>>>>>>> right?
>
> >>>>>>>>>> > >>>>>>>>>>> > > > > On Jun 14, 8:02 pm, Carlos Roberto <
> >>>>>>>>>> carlo...@gmail.com>
> >>>>>>>>>> > >>>>>>>>>>> wrote:
> >>>>>>>>>> > >>>>>>>>>>> > > > > > You can just run the record project to get
> >>>>>>>>>> depth data.
>
> >>>>>>>>>> > >>>>>>>>>>> > > > > >http://openkinect.org/wiki/Fakenect#Record
>
> >>>>>>>>>> > >>>>>>>>>>> > > > > > Carlos Roberto,
>
> ...
>
> read more >>

shorn william

unread,
Jun 20, 2011, 10:05:42 PM6/20/11
to openk...@googlegroups.com
yeah

2011/6/20 lakshmen <laksh...@gmail.com>



--
Good Luck and Have a day!

William Shorn
Mobile: 13811278218
MSN: willia...@hotmail.com
BeiJing People's Republic of China

lakshmen

unread,
Jun 21, 2011, 7:26:35 AM6/21/11
to OpenKinect
Two more questions:
1)How to get the R and T of the cameras.The values given by
nicolas.burrus are
R
[ 9.9984628826577793e-01, 1.2635359098409581e-03,
-1.7487233004436643e-02, -1.4779096108364480e-03,
9.9992385683542895e-01, -1.2251380107679535e-02,
1.7470421412464927e-02, 1.2275341476520762e-02,
9.9977202419716948e-01 ]

T
[ 1.9985242312092553e-02, -7.4423738761617583e-04,
-1.0916736334336222e-02 ]

But how do u go about to find out the values? does anyone know?
2) there was another forumla given by nicolas.burrus

P2D_rgb.x = (P3D'.x * fx_rgb / P3D'.z) + cx_rgb
P2D_rgb.y = (P3D'.y * fy_rgb / P3D'.z) + cy_rgb

Am i right to say that plotting x against y will give me the rgb
image?

Sorry to disturb you guys...

On Jun 21, 10:05 am, shorn william <shorn....@gmail.com> wrote:
> yeah
>
> 2011/6/20 lakshmen <lakshme...@gmail.com>
> ...
>
> read more >>
Reply all
Reply to author
Forward
0 new messages