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

📄 hsv32image.cc

📁 VC视频对象的跟踪提取原代码(vc视频监控源码)
💻 CC
📖 第 1 页 / 共 2 页
字号:
	    }	    	    case CF_METHOD_S:	    {		grey = image_col->S;		break;	    }	    case CF_METHOD_V:	    {		grey = image_col->V;		break;	    }	    	    //  	    case CF_METHOD_Y_709:     // Y  from YCbCr after CIE recommendation 709//  	    {//  		//  source: C Poynton's Colour FAQ page 6//  		grey = (218 * (unsigned int) image_col->H//  			 + 732 * (unsigned int) image_col->S//  			 + 74 * (unsigned int) image_col->V)//  			     >> 10;	//  		break;//  	    }	    	    default:	    {		cerror << " HSV32Image::ColourFilter: unknown filtering method requested " << endl;		exit(1);	    }	    }	    	    	    if (grey > 255)		*result_col++ = 255;	    else		*result_col++ = (unsigned char) grey;	    	    image_col++;	}    }        return res;}   ////  "ColourDistance" to greyImage *HSV32Image::ColourDistance (Image *res, ColourDistanceMethod method){    if (res == NULL)	res = new Grey8Image(width, height, frame_id, frame_time_in_ms);        // row and column counters...    unsigned int row;    unsigned int col;        // pointers to data: columns of image and result    HSV32pixel *image_col;    unsigned char *result_col;        unsigned int grey;        // FIXME: should put switch out of loop or use several inline    //        functions (pointed to) or something.  No time.    for (row = 0; row < height; row++)    {	image_col  = (HSV32pixel*) get_pixel(0,row);	result_col = res -> get_pixel(0,row);		for (col = 0; col < width; col++)	{	    switch (method)	    {	    case CD_METHOD_V_WEIGHTED_HS:   // distance in H/S circle, weighted by V	    {		grey = ((unsigned int) image_col->H			+ (unsigned int) image_col->S			+ (unsigned int) image_col->V			+ 1)		    / 3;		break;	    }	    	    default:	    {		cerror << " HSV32Image::ColourDistance: unknown distance measure requested " << endl;		exit(1);	    }	    }	    	    	    if (grey > 255)		*result_col++ = 255;	    else		*result_col++ = (unsigned char) grey;	    	    image_col++;	}    }        return res;}   ////  colour differencing (no filtering or thresholding), using simple abs/diffImage *HSV32Image::difference(Image *image2, Image *res){    if ((this == NULL) || (image2 == NULL))	return NULL;        if (image2->get_image_type() != HSV32)    {	if (image2->get_image_type() == GREY8)	    return HSV32Image::difference((Grey8Image*) image2, res);		cerror << "HSV32Image::difference(): cannot difference different image types. "	       << endl;	exit(1);    }        if (res == NULL)	res = new HSV32Image(width, height, frame_id, frame_time_in_ms);        // row and column counters...    unsigned int row;    unsigned int col;        // pointers to data: columns in both images, and the result    HSV32pixel *image1_col;    HSV32pixel *image2_col;    HSV32pixel *result_col;        HSV32pixel temp_result;    temp_result.alpha = 0x00;        for (row = 0; row < height; row++)    {	image1_col = (HSV32pixel*)           get_pixel(0,row);	image2_col = (HSV32pixel*) image2 -> get_pixel(0,row);	result_col = (HSV32pixel*) res    -> get_pixel(0,row);		for (col = 0; col < width; col++)	{	    temp_result.H  = (image1_col->H > image2_col->H) ?		(image1_col->H - image2_col->H) :		(image2_col->H - image1_col->H);	    if (temp_result.H > 127)  // wrap around difference		temp_result.H = 255 - temp_result.H;	    temp_result.H <<= 2;	    	    temp_result.S  = (image1_col->S > image2_col->S) ?		(image1_col->S - image2_col->S) :		(image2_col->S - image1_col->S);	    	    temp_result.V = (image1_col->V > image2_col->V) ?		(image1_col->V - image2_col->V) :		(image2_col->V - image1_col->V);	    	    *result_col++ = temp_result;	    image1_col++;	    image2_col++;	}    }        return res;}////  colour differencing --- version for HSV32-GREY8: at the moment, only uses VImage *HSV32Image::difference(Grey8Image *image2, Image *res){    if ((this == NULL) || (image2 == NULL))	return NULL;        if (image2->get_image_type() != GREY8)    {	cerror << "HSV32Image::difference(): cannot difference these image types. "	       << endl;	exit(1);    }        if (res == NULL)	res = new HSV32Image(width, height, frame_id, frame_time_in_ms);        // row and column counters...    int row;    int col;        // pointers to data: columns in both images, and the result    HSV32pixel *image1_col;    unsigned char *image2_col;    HSV32pixel *result_col;        HSV32pixel temp_result;    temp_result.alpha = 0x00;        for (row = 0; row < height; row++)    {	image1_col = (HSV32pixel*)           get_pixel(0,row);	image2_col =               image2 -> get_pixel(0,row);	result_col = (HSV32pixel*) res    -> get_pixel(0,row);		for (col = 0; col < width; col++)	{	    temp_result.H = image1_col->H;	    	    temp_result.S = image1_col->S;	    	    temp_result.V = (image1_col->V > *image2_col) ?		(image1_col->V - *image2_col) :		(*image2_col - image1_col->V);	    	    *result_col++ = temp_result;	    image1_col++;	    image2_col++;	    	}    }        return res;}Image *HSV32Image::resample(int xstep , int ystep , Image *resampled){    int new_width = (width / xstep);    if (resampled == NULL)	resampled = (Image *) new HSV32Image(new_width, height / ystep,					     frame_id, frame_time_in_ms);    HSV32pixel *idat;    HSV32pixel *odat;    int outy = 0;    for (int y = 0; y < height; y += ystep)    {	idat = (HSV32pixel*) get_pixel(0,y);	odat = (HSV32pixel*) resampled->get_pixel(0, outy);	for (int x = 0; x < new_width; x ++)	{	    *odat = *idat;	    odat++;	    idat = idat + xstep;	}	outy++;    }    return resampled;}int HSV32Image::compar_char(const void *c1, const void *c2){    return (int) (*((unsigned char *) c1) - *((unsigned char *) c2));}inline void HSV32Image::clear(HSV32pixel fill_colour){    HSV32pixel *current;    HSV32pixel *end = (HSV32pixel *) end_data;    for (current = (HSV32pixel *) data; current < end; *current++ = fill_colour) ;    }void HSV32Image::clear_border(){    HSV32pixel HSV_CLEAR_MARK = {0,0,0,0};        register int w1 = width-1;    for (register int y = 0; y < height; y++)    {	*((HSV32pixel*) get_pixel( 0,y)) = HSV_CLEAR_MARK;	*((HSV32pixel*) get_pixel(w1,y)) = HSV_CLEAR_MARK;    }    register int h1 = height-1;    for (register int x = 0; x < width; x++)    {	*((HSV32pixel*) get_pixel(x, 0)) = HSV_CLEAR_MARK;	*((HSV32pixel*) get_pixel(x,h1)) = HSV_CLEAR_MARK;    }}Image *HSV32Image::mask(Image *mask, Image *res){    if (mask == NULL)	return NULL;        if (res == NULL)	res = new HSV32Image(width, height, frame_id, frame_time_in_ms);        if ((mask->get_width() != width) || (mask->get_height() != height))    {	register unsigned long *mask_pix;	register unsigned int x;	unsigned int y;	for (y = 0; y < height; y++)	    for (x = 0; x < width; x++)	    {		// FIXME: Should use HSV32pixel here, as well.		if (mask->check_coords(x,y))		{		    mask_pix = (unsigned long*) mask->get_pixel(x,y);		    if (*mask_pix != 0x00000000)			*((unsigned long*) res->get_pixel(x,y))			    = *((unsigned long*) get_pixel(x,y));		}	    }    }    else     {	// FIXME: Should use HSV32pixel here, as well. 	unsigned long *dat1 = (unsigned long*) data;	unsigned long *dat2 = (unsigned long*) mask->get_data();	unsigned long *edat = (unsigned long*) get_end_data();	register unsigned long *rdat = (unsigned long*) res->get_data();	while (dat1 < edat)	    *rdat++ = *dat1++ & *dat2++;    }    return res;}void HSV32Image::draw_rectangle(int xmin, int xmax, int ymin, int ymax, int val){    if ((xmin > xmax) || (ymin > ymax))    {	cerror << " HSV32Image::draw_rectangle("	       << xmin << "," << xmax << "," << ymin << "," << ymax	       << ", " << val << ") : cannot draw! " << endl;	return;    }        if (xmin < 0)	xmin = 0;    if (ymin < 0)	ymin = 0;    if (xmax >= width)	xmax = (width-1);    if (ymax >= height)	ymax = (height-1);        int nbytes = (xmax - xmin + 1) * bytes_per_pixel;     for (int y = ymin; y <= ymax; y++)	memset(get_pixel(xmin,y),val, nbytes);  // just paint grey values all over}} // namespace ReadingPeopleTracker

⌨️ 快捷键说明

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