コード例 #1
0
int main(int argc, const char* argv[])
{

	if (argc < 5){
		printf("USAGE: %s <device> <filename> <width> <height> [<wait>]\n", argv[0]);
		return 1;
	}

	const char *device = argv[1];
	const char *filename = argv[2];
	float width = atof(argv[3]);
	float height = atof(argv[4]);

	int wait = 0;
	if (argc == 6){
		wait = atoi(argv[5]);
	}

	int fd = koki_v4l_open_cam(device);
	struct v4l2_format fmt = koki_v4l_create_YUYV_format(width, height);
	koki_v4l_set_format(fd, fmt);

	int num_buffers = 1;
	koki_buffer_t *buffers;
	buffers = koki_v4l_prepare_buffers(fd, &num_buffers);

	koki_v4l_start_stream(fd);

	if (wait){
		fprintf(stderr, "Press [ENTER] to take photo...\n");
		getchar();
	}

	uint8_t *yuyv = koki_v4l_get_frame_array(fd, buffers);
	IplImage *frame = koki_v4l_YUYV_frame_to_grayscale_image(yuyv, width, height);
	cvSaveImage(filename, frame, 0);

	cvReleaseImage(&frame);
	koki_v4l_stop_stream(fd);

	return 0;
}
コード例 #2
0
ファイル: take_photo.c プロジェクト: PSC-SR/libkoki
int main(int argc, const char **argv)
{

	int fd;
	int num_buffers = 1;
	struct v4l2_format fmt;
	const char *dev;
	const char *filename;
	koki_buffer_t *buffers;
	uint8_t *frame;
	IplImage *output;

	if (argc != 3){
		printf("Usage: %s VIDEO_DEVICE FILENAME\n", argv[0]);
		return 1;
	}

	dev = argv[1];
	filename = argv[2];

	fd = koki_v4l_open_cam(dev);

	if (fd == -1){
		printf("Couldn't open camera '%s'\n", dev);
		return 1;
	}

	fmt = koki_v4l_create_YUYV_format(WIDTH, HEIGHT);
	if (koki_v4l_set_format(fd, fmt) < 0){
		printf("Unable to set format:\n");
		koki_v4l_print_format(fmt);
		return 1;
	}

	buffers = koki_v4l_prepare_buffers(fd, &num_buffers);

	if (num_buffers < 1){
		printf("Not enough buffer(s)\n");
		return 1;
	}

	if (koki_v4l_start_stream(fd) < 0){
		printf("Unable to start stream\n");
		return 1;
	}

	frame = koki_v4l_get_frame_array(fd, buffers);
	assert(frame != NULL);

	output = koki_v4l_YUYV_frame_to_RGB_image(frame, WIDTH, HEIGHT);

	cvSaveImage(filename, output, 0);

	cvReleaseImage(&output);

	koki_v4l_stop_stream(fd);
	koki_v4l_close_cam(fd);

	return 0;

}
コード例 #3
0
int main(void)
{

	koki_camera_params_t params;

	params.size.x = WIDTH;
	params.size.y = HEIGHT;
	params.principal_point.x = params.size.x / 2;
	params.principal_point.y = params.size.y / 2;
	params.focal_length.x = 571.0;
	params.focal_length.y = 571.0;

	int fd = koki_v4l_open_cam("/dev/video0");
	struct v4l2_format fmt = koki_v4l_create_YUYV_format(WIDTH, HEIGHT);
	koki_v4l_set_format(fd, fmt);

	int num_buffers = 1;
	koki_buffer_t *buffers;
	buffers = koki_v4l_prepare_buffers(fd, &num_buffers);

	koki_v4l_start_stream(fd);

	while (1){

		uint8_t *yuyv = koki_v4l_get_frame_array(fd, buffers);
		IplImage *frame = koki_v4l_YUYV_frame_to_RGB_image(yuyv, WIDTH, HEIGHT);

		IplImage *thresholded;
		thresholded = koki_threshold_adaptive(frame, 5, 3,
						      KOKI_ADAPTIVE_MEAN);
		cvShowImage("thresh", thresholded);

		koki_labelled_image_t *l = koki_label_image(thresholded, 128);

		for (int i=0; i<l->clips->len; i++){

			if (!koki_label_useable(l, i))
				continue;

			GSList *contour = koki_contour_find(l, i);

			koki_quad_t *quad = koki_quad_find_vertices(contour);

			if (quad == NULL){
				koki_contour_free(contour);
				continue;
			}

			koki_contour_draw(frame, contour);
			koki_quad_refine_vertices(quad);
			koki_quad_draw(frame, quad);

			koki_marker_t *marker;
			marker = koki_marker_new(quad);

			if (koki_marker_recover_code(marker, frame)){

				koki_pose_estimate(marker, 0.11, &params);
				koki_bearing_estimate(marker);

				printf("marker code: %d\n", marker->code);

			}

			koki_contour_free(contour);
			koki_quad_free(quad);
			koki_marker_free(marker);

		}//for

		cvShowImage("frame", frame);
		cvWaitKey(1);

		koki_labelled_image_free(l);
		cvReleaseImage(&thresholded);
		cvReleaseImage(&frame);

	}

	return 0;

	cvDestroyWindow("frame");
	cvDestroyWindow("thresh");

}