int read_frame(void) {
	struct v4l2_buffer buf;

	memset(&buf, 0, sizeof(buf));
	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	buf.memory = V4L2_MEMORY_MMAP;

	if (ioctl(fd_camera, VIDIOC_DQBUF, &buf) != 0) {
		if (errno != EAGAIN && errno != EIO) {
			perror("red_frame: VIDIOC_DQBUF");
			exit(EXIT_FAILURE);
		} else {
			return 0;
		}
	}

	if (buf.index > n_buffers) {
		fprintf(stderr, "Wrong buffer size\n");
		exit(EXIT_FAILURE);
	}

	make_ppm(buffers[buf.index].start, "image.ppm", width, height);

	if (ioctl(fd_camera, VIDIOC_QBUF, &buf) != 0) {
		perror("read_frame: VIDIOC_QBUF");
		exit(EXIT_FAILURE);
	}

	return 1;
}
Beispiel #2
0
int makeImage(double m1, double b1, double m2, double b2, int count, int w, int h) {
	double m[2] = {2,-2}, b[2] = {0,200};
	int add_noise = 0;

	m[0] = m1; m[1] = m2;
	b[0] = b1; b[1] = b2;
	add_noise = 0;
	printf("Producing frame %d with m = %f b = %f add_noise = %d\n", count, m[0], b[0], add_noise);

	unsigned char *img = (unsigned char *)malloc(w*h*3);

	for (int i=0; i< w*h; i++)  // set it to blue;
	{
		img[3*(i) + 0] = 40;  // B?
		img[3*(i) + 1] = 0; // G
		img[3*(i) + 2] = 0; // R
	}

	int max_r_c= (h>w) ? h : w;
	double y=0, x=0, this_b, this_m;
	int row, col, r_err=0, c_err=0;

	for (int l=0; l<2; l++)
	{
		this_b=b[l];
		this_m=m[l];
		for(int i=0; i< max_r_c; i++)
		{
			if (fabs(this_m) < 1)
			{
				y=this_m*i+this_b;
				col = i;
				row = (int)(y+.5);
			}
			else
			{
				x=(i-this_b)/this_m;
				row = i;
				col = (int)(x+.5);
			}
			if (add_noise)
			{
				col = col+(c_err=rand_err());
				row = row+(r_err=rand_err());
			}
			if ((col>=0)&&(row>=0)&&(col<w)&&(row<h))
			{
				img[3*(col+row*w)+0]=0;
				img[3*(col+row*w)+1]=0;
				img[3*(col+row*w)+2]=125;
			}
		}
	}


	make_ppm("test.ppm", img, w, h);
	char msg[100];
	/*sprintf(msg, "ppmtobmp test.ppm > %d.bmp", count);
	system(msg);
	sprintf(msg, "pnmtojpeg test.ppm -quality 95 > %d.jpg", count);
	system(msg);*/
	sprintf(msg, "pnmtotiff test.ppm > %d.tiff", count);
	system(msg);


	return 0;
}