shithub: util

ref: 970b9575619b8d39bac6554449ff164d6d5ceef6
dir: /motion.c/

View raw version
#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;
	}
}