Exemplo n.º 1
0
int main(int argc, char **argv)
{
	struct ctx ctx = { };
	int key;
	char *imageFile = argv[1];
	ctx.image = cvLoadImage(imageFile, 1);
	//init_capture(&ctx);
	//init_recording(&ctx);
	init_windows();
	init_ctx(&ctx);

	//do {
		// ctx.image = cvQueryFrame(ctx.capture); 
		//ctx.image = cvLoadImage("/home/csrobot/Downloads/grab_box/images/OtivvoH.jpg", 1);
		//fprintf(stdout, "image loaded\n");
		filter_and_threshold(&ctx);
		find_contour(&ctx);
		find_convex_hull(&ctx);
		find_fingers(&ctx);

		display(&ctx);
		cvWriteFrame(ctx.writer, ctx.image);

		key = cvWaitKey(0);
	//} while (key != 'q');

	return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    struct ctx ctx = { };
    int key;
    CvPoint last_center;
    last_center.x = 0;
    last_center.y = 0;
    int threshold_x = 50;
    int threshold_y = 50;

    init_capture(&ctx);
    init_windows();
    init_ctx(&ctx);

    do
    {
        ctx.image = cvQueryFrame(ctx.capture);

        filter_and_threshold(&ctx);
        find_contour(&ctx);
        find_convex_hull(&ctx);
        find_fingers(&ctx);

        display(&ctx);
//cvWriteFrame(ctx.writer, ctx.image);

//printf("num: %d rad: %d def: %d x: %d y: %d\n", ctx.num_fingers, ctx.hand_radius, ctx.num_defects, ctx.hand_center.x, ctx.hand_center.y);

        if(ctx.num_fingers && ctx.hand_radius)
        {
            if(!last_center.x)
            {
                last_center = ctx.hand_center;

            }
            else
            {
                //Check If Position changed

                if( abs(ctx.hand_center.x - last_center.x)  > threshold_x )
                {
                    if( ctx.hand_center.x - last_center.x > 0 )
                    {
                        printf("move left\n");
                    }
                    else
                    {
                        printf("move right\n");
                    }
                }

                if( abs(ctx.hand_center.y - last_center.y)  > threshold_y )
                {
                    if( ctx.hand_center.y - last_center.y > 0 )
                    {
                        printf("move down\n");
                    }
                    else
                    {
                        printf("move up\n");
                    }
                }


                last_center = ctx.hand_center;

            }



        }




        key = cvWaitKey(1);
    }
    while (key != 'q');

    return 0;
}