Calibration after data collection

66 views
Skip to first unread message

mankoff

unread,
Mar 23, 2012, 10:48:09 AM3/23/12
to openk...@googlegroups.com
I'm trying to make a little utility that calibrates the Kinect data after the data collection occurs. I'm having a bit of trouble with the second part of this and hope I can get some pointers from the developers.

My ideal workflow is:

1) Record data with a modified version of 'record'.

The modified version dumps the kinect registration parameters to disk, in addition to including 'glview' so that I can see what I am recording. I do this so that I can record at 30 Hz, and record the raw data.

2) Later, convert the raw data to world coordinates. Perhaps after combining several hundred depth-PGM files into one thereby greatly reducing the signal-to-noise ratio and improving accuracy and precision.

So far, the dumping is done like this:

 freenect_context *f_ctx;
 freenect_device *f_dev;
 freenect_registration thisDevice;
 int user_device_number = 0;
 freenect_init(&f_ctx, NULL)
 freenect_select_subdevices(f_ctx, (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA));
 freenect_open_device(f_ctx, &f_dev, user_device_number)
 thisDevice = freenect_copy_registration( f_dev );
 char fn[ ] = "regdump.dat";
 FILE* fp = fopen(fn, "w");
 fwrite( &thisDevice, sizeof(thisDevice), 1, fp);
 fclose(fp);

This produces 'regdump.dat', which is 176 bytes.

The second part, done at a later time, takes one PGM file and the regdump.dat and attempts to produce some processed data (a PGM with mm values, and an x,y,z ASCII file).

I load the raw PGM and the regdump.dat file produced above, but when I call 'freenect_apply_registration(&dev, PGMdata, wz);', it wants a pointer to a 'freenect_device', not a 'freenect_registration'. So, it seems I need to dump the freenect device into the regdump.dat file in addition to the registration, but I'm not sure how.

I can't find an inverse function for this:  thisDevice = freenect_copy_registration( f_dev );

And this might be a basic C issue, but I'm not sure how to write out f_dev, since it is a pointer to a complex structure, and I don't know how to determine the full size of that structure.

Any hints much appreciated.

Thanks,

   -k.

drew.m...@gmail.com

unread,
Mar 23, 2012, 1:29:41 PM3/23/12
to openk...@googlegroups.com

Note that the freenect_registration struct contains several pointers.
You'll have to do a deeper copy to save the following:

uint16_t* raw_to_mm_shift;
int32_t* depth_to_rgb_shift;
int32_t (*registration_table)[2];

(which are, incidentally, the fields that you care about more.) Each
struct's actual size can be found in freenect_copy_registration() in
registration.c where the field is malloc()'d.

> The second part, done at a later time, takes one PGM file and the
> regdump.dat and attempts to produce some processed data (a PGM with mm
> values, and an x,y,z ASCII file).
>
> I load the raw PGM and the regdump.dat file produced above, but when I call
> 'freenect_apply_registration(&dev, PGMdata, wz);', it wants a pointer to a
> 'freenect_device', not a 'freenect_registration'. So, it seems I need to
> dump the freenect device into the regdump.dat file in addition to the
> registration, but I'm not sure how.

That function uses the freenect_device solely to get at the
freenect_registration contained therein.

> I can't find an inverse function for this:  thisDevice =
> freenect_copy_registration( f_dev );
>
> And this might be a basic C issue, but I'm not sure how to write out f_dev,
> since it is a pointer to a complex structure, and I don't know how to
> determine the full size of that structure.

Just copy freenect_apply_registration (it's not public API anyway) and
change it so you pass it the freenect_registration* instead of it
pulling it out of the device on the first line.

-Drew

Reply all
Reply to author
Forward
0 new messages