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

📄 rgb32image.cc

📁 VC视频对象的跟踪提取原代码(vc视频监控源码)
💻 CC
字号:
/* * RGB32Image.cc * 24-bit (plus alpha) colour image class derived from generic * Image class in Image.h/Image.cc * * author : A M Baumberg */#include <cstdio>#include <cstdlib>#include <cstring>#include <fstream>#include <cstring>  // for memcpy()#include "RGB32Image.h"#include "Grey8Image.h"#include "Point2.h"#include "text_output.h"#ifdef HSV#include "HSV32Image.h"#endif#ifndef NO_DISPLAY#ifdef USE_GL#include <gl/gl.h>#else#include <X11/X.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/Xatom.h>#endif#endif   // #ifndef NO_DISPLAY#include "tracker_defines_types_and_helpers.h"namespace ReadingPeopleTracker{// definition and initialisation of static member variablesconst unsigned int RGB32Image::BOX_SIZE = 8;const unsigned int RGB32Image::HIST_SHIFT = 2;const unsigned int RGB32Image::HIST_RANGE = 256 >> HIST_SHIFT;const unsigned int RGB32Image::HIST_GROUP = 1 << HIST_SHIFT;const unsigned int RGB32Image::HIST_SHIFT_RED = HIST_SHIFT;const unsigned int RGB32Image::HIST_SHIFT_GREEN = HIST_SHIFT*2;const unsigned int RGB32Image::HIST_SHIFT_BLUE = HIST_SHIFT*3;const unsigned long RGB32Image::HIST_MASK_RED = (HIST_RANGE-1) << HIST_SHIFT;const unsigned long RGB32Image::HIST_MASK_GREEN = (HIST_RANGE-1) << 8+HIST_SHIFT;const unsigned long RGB32Image::HIST_MASK_BLUE = (HIST_RANGE-1) << 16+HIST_SHIFT;// Often, we would like to address the whole struct as an unsigned long// so here is a not-so-nice casting function:inline RGB32pixel RGB32Image::to_RGB32(unsigned long &colour){    return * ((RGB32pixel*) &colour);}inline RGB32pixel RGB32Image::to_RGB32(const unsigned char colour){    unsigned long colour_all_over = ((colour << 8 + colour) << 8 + colour) << 8 + colour;    return to_RGB32(colour_all_over);}// and the other way around:inline unsigned long RGB32Image::to_ulong(RGB32pixel &colour){    return * ((unsigned long*) &colour);}// write out an RGB32pixel as (r,g,b) tripletostream &operator<< (ostream &target, const RGB32pixel &ColourPixel){    target << "(";    u_int32_t AX = 0;    *((unsigned char*) &AX) = ColourPixel.red;    target << AX << ",";    AX = 0;    *((unsigned char*) &AX) = ColourPixel.green;    target << AX << ",";    AX = 0;    *((unsigned char*) &AX) = ColourPixel.blue;    target << AX << ")";    return target;}// copy image data, dimensions, time.Image *RGB32Image::copy(Image *res) const{    if (res == NULL)	res = new RGB32Image(width, height, frame_id, frame_time_in_ms);    else    {	// check destination image format and dimensions	if ((res->get_image_type() != RGB32) ||	    (res->get_width() != width) ||	    (res->get_height() != height))	{	    cerror << " RGB32Image::copy: cannot copy to resulting image of different type/dimensions "		   << endl;	    exit(1);	}		// use same frame id and time since it is the same image	res->set_frame_id(frame_id);	res->set_frame_time_in_ms(frame_time_in_ms);    }    res->set_timestamp(&timestamp);    // NB window handle (in GL, variable glwin) is not copied over!        void *src = data;    void *dest = res->get_data();    size_t n = (width * height) << 2;        memcpy(dest, src, n);        return res;}#ifdef USE_GLlong RGB32Image::display(long awindow){#ifdef NO_DISPLAY    return NULLWIN;#else    if (awindow != NULLWIN)	glwin = awindow;        if (glwin == NULLWIN)    {	unsigned int zoom = Image::display_zoom->value;	if (window_title[0] == 0)  // no title given?  default to this:	    sprintf(window_title," RGB32 image %d by %d ", width, height);	prefsize(width * zoom, height * zoom);	// nts: this gives an error in Ygl version 4.x//	foreground();		glwin = winopen(window_title);		winset(glwin);	reshapeviewport();	prefsize(width * zoom, height * zoom);	if (zoom != 1)	{	    rectzoom((float) zoom, (float) zoom);	    viewport(0, width * zoom - 1, 0, height * zoom - 1);	    ortho2(-0.5, width + 0.5, -0.5, height + 0.5);	}	winconstraints();	RGBmode();		gconfig();  // we have to do this after RGBmode and before cpack		cpack(0x00ffffff);	gflush();	gconfig();    }    winset(glwin);    lrectwrite(0,0,width-1,height-1,(Int32 *) data);    return glwin;#endif   // #ifdef NO_DISPLAY  #else}#else// X interfacelong RGB32Image::display(long dummy){#ifndef NO_DISPLAY    if (mydisplay == NULL)    {	if (window_title[0] == 0)  // no title given?  default to this:	    sprintf(window_title," RGB image %d by %d ", width, height);      	XSizeHints myhints;	myhints.width = width;	myhints.height = height;	myhints.flags = PSize;	mydisplay = XOpenDisplay("");	int screen = DefaultScreen(mydisplay);	rshift = bshift = gshift = 0;	Status res = XMatchVisualInfo(mydisplay, screen, 24, TrueColor,				      &xv_info);	matched_depth = 32;	if (res == 0) // no matching visual found	{	    Status res = XMatchVisualInfo(mydisplay, screen, 8, TrueColor,					  &xv_info);	    if (res == 0) // no matching visual found	    {		cerror << "RGB32Image::display: XMatchVisualInfo did not return usable visual" << endl;		exit(1);	    }	    rshift = bshift = gshift = 0;	    register int i;	    for (i = xv_info.red_mask; i < 128; i *= 2)		rshift++;	    for (i = xv_info.green_mask; i < 128; i *=2)		gshift++;	    for (i = xv_info.blue_mask; i < 128; i *=2 )		bshift++;	    matched_depth = 8;	}	else	{	    register long i;	    for (i = xv_info.red_mask; i > 256; i /= 256)		rshift++;	    for (i = xv_info.green_mask; i > 256; i /= 256)		gshift++;	    for (i = xv_info.blue_mask; i > 256; i /= 256)		bshift++;	    rshift = 3 - rshift;	    gshift = 3 - gshift;	    bshift = 3 - bshift;	}		RGB32pixel white = WhitePixel(mydisplay, screen);	RGB32pixel black = BlackPixel(mydisplay, screen);	Colormap cmap = XCreateColormap(mydisplay,					XRootWindow(mydisplay, screen),					xv_info.visual, AllocNone);		mypixmap = XCreatePixmap(mydisplay,				 XRootWindow(mydisplay, screen), width,				 height, xv_info.depth);		XSetWindowAttributes swa;	swa.background_pixel = BlackPixel(mydisplay, screen);	swa.border_pixel = WhitePixel(mydisplay, screen);	swa.colormap = cmap;	swa.background_pixmap = mypixmap;		mywindow = XCreateWindow (mydisplay, RootWindow(mydisplay, screen),				  100,100,width,height,1,				  xv_info.depth, InputOutput,				  xv_info.visual,				  CWBackPixmap | CWColormap | CWBorderPixel, &swa);		XSetStandardProperties(mydisplay,			       mywindow, &window_title,			       "image", None,			       NULL, 0, &myhints);		XMapRaised(mydisplay, mywindow);		myimage = XCreateImage( mydisplay, xv_info.visual,				xv_info.depth, ZPixmap, 0, None, width, height,				matched_depth, 0);#ifdef LSB_FIRST	myimage->byte_order = LSBFirst;	myimage->bitmap_bit_order = LSBFirst;#else	myimage->byte_order = MSBFirst;	myimage->bitmap_bit_order = MSBFirst;#endif		//mygc = XCreateGC (mydisplay, mywindow, 0, 0);	mygc = XCreateGC (mydisplay, mypixmap, 0, 0);	// check whether the data format is compatible with ours	if ((matched_depth == 32) && (Image::image_storage_mode == IA_TOP_TO_BOTTOM)	    && (rshift == 3) && (gshift == 2) && (bshift == 1))	    myimage->data = (char *) data;	else	    myimage->data = new char[width * height * matched_depth / 8];    }    if (xv_info.depth == 8)    {	cerror << "RGB32Image::display: Warning: No TrueColour visual found.  Using 8-bit visual." << endl;		unsigned int x;	unsigned int y;	RGB32pixel *idat;	unsigned char *odat = (unsigned char*) myimage->data;	unsigned char red_mask = xv_info.red_mask;	unsigned char green_mask = xv_info.green_mask;	unsigned char blue_mask = xv_info.blue_mask;		for (y = height; y > 0; y--)	{	    idat = (RGB32pixel *)get_pixel(0, y-1);	    for (x = 0; x < width; x++)    	    {		*odat++ = (((idat->red) >> rshift) & red_mask)		    + (((idat->green) >> gshift) & green_mask)		    + (((idat->blue) >> bshift) & blue_mask);		idat++;	    }	}    }    else  // that is, xv_info.depth != 8 so it must be 24    {	assert (xv_info.depth == 24);	if (myimage->data != (char *)(data))	{	    // xv_info.depth == 24	    unsigned int x,y;	    RGB32pixel *idat;	    unsigned char *odat = (unsigned char*) myimage->data;	    for (y = height; y > 0; y--)	    {		idat = (RGB32pixel *)get_pixel(0, (y-1));		for (x = 0; x < width; x++)    		{		    odat[rshift] = idat->red;		    odat[gshift] = idat->green;		    odat[bshift] = idat->blue;		    idat++;		    odat += 4;		}	    }	}    }        //  XPutImage(mydisplay, mywindow, mygc, myimage, 0,0,0,0,width,height);    XPutImage(mydisplay, mypixmap, mygc, myimage, 0,0,0,0,width, height);    XClearArea(mydisplay, mywindow, 0,0,0,0, True);    #endif   // #ifndef NO_DISPLAY    return 0;    }#endifvoid RGB32Image::save_pnm(char *filename)  // save PPM file{    // open output file for PPM output    ostream *ostream_ptr = NULL;        if (filename != NULL)	ostream_ptr = (ostream*)	    new ofstream(filename, ios::out);        if ((ostream_ptr == NULL) || (ostream_ptr->bad()))        {            cerror << "RGB32Image::save_pnm: could save image file "                   << "

⌨️ 快捷键说明

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