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
Creating Image with RGB data
There is probably a faster way, but this should work.
Then display it on something.
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();
}
-
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();
}
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.
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.