Creating Image with RGB data

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
YoJi

Creating Image with RGB data

Post by YoJi »

Hello
I'm making a eye toy project and i have grab a frame of my webcam , i have construct a class image who contain all the RGB data and i want to display it ...

How can i do to display my webcam's grab in a Irrlicht device?

Thx to your answer
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

There is probably a faster way, but this should work.

Code: Select all

// create the texture
ITexture* pMyTexture = Driver->addTexture(core::dimension2d<s32>(512, 512), "myTexture", ECF_A8R8G8B8);

// periodically read new data from your camera
void* pMyTexturePixels = pMyTexture->lock();
if (pMyTextureData)
{
  // write pixel data from your camera
  pMyTexture->unlock();
}
Then display it on something.
YoJi

Post by YoJi »

Thank you wery much, with your help i found a function who is exactly what i researched, but I have a new problem my Image is not display...


Code: Select all

void Webcam::AfficheImage(Image * ImageAAfficher, int x, int y, IVideoDriver* driver)
{
	int i, j;
    LPBYTE DonneeWebcam = new BYTE[4*VMAX*HMAX];
    
	// Parcoure le tbl
	for(i=0; i<HMAX; i++)
		for(j=0; j<VMAX; j++)
		{
			DonneeWebcam[4*VMAX*(HMAX-1-i)+4*j+2] = ImageAAfficher->Couleur(i,j,'r');
			DonneeWebcam[4*VMAX*(HMAX-1-i)+4*j+1] = ImageAAfficher->Couleur(i,j,'g');
			DonneeWebcam[4*VMAX*(HMAX-1-i)+4*j]   = ImageAAfficher->Couleur(i,j,'b');
		}
    IImage * ImageWebcam = driver->createImageFromData(ECF_A8R8G8B8, dimension2d<s32>(VMAX,HMAX), DonneeWebcam,true); 	
	ITexture * TextureWebcam = driver->addTexture("My Webcam",ImageWebcam);
	driver->draw2DImage(TextureWebcam, position2d<s32>(x,y)); 
    

    free (TextureWebcam);
    ImageWebcam->drop();	
}
YoJi
Posts: 12
Joined: Sat Mar 11, 2006 7:32 am

Post by YoJi »

Sorry for my question that work ^^ , i display an other image in my image webcam that why i couldn't display it
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

One glaring bug in the code above... TextureWebcam is being free'd, but it is owned by the driver. You should never free, delete or drop a texture that is not owned by you.

Also, it looks like you may have a leak. Calling driver->addTexture repeatedly with the same name appears to create multiple texture entries in the texture cache. If your program runs for a long period of time, it may run out of memory because the cache will keep growing.

Also, if you are going to be calling AfficheImage often to update the display, you might want to consider allocating the data block once and writing the data directly to it.
Post Reply