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

📄 edgedetector.cc

📁 不错的shijuegezong的程序
💻 CC
📖 第 1 页 / 共 3 页
字号:
/*************************************************************** * C++ source * * File : 	EdgeDetector.cc * * Module :	EdgeDetector * * Author : 	A M Baumberg (CoMIR) * * Creation Date : Fri May 17 14:17:32 1996 * * Comments : 	 * ***************************************************************/// include files#include "OcclusionHandler.h"#include "EdgeDetector.h"#include "Image.h"#include "PipeSource.h"#include "Grey8Image.h"#include "RGB32Image.h"#include "ActiveShapeTracker.h"#include "text_output.h"#include "ActiveModel.h"#ifndef NO_DISPLAY#ifdef USE_GL#include <gl.h>#else#include <vogl.h>#endif#endif   // #ifndef NO_DISPLAY#include <cassert>namespace ReadingPeopleTracker{// definition and initialisation of static member variablesrealno EdgeDetector::max_scale_height_ratio = 0.05;realno EdgeDetector::max_scale_width_ratio = 1.0;const realno EdgeDetector::MAX_NORM_RGB_DISTANCE = sqrt(2.0);const realno EdgeDetector::MAX_RGB_DISTANCE = sqrt(3.0 * 255.0 * 255.0);const realno EdgeDetector::MAX_GREY_DISTANCE = 255.0;#ifndef NO_DISPLAYint ColourBlob::cblob_glwin = NULLWIN;#endif// Names of edge detection methodschar *EdgeDetector::edge_detection_method_names[] ={    "COLOUR_FOREGROUND_EDGE",    "COLOUR_EDGE",    "MOVING_EDGE",    "SIMPLE_EDGE",    "SOBEL_EDGE",    "FOREGROUND_EDGE",    "NORMALISED_COLOUR_FOREGROUND_EDGE",    NULL};// pixelwise edge / contrast detection functions ...bool EdgeDetector::grey_simple(int x, int y, int step, Point2 &n,			       realno &edge, ActiveModel *active_model){    int dx = real_to_int(n.x * step);    int dy = real_to_int(n.y * step);        int xr = x + dx;    int yr = y + dy;    int xl = x - dx;    int yl = y - dy;    Image *img = active_model->get_video_image();        if (!((img->check_coords(xr,yr)) && (img->check_coords(xl,yl))))	return false;        int c1 = *img->get_pixel(xr,yr);    int c2 = *img->get_pixel(xl,yl);        edge = (realno) abs(c1 - c2);    return true;}bool EdgeDetector::grey_sobel(int x, int y, int step, Point2 &n, realno &edge, ActiveModel *active_model){    int xr = x + step;    int xl = x - step;    int yr = y + step;    int yl = y - step;    Image *img = active_model->get_video_image();        if (!((img->check_coords(xr,yr)) && (img->check_coords(xl,yl))))	return false;        int c1 = *img->get_pixel(xl,yl);    int c2 = *img->get_pixel(x,yl);    int c3 = *img->get_pixel(xr,yl);    int c4 = *img->get_pixel(xl,y);    //  int c5 = *img->get_pixel(x,y);    int c6 = *img->get_pixel(xr,y);    int c7 = *img->get_pixel(xl,yr);    int c8 = *img->get_pixel(x,yr);    int c9 = *img->get_pixel(xr,yr);        int v_response = c1 - c7 + (2 * (c2 - c8)) + c3 - c9;    int h_response = c1 - c3 + (2 * (c4 - c6)) + c7 - c9;        //  edge = fabs((h_response * n.x) + (v_response * n.y));    edge = sqrt((float)(h_response * h_response) + (v_response * v_response));        return true;}bool EdgeDetector::rgb_simple(int x, int y, int step,			      Point2 &n, realno &edge, ActiveModel *active_model){    int dx = real_to_int(n.x * step);    int dy = real_to_int(n.y * step);        if ((dx == 0) && (dy == 0))    {	cdebug << "rgb_simple: dx == dy == 0.  This should not happen. " << endl	       << "  n = " << n << ", step = " << step << endl;    }        int xr = x + dx;    int yr = y + dy;    int xl = x - dx;    int yl = y - dy;    Image *img = active_model->get_video_image();        if (!((img->check_coords(xr,yr)) && (img->check_coords(xl,yl))))	return false;        RGB32pixel *p1 = (RGB32pixel*) img->get_pixel(xr,yr);    RGB32pixel *p2 = (RGB32pixel*) img->get_pixel(xl,yl);        int rdiff = p1->red - p2->red;    int gdiff = p1->green - p2->green;    int bdiff = p1->blue - p2->blue;        edge = sqrt((float)(rdiff * rdiff + gdiff * gdiff + bdiff * bdiff));        return true;}bool EdgeDetector::rgb_sobel(int x, int y, int step, Point2 &n, realno &edge, ActiveModel *active_model){    int xr = x + step;    int xl = x - step;    int yr = y + step;    int yl = y - step;    Image *img = active_model->get_video_image();    if (!((img->check_coords(xr,yr)) && (img->check_coords(xl,yl))))	return false;        RGB32pixel *c1 = (RGB32pixel*) img->get_pixel(xl,yl);    RGB32pixel *c2 = (RGB32pixel*) img->get_pixel(x,yl);    RGB32pixel *c3 = (RGB32pixel*) img->get_pixel(xr,yl);    RGB32pixel *c4 = (RGB32pixel*) img->get_pixel(xl,y);    //  RGB32pixel *c5 = (RGB32pixel*) img->get_pixel(x,y);    RGB32pixel *c6 = (RGB32pixel*) img->get_pixel(xr,y);    RGB32pixel *c7 = (RGB32pixel*) img->get_pixel(xl,yr);    RGB32pixel *c8 = (RGB32pixel*) img->get_pixel(x,yr);    RGB32pixel *c9 = (RGB32pixel*) img->get_pixel(xr,yr);        int r_v_response =	c1->red - c7->red + (2 * (c2->red - c8->red)) + c3->red - c9->red;    int g_v_response =	c1->green - c7->green + (2 * (c2->green - c8->green)) +	c3->green - c9->green;    int b_v_response = c1->blue - c7->blue + (2 * (c2->blue - c8->blue))	+ c3->blue - c9->blue;        int r_h_response =	c1->red - c3->red + (2 * (c4->red - c6->red)) + c7->red - c9->red;    int g_h_response = c1->green - c3->green +	(2 * (c4->green - c6->green)) +	c7->green - c9->green;    int b_h_response = c1->blue - c3->blue +	(2 * (c4->blue - c6->blue)) + c7->blue - c9->blue;        realno r_edge = (r_h_response * n.x) + (r_v_response * n.y);    realno g_edge = (g_h_response * n.x) + (g_v_response * n.y);    realno b_edge = (b_h_response * n.x) + (b_v_response * n.y);        edge = (sqrt((float)(r_edge * r_edge + g_edge * g_edge + b_edge * b_edge)));    return true;        }bool EdgeDetector::grey_moving_edge(int x, int y, int step, Point2 &n, realno &edge, ActiveModel *active_model){        int dx = real_to_int(n.x * step);    int dy = real_to_int(n.y * step);        int xr = x + dx;    int yr = y + dy;    int xl = x - dx;    int yl = y - dy;        Image *prev = active_model->get_previous_video_image();    Image *curr = active_model->get_video_image();            if (!((curr->check_coords(xr,yr)) && (curr->check_coords(xl,yl))))	return false;        int c1 = *curr->get_pixel(xr,yr);    int c2 = *curr->get_pixel(xl,yl);    int c3 = *curr->get_pixel(x,y);    int c4 = *prev->get_pixel(x,y);        edge = (realno) (abs(c1 - c2) + abs(c3 - c4));    return true;}bool EdgeDetector::rgb_moving_edge(int x, int y, int step, Point2 &n, realno &edge, ActiveModel *active_model){        int dx = real_to_int(n.x * step);    int dy = real_to_int(n.y * step);        int xr = x + dx;    int yr = y + dy;    int xl = x - dx;    int yl = y - dy;        Image *prev = active_model->get_previous_video_image();    Image *curr = active_model->get_video_image();        if (!((curr->check_coords(xr,yr)) && (curr->check_coords(xl,yl))))	return false;        RGB32pixel *p1 = (RGB32pixel*) curr->get_pixel(xr,yr);    RGB32pixel *p2 = (RGB32pixel*) curr->get_pixel(xl,yl);    RGB32pixel *p3 = (RGB32pixel*) curr->get_pixel(x,y);    RGB32pixel *p4 = (RGB32pixel*) prev->get_pixel(x,y);        int rdiff = p1->red - p2->red;    int gdiff = p1->green - p2->green;    int bdiff = p1->blue - p2->blue;        realno spatial_edge =	sqrt((float)(rdiff * rdiff + gdiff * gdiff + bdiff * bdiff));        rdiff = p3->red - p4->red;    gdiff = p3->green - p4->green;    bdiff = p3->blue - p4->blue;    realno temporal_edge =	sqrt((float)(rdiff * rdiff + gdiff * gdiff + bdiff * bdiff));        edge = spatial_edge + temporal_edge;        return true;}bool EdgeDetector::grey_foreground_edge(int x, int y, int step, Point2 &n,					realno &edge, ActiveModel *active_model){    ForegroundEdgeDetector *parent = (ForegroundEdgeDetector*) active_model->get_edge_detector();    int dx = real_to_int(n.x * step);    int dy = real_to_int(n.y * step);        int xr = x + dx;    int yr = y + dy;    int xl = x - dx;    int yl = y - dy;    Image *back = active_model->get_background_image();    Image *front = active_model->get_video_image();        if (!((front->check_coords(xr,yr)) && (front->check_coords(xl,yl))))	return false;        int c1 = *front->get_pixel(xr,yr);    int c2 = *back->get_pixel(xr,yr);    int c3 = *front->get_pixel(xl,yl);    int c4 = *back->get_pixel(xl,yl);        int d1 = abs(c1 - c2);    int d2 = abs(c3 - c4);        if ((d2 <= parent->thresh_foreground) ||	(d1 >= parent->thresh_background))	edge = 0;    else	edge = (realno) (d2 - d1);        return true;}bool EdgeDetector::rgb_foreground_edge(int x, int y, int step, Point2 &n,				       realno &edge, ActiveModel *active_model){    ForegroundEdgeDetector *parent = (ForegroundEdgeDetector*) active_model->get_edge_detector();    int dx = real_to_int(n.x * step);    int dy = real_to_int(n.y * step);        int xr = x + dx;    int yr = y + dy;    int xl = x - dx;    int yl = y - dy;    Image *back = active_model->get_background_image();    Image *front = active_model->get_video_image();        if (!((front->check_coords(xr,yr)) && (front->check_coords(xl,yl))))	return false;        RGB32pixel *p1 = (RGB32pixel*) front->get_pixel(xr,yr);    RGB32pixel *p2 = (RGB32pixel*) back->get_pixel(xr,yr);    RGB32pixel *p3 = (RGB32pixel*) front->get_pixel(xl,yl);    RGB32pixel *p4 = (RGB32pixel*) back->get_pixel(xl,yl);        int rdiff = p1->red - p2->red;    int gdiff = p1->green - p2->green;    int bdiff = p1->blue - p2->blue;        realno d1 = sqrt((float)(rdiff * rdiff + gdiff * gdiff + bdiff * bdiff));        rdiff = p3->red - p4->red;    gdiff = p3->green - p4->green;    bdiff = p3->blue - p4->blue;    realno d2 = sqrt((float)(rdiff * rdiff + gdiff * gdiff + bdiff * bdiff));        if ((d2 <= parent->thresh_foreground) ||	(d1 >= parent->thresh_background))	edge = 0;    else	edge = d2 - d1;        return true;}edge_status_tGenericEdgeDetector::find_edge(realno u, Point2 &pos,			       Point2 &search_line,			       Point2 &normal, realno window_size,			       OcclusionHandler *occlusion_map,			       Profile *currx,			       Point2 &p_obs, realno &var,			       ActiveModel *active_model){    curr_u_val = u;        // ugly switch cannot easily be avoided !    switch (search_mthd)    {    case NEAREST_EDGE_SEARCH:	return nearest_edge(pos, search_line, normal, window_size,			    occlusion_map, currx, p_obs, var, tracker->get_active_model());    case STATISTICAL_EDGE_SEARCH:	return stat_edge(pos, search_line, normal, window_size,			 occlusion_map, currx, p_obs, var, tracker->get_active_model());    default:    case MAXIMUM_EDGE_SEARCH:	return max_edge(pos, search_line, normal, window_size,			occlusion_map, currx, p_obs, var, tracker->get_active_model());	    }    return EDGE_BAD;}// mechanisms for combining pixel edge informationedge_status_tGenericEdgeDetector::stat_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 sum_e = 0;    realno sum_d = 0;    realno sq_sum = 0;    realno max_e = -1e30, best = 0;

⌨️ 快捷键说明

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