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.)
The idea here is to periodically fetch() and keep the client and server Collections in sync in such a way that the consuming View(s) only get updated when a Model is added to or removed from a Collection, or the attributes of one of the Models in it change. What's done is:
Compare the existing Collection to the incoming set and remove every Model from the existing Collection that is not in the incoming set.
Compare the incoming set to the existing Collection and add every Model from the incoming set to the existing Collection that is not already there.
Compare each Model in the two sets and update the ones in the existing Collection to the ones in the incoming set that are different.
The first two steps compare the Model's resource_uris and the last part is done with SHA1 hashes.
Update 3: looking at this afterwards, I'm not sure of the complete watertightness of the above. Perhaps the Backbone Poller project would be be a better approach.
Update 2: In order to avoid borking on an empty response, do:
var attrs = Backbone.Model.prototype.parse.apply(this, data);
if(!attrs) return;
Update: My Javascript-Fu is weak which made me not see the obvious. As suggested in Backbone.js documentation, you can call the parent's implementation like this:
;;;;;;;;;;;;;;;;;;;;
;; set up unicode
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; This from a japanese individual. I hope it works.
(setq default-buffer-file-coding-system 'utf-8)
;; From Emacs wiki
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; MS Windows clipboard is UTF-16LE
(set-clipboard-coding-system 'utf-16le-dos)
Also, add this to the beginning of your source files when working with Python (otherwise you'll get "SyntaxError: Non-ASCII character '\xc3' in file…" etc. errors):