ref: 30d7ba73ff01b66e88e28faa260583935a20c1d7
dir: /motion.c/
#include <u.h> #include <libc.h> #include <draw.h> #include <memdraw.h> void usage(void) { sysfatal("usage:\n\t%s [-v]\n", argv0); } void main(int argc, char **argv) { Memimage *last, *this; unsigned long long dist; int len; int thresh; int i; int debug = 0; ARGBEGIN { case 'v': debug = 1; break; default: usage(); } ARGEND; last = readmemimage(0); len = bytesperline(last->r, last->depth) * Dy(last->r); thresh = (len / 3) * 10; if (debug) fprint(2, "%d %d\n", len, thresh); while(1) { this = readmemimage(0); dist = 0; for (i = 0; i < len; i++) { dist += abs(this->data->bdata[i] - last->data->bdata[i]); } if (debug) fprint(2, "%llud\n", dist); if (dist > thresh) writememimage(1, this); freememimage(last); last = this; } }