⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edgedetector.cc

📁 不错的shijuegezong的程序
💻 CC
📖 第 1 页 / 共 3 页
字号:
    Point2 pos_base = pos + Point2(0.5, 0.5);//    Point2 line_offset = edge_scale * search_line;        for (int i = -nsubs;i <= nsubs; i++)    {	realno d_i = i * edge_scale;		realno e_i = significance_threshold-1.0;	Point2 pos_i = pos_base + (d_i * search_line);	if (occlusion_map->is_occlusion(pos_i.x, pos_i.y))	    return EDGE_OCCLUDED;	//       if (!(occlusion_map->is_occlusion(pos_i.x, pos_i.y) ||// 	    occlusion_map->is_occlusion(pos_i.x + line_offset.x,// 					pos_i.y + line_offset.y) ||// 	    occlusion_map->is_occlusion(pos_i.x - line_offset.x,// 					pos_i.y - line_offset.y)))	if (!(*edge_response)((int) pos_i.x, (int) pos_i.y, grid_scale, normal,			      e_i, tracker->get_active_model()))	    return EDGE_OCCLUDED;	realno new_e_i = 0;		if (e_i > significance_threshold)	{	    new_e_i = e_i;	    if (e_i > max_e)	    {		max_e = e_i;		best = d_i;	    }	}		sum_e += new_e_i;	sum_d += d_i * new_e_i;	sq_sum += d_i * d_i * new_e_i;	    }        if (sum_e == 0)	return EDGE_BAD;        realno mean = sum_d / sum_e;    //realno mean = best;    var = 0.25 * ((sq_sum / sum_e) - (mean * mean));    p_obs = pos_base + mean * search_line;    // var += 0.25 * edge_scale * edge_scale;    return EDGE_GOOD;}edge_status_tGenericEdgeDetector::max_edge(Point2 &pos, Point2 &search_line,			      Point2 &normal, realno window_size,			      OcclusionHandler *occlusion_map,			      Profile *currx,			      Point2 &p_obs, realno &var,			      ActiveModel *active_model){    int nsubs; // sampling size        if (window_size > max_scale)  // this will generally be the case	nsubs = (int) (0.5 + (window_size / max_scale));    else	nsubs = 1;        realno edge_scale = window_size / ((realno) nsubs);    int grid_scale = (int) (edge_scale + 0.5);    var = 0;    realno max_e = -significance_threshold;        Point2 pos_base = pos + Point2(0.5, 0.5);    for (int i = -nsubs;i <= nsubs; i++)    {	Point2 offset =  (i * edge_scale) * search_line;		realno e_i;	Point2 pos_i = pos_base + offset;	if (occlusion_map->is_occlusion(pos_i.x, pos_i.y))	    return EDGE_OCCLUDED;		if (!(*edge_response)((int) pos_i.x, (int) pos_i.y, grid_scale, normal,			      e_i, tracker->get_active_model()))	    return EDGE_OCCLUDED;		if (e_i > max_e)	{	    max_e = e_i;	    p_obs = pos_i;	}	    }        if (max_e <= significance_threshold)	return EDGE_BAD;        // var = 0.25 * edge_scale * edge_scale;    return EDGE_GOOD;}edge_status_tGenericEdgeDetector::nearest_edge(Point2 &pos, Point2 &search_line,				  Point2 &normal, realno window_size,				  OcclusionHandler *occlusion_map,				  Profile *currx,				  Point2 &p_obs, realno &var,				  ActiveModel *active_model){    int nsubs; // sampling size        if (window_size > max_scale)  // this will generally be the case	nsubs = (int) (0.5 + (window_size / max_scale));    else	nsubs = 1;        realno edge_scale = window_size / ((realno) nsubs);    int grid_scale = (int) (edge_scale + 0.5);    var = 0;//    realno max_e = -significance_threshold;    realno e_i;        Point2 pos_base = pos + Point2(0.5, 0.5);    p_obs = pos_base;        if (occlusion_map->is_occlusion(pos_base.x, pos_base.y))	return EDGE_OCCLUDED;  ///  FIXME: nts: was EDGE_BAD --- ????        if (!(*edge_response)((int) pos_base.x, (int) pos_base.y, grid_scale,			  normal, e_i, tracker->get_active_model()))	return EDGE_BAD;        if (e_i > significance_threshold)	return EDGE_GOOD;        for (int i = 1; i <= nsubs; i++)    {	Point2 offset =  (i * edge_scale) * search_line;	Point2 pos_i = pos_base + offset;		if (occlusion_map->is_occlusion(pos_i.x, pos_i.y))	    return EDGE_OCCLUDED;		if (!(*edge_response)	    ((int) pos_i.x, (int) pos_i.y, grid_scale, normal, e_i, tracker->get_active_model()))	    return EDGE_OCCLUDED;		if (e_i > significance_threshold)	{	    p_obs = pos_i;	    return EDGE_GOOD;	}		pos_i = pos_base - offset;	if (occlusion_map->is_occlusion(pos_i.x, pos_i.y))	    return EDGE_OCCLUDED;		if (!(*edge_response)((int) pos_i.x, (int) pos_i.y, grid_scale, normal,			      e_i, tracker->get_active_model()))	    return EDGE_OCCLUDED;	if (e_i > significance_threshold)	{	    p_obs = pos_i;	    return EDGE_GOOD;	}    }        return EDGE_BAD;    }SobelEdgeDetector::SobelEdgeDetector(realno thresh,				     edge_search_method_t mthd,				     ActiveShapeTracker *the_tracker) :    GenericEdgeDetector(mthd){    assert (the_tracker != NULL);    tracker = the_tracker;        set_significance_threshold(thresh);        if (tracker->get_active_model()->get_video_image_type() == GREY8)	edge_response = &grey_sobel;    else	if (tracker->get_active_model()->get_video_image_type() == RGB32)	    edge_response = &rgb_sobel;	else	{	    cerror << "SobelEdgeDetector::SobelEdgeDetector: "		   << "Invalid image type, cannot work. " << endl;	    exit(1);    	}}inline realno SobelEdgeDetector::get_maximum_response(){    if (tracker->get_active_model()->get_video_image_type() == GREY8)	return 4.0 * 255;    else	if (tracker->get_active_model()->get_video_image_type())	    return 2.0 * MAX_RGB_DISTANCE;	else	{	    cerror << "SobelEdgeDetector::get_maximum_response(): "		   << "Invalid image type, expect trouble" << endl;	    return 0;	}}SimpleEdgeDetector::SimpleEdgeDetector(realno thresh, edge_search_method_t mthd,				       ActiveShapeTracker *the_tracker)    : GenericEdgeDetector(mthd){    assert (the_tracker != NULL);    tracker = the_tracker;        if (tracker->get_active_model()->get_video_image_type() == GREY8)	edge_response = &grey_simple;    else	if (tracker->get_active_model()->get_video_image_type() == RGB32)	    edge_response = &rgb_simple;	else    	{	    cerror << "SimpleEdgeDetector::SimpleEdgeDetector: "		   << "Invalid image type, cannot work. " << endl;	    exit(1);    	}    set_significance_threshold(thresh);}inline realno SimpleEdgeDetector::get_maximum_response(){    if (tracker->get_active_model()->get_video_image_type() == GREY8)	return 255;    else	if (tracker->get_active_model()->get_video_image_type() == RGB32)	    return MAX_RGB_DISTANCE;	else	{	    cerror << "SobelEdgeDetector::get_maximum_response(): "		   << "Invalid image type, expect trouble" << endl;	    return 0;	}}MovingEdgeDetector::MovingEdgeDetector(realno thresh,				       edge_search_method_t mthd,				       ActiveShapeTracker *the_tracker)    : GenericEdgeDetector(mthd){    assert (the_tracker != NULL);    tracker = the_tracker;        if (tracker->get_active_model()->get_video_image_type() == RGB32)	edge_response = &rgb_moving_edge;    else	if (tracker->get_active_model()->get_video_image_type() == GREY8)	    edge_response = &grey_moving_edge;	else    	{	    cerror << "MovingEdgeDetector::MovingEdgeDetector: "		   << "Invalid image type, cannot work. " << endl;	    exit(1);    	}    set_significance_threshold(thresh);}inline realno MovingEdgeDetector::get_maximum_response(){    if (tracker->get_active_model()->get_video_image_type() == GREY8)	return 2.0 * 255;    else	if (tracker->get_active_model()->get_video_image_type() == RGB32)	    return 2.0 * MAX_RGB_DISTANCE;	else	{	    cerror << "MovingEdgeDetector::get_maximum_response(): "		   << "Invalid image type, expect trouble" << endl;	    return 0;	}}ForegroundEdgeDetector::ForegroundEdgeDetector(realno thresh_lower,					       realno thresh_upper,					       edge_search_method_t mthd,					       ActiveShapeTracker *the_tracker)    : GenericEdgeDetector(mthd){    assert (the_tracker != NULL);    tracker = the_tracker;        if (tracker->get_active_model()->get_video_image_type() == RGB32)	edge_response = &rgb_foreground_edge;    else	edge_response = &grey_foreground_edge;        set_significance_threshold(0.0);    thresh_background = thresh_lower * get_maximum_response();    thresh_foreground = thresh_upper * get_maximum_response();}realno ForegroundEdgeDetector::get_maximum_response(){    if (tracker->get_active_model()->get_video_image_type() == GREY8)	return MAX_GREY_DISTANCE;    else	if (tracker->get_active_model()->get_video_image_type() == RGB32)	    return MAX_RGB_DISTANCE;	else	{	    cerror << "ForegroundEdgeDetector::get_maximum_response(): "		   << "Invalid image type, expect trouble" << endl;	    return MAX_RGB_DISTANCE;	}}// FIXME:  nts: how is this colour distance (2-norm) motivated?realno ColourBlob::colour_distance(RGB32pixel *col){    if (theColour_valid == false)	return 0;        int rdiff = col->red - theColour.red;    int gdiff = col->green - theColour.green;    int bdiff = col->blue - theColour.blue;        return sqrt((float)(rdiff * rdiff + gdiff * gdiff + bdiff * bdiff));}realno ColourBlob::norm_colour_distance(RGB32pixel *col){    if (theColour_valid == false)	return 0;        realno sum1 = 1 + theColour.red + theColour.green + theColour.blue;    realno r1 = theColour.red / sum1;    realno g1 = theColour.green / sum1;    realno b1 = theColour.blue / sum1;        realno sum2 = 1 + col->red + col->green + col->blue;    realno r2 = col->red / sum2;    realno g2 = col->green / sum2;    realno b2 = col->blue / sum2;        r1 -= r2; g1 -= g2; b1 -= b2;    return sqrt((float)(r1*r1 + g1*g1 + b1*b1));}void ColourBlob::update(){    if (newColour_valid == false)	return;        if (theColour_valid == false)    {	theColour_valid = true;	theColour = newColour;    }    else    {	// sorry, optimised a bit, less readable now -- nts	// this is how one of the 3 r,g,b parts looked like before:		// int gdiff = newColour->green - theColour->green;	// if (ABS(gdiff) > 4)	//	   gdiff = 4 * ZSGN(gdiff);	// else	//	   gdiff = ZSGN(gdiff);	// theColour -> green += gdiff;		register int rdiff = newColour.red - theColour.red;	if (rdiff > 0)	    if (rdiff > 4)		rdiff = 4;	    else		rdiff = 1;	else	    if (rdiff != 0)		if (rdiff < -4)		    rdiff = -4;		else		    rdiff = -1;		theColour.red += rdiff;		register int gdiff = newColour.green - theColour.green;	if (gdiff > 0)	    if (gdiff > 4)		gdiff = 4;	    else		gdiff = 1;	else	    if (gdiff != 0)		if (gdiff < -4)		    gdiff = -4;		else		    gdiff = -1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -