This is old, from December 2010 it seems, but it's here in case the machine goes titsup. Quick, dirty and ugly but it works most of the time. First, the capture program:
#include <libusb-1.0/libusb.h>
#include "libfreenect.h"
#include "libfreenect_sync.h"
#include <stdio.h>
#include <stdlib.h>
/*
No error checking performed whatsoever; dealing with it later (or not).
*/
int main(int argc, char** argv)
{
uint16_t * depth = (uint16_t *)malloc(FREENECT_DEPTH_11BIT_SIZE);
uint32_t timestamp;
int index = 0;
freenect_depth_format fmt = FREENECT_DEPTH_11BIT;
uint8_t * depth8 = (uint8_t *)malloc(FREENECT_FRAME_PIX);
int i;
/* Capture one Kinect depth frame */
freenect_sync_get_depth(&depth, ×tamp, index, fmt);
/* Convert captured frame to an 8-bit greyscale image */
for(i = 0; i < FREENECT_FRAME_PIX; i++) {
depth8[i] = (2048 * 256) / (2048.0 - depth[i]);
}
/* Write raw greyscale image to stdout */
fwrite(depth8, FREENECT_FRAME_PIX, 1, stdout);
return 0;
}
(Don't know if it's the Suffusion theme or what that kill all the newlines from these listings. They're there, I can assure you, they're just not visible.)