示例#1
0
/** 
* @brief Copy part of display
* 
* @param display gui_diaplay instance
* @param rect    rectangle to copy
* @param img
* 
* @return 
*/
wg_status
gui_display_copy(Gui_display *display, Wg_rect *rect, Wg_image *img)
{
    wg_uchar *buffer = NULL;
    Wg_image image;
    Wg_image rect_image;
    wg_uint width  = 0;
    wg_uint height = 0;
    cam_status status = CAM_FAILURE;

    gdk_threads_enter();

    width  = gdk_pixbuf_get_width(display->pixbuf);
    height = gdk_pixbuf_get_height(display->pixbuf);
    buffer = gdk_pixbuf_get_pixels(display->pixbuf); 

    status = img_rgb_from_buffer(buffer, width, height, &image);
    if (CAM_FAILURE == status){
        return WG_FAILURE;
    }

    gdk_threads_leave();

    status = img_fill(rect->width, rect->height,
            RGB24_COMPONENT_NUM, IMG_RGB, &rect_image);
    if (CAM_FAILURE == status){
        img_cleanup(&image);
        return WG_FAILURE;
    }

    status = img_get_subimage(&image, rect->x, rect->y, &rect_image);
    if (CAM_FAILURE == status){
        img_cleanup(&image);
        img_cleanup(&rect_image);
        return WG_FAILURE;
    }

    status = img_rgb_2_hsv_gtk(&rect_image, img);
    if (CAM_FAILURE == status){
        img_cleanup(&image);
        img_cleanup(&rect_image);
        return WG_FAILURE;
    }

    img_cleanup(&image);
    img_cleanup(&rect_image);

    return WG_SUCCESS;
}
示例#2
0
文件: teacher.c 项目: xieran1988/asys
void process()
{
/*
	static int tmc=0;
	tmc++;
	if(tmc==30)
	{
		tmc=0;
		set_indoor();
	}
*/
	int x, y;


	//初始化背景
	if(bInited==0)
	{
		static int initCount=0;
		if(initCount<30)
		{
			initCount++;
			img_copy(&BACK, &Y);
		}
		else
		{
			bInited=1;
			img_fill(&UBAK, 0);
			set_target_pan_tilt(0, 0);
			set_zoom(1);
		}
		return;
	}

	img_fill(&COMP, 0);
	img_fill(&COMPB, 0);
	img_fill(&CLUS, 0);
	img_fill(&LABEL, 0); 

	//计算准备
	for (y = masky1; y < masky2; y++)
		for (x = maskx1; x < maskx2; x++)
		{
			COMP.data[y][x] = abs(Y.data[y][x] - PREV.data[y][x]) > compare_th ? 255 : 0;
			if(Y.data[y][x] < dark || PREV.data[y][x] < dark)
				COMP.data[y][x] = abs(Y.data[y][x] - PREV.data[y][x]) > compare_th*dark_th ? 255 : 0;

			COMPB.data[y][x] = abs(Y.data[y][x] - BACK.data[y][x]) > compare_th2 ? 255 : 0;
			if(Y.data[y][x] < dark || BACK.data[y][x] < dark)
				COMPB.data[y][x] = abs(Y.data[y][x] - BACK.data[y][x]) > compare_th2*dark_th ? 255 : 0;
		}
	img_copy(&PREV, &Y);

	

	//选择性更新背景
	updataBack();

	//聚类
	cluster();

	img_copy(&LABEL, &CLUS);

	//连通域
	int k=label();

	img_plot_rect(&Y, maskx1, masky1, 
			maskx2 - maskx1, masky2 - masky1, 128);

	
	//输出连通域信息
	int i=0;
	mon("count: %d\n", k);
	for(i=0;i<k;i++)
	{
		mon("area%d: %d\n", i, Box[i].area);
		
	}

	float p=0,t=0,z=1;
	int ml=IMG_W,mr=0,cx=0,dx;
	for(i=0;i<k;i++)
	{
		if(Box[i].left < ml) ml = Box[i].left;
		if(Box[i].right > mr) mr = Box[i].right;
	}
	cx=(ml+mr)/2;
	dx=(mr-ml)*1.3;
	
	p = (float)(cx - IMG_W/2) / (IMG_W/2) * (PAN_RANGE/2);
	

	z = CAM_RANGE / ((float)dx / IMG_W * PAN_RANGE);

	if(z<1.0)
		z=1;
	
	printf("--------%d\n",k);

	myTimer(&p,&t,&z,k);
	set_target_pan_tilt(p, t);
	set_zoom(z);
	
	
	mon("PZ:%f,%f\n", p, z);
	
}