Esempio n. 1
0
int main()
{
	gun_net = (struct neuronet *)malloc(sizeof(struct neuronet));
	notgun_net = (struct neuronet *)malloc(sizeof(struct neuronet));
	if (netfromfile(gun_net, GUN_NEURO_PATH) == -1) {
		fprintf(stderr, "Can not open file %s: %s\n", strerror(errno), GUN_NEURO_PATH);
		return -1;
	}
	if (netfromfile(notgun_net, NOTGUN_NEURO_PATH) == -1) {
		fprintf(stderr, "Can not open file %s: %s\n", strerror(errno), NOTGUN_NEURO_PATH);
		return -1;
	}

	struct IplImage *frame;
	struct IplDev *dev1;
	FILE *fo;
	int f, i;
	char name[256];

	
	f = 0;
	if ((dev1 = ipl_opendev(0, IPL_RGB_MODE)) == NULL)
		printf("error while creating device 0\n");
	if (ipl_setparams(dev1, 320, 240, IPL_FORCE_SCALE_OFF) < 0) {
		fprintf(stderr, "error on changing cam params\n");
		free(dev1);
	}

	while (1) {
		f++;	
	
		if ((frame = ipl_getframe(dev1)) == NULL) {
			printf("error capturing curr1\n");
		}
		ipl_scaleimg(&frame, 640, 480);

		if(neurowork(frame))
			fprintf(stderr, "error in neurowork\n");

		bzero(name, 256);
		sprintf(name, "/home/user/frame%d.ppm", f);
		fo = fopen(name, "w+");
		fprintf(fo, "P3\n");
		fprintf(fo, "%d %d\n", frame->width, frame->height);
		fprintf(fo, "255\n");
		

		for (i = 0; i < frame->width * frame->height * frame->nchans; i++)
			fprintf(fo, "%u\n", frame->data[i]);
		fclose(fo);

		ipl_freeimg(&frame);
	}

	return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	int x, y;

	Window win1;
	GC gc1;
	XEvent event;
	XImage *ximg1;

	int flag;
	struct IplImage *prev1, *curr1, *motion;
	struct IplDev *dev1;

	time_t start, end;
	int f;

	f = 0;
	start = 0;
	end = 0;
	
	x = 0;
	y = 0;
	initX();
	getXinfo();
	win1 = openWindow(500, 500, 640, 480, 0, &gc1);
	XNextEvent(theDisplay, &event);
	ximg1 = XGetImage(theDisplay, win1, x, y, 640, 480, AllPlanes, ZPixmap);
	if(XInitImage(ximg1) == 0) {
		fprintf(stderr,"error: XInitImage\n");
		return 1;
	}

	printf("first xgetimage done\n");

	if ((dev1 = ipl_opendev(0, IPL_RGB_MODE)) == NULL) {
		printf("error while creating device 0\n");
		return 1;
	}

	if (ipl_setparams(dev1, 320, 240, IPL_FORCE_SCALE_ON) < 0) {
		fprintf(stderr, "error on changing cam params\n");
		free(dev1);
		return 1;
	}
	if ((prev1 = ipl_getframe(dev1)) == NULL) {
		printf("error capturing prev1\n");
		return 1;
	}


	flag = 1;
	start = time(NULL);
	
	while (flag) {
		f++;	
		end = time(NULL);
		if (end - start >= 1.0) {
			printf("fps = %i\n", f);
			f = 0;
			start = end;
		}
	
		if ((curr1 = ipl_getframe(dev1)) == NULL) {
			printf("error capturing curr1\n");
			return 1;
		}
		motion = framescompare(curr1, prev1);
		ipl_scaleimg(&motion, 640, 480);
		camera_shoot(motion, ximg1, gc1, win1, x, y);
		ipl_freeimg(&prev1);
		prev1 = curr1;


		ipl_freeimg(&motion);
		XCheckTypedWindowEvent(theDisplay, win1, ButtonPress, &event);
		if (event.xbutton.button == 1)
			flag = 0;
	}

	ipl_freeimg(&curr1);
	XDestroyImage(ximg1);
	XDestroyWindow(theDisplay, win1);

	quitX();


	return 0;
}