Page 1 of 1

Update a texture live (webcam)...

Posted: Tue Apr 17, 2007 08:32
by jojomillenium
Hello!
I'm trying to display a webcam into a TaharezLook/StaticImage
What i'm doing is grabing the image as a byte array... i can grab it at init and display it... no problem!
But now i would like to grab it continuously and display it... how can i do that?
I know that the setTexture is not a good idea (and is protected) and i'm not sure that destroying my imageset and creating it again with the new texture from memory is going to be fast enough! (cuz it should be quite fast to look like it is live.. no lag)

any idea on how to update/change the texture of an imageset in a fast and practical way? Or maybe a total other way of doing it!?

Thank you very much for your help!

Posted: Tue Apr 17, 2007 10:00
by Rackle
This Ogre Wiki article uses a dynamically created image, by rendering rotating 3D objects to an image. If you are using Ogre as your renderer then you have a lot of the code already done for you. Otherwise you'll have to adapt the code to your specific renderer. That article should provide a good starting point for your application.

Posted: Tue Apr 17, 2007 10:24
by jojomillenium
I'm not using Ogre, but the CEGUI library 0.5.0 !
What is the best way of doing what i want to do?

Posted: Tue Apr 17, 2007 11:08
by Rackle
You are not using only Cegui; you also need a renderer. It could be DirectX, OpenGL, Ogre, Irrlicht, etc.

The link to the Ogre wiki rotates a 3D model in front of a camera and the contents of that camera are placed within a texture, which is used to dynamically update an image displayed within Cegui. It uses the Ogre renderer, with some code specific for that renderer. However you should be able to go through that code and adapt it to the renderer you are using (I'm guessing DirectX or OpenGL).

Posted: Tue Apr 17, 2007 12:16
by jojomillenium
right of course, i'm using OpenGL!
I'm gonna go trough that and get back here if something's wrong!

Thanks!

Posted: Tue Apr 17, 2007 13:02
by jojomillenium
I went trought the code, and i didnt find anywhere a way to update a texture of an imageset!
From a 3D object, the object is define, but what i want is that (for exemple if it is really slow) every second, my webcam gets a new image as a byte array. I create a new texture from this array with LoadFromMemory()
(until here it works well)
then i want to apply this texture to the imageset i'm displaying!
I have a window (staticimage) displaying the imageset called "ImgSet" and the image "ImgCam". So ImgSet as to change it's texture right so the image changes!
It's the only way i found to do it!
If something else to do, please let me know! I'm very new in CEGUI!

Posted: Tue Apr 17, 2007 16:23
by Rackle
This is part of the code from DialogBuild::DialogBuild()

Code: Select all

// Create an Ogre texture via DirectX or OpenGL
texName = "RttTex_" + StringConverter::toString(buttonIndex);
rttTex[buttonIndex] = global->root->getRenderSystem()->createRenderTexture(texName, RTT_WINDOW_SIZE, RTT_WINDOW_SIZE, TEX_TYPE_2D, PF_R8G8B8);
Ogre::TexturePtr ogreTex = Ogre::TextureManager::getSingletonPtr()->getByName(texName);

// Create a Cegui Texture via the Ogre Cegui Renderer
OgreCEGUITexture* ceguiTex = (OgreCEGUITexture*)global->guiRenderer->createTexture();
ceguiTex->setOgreTexture(ogreTex);

// Create a Cegui imageset from an OgreCeguiRenderer texture
imageSetName = "ButtonTextureImageset_" + StringConverter::toString(buttonIndex);
Imageset* textureImageSet = CEGUI::ImagesetManager::getSingleton().createImageset(imageSetName, ceguiTex);
textureImageSet->defineImage("RttTex", Point(0.0f, 0.0f), Size(ceguiTex->getWidth(), ceguiTex->getHeight()), Point(0.0f,0.0f));
imageSetName = "set:ButtonTextureImageset_" + StringConverter::toString(buttonIndex) + " image:RttTex";

// Use that Cegui image for the various states of the button
rootWindow->getChild(buttonID[buttonIndex])->setProperty("NormalImage", imageSetName);
rootWindow->getChild(buttonID[buttonIndex])->setProperty("HoverImage", imageSetName);
rootWindow->getChild(buttonID[buttonIndex])->setProperty("PushedImage", imageSetName);


After this point I believe you would simply update the texture you created via DirectX or OpenGL.

Posted: Wed Apr 18, 2007 14:30
by Pompei2
You could also just NOT use CEGUI to do that: create a texture in opengl and render it above your CEGUI scene. calculating its position shouldn't be that hard.

Posted: Thu Apr 19, 2007 11:59
by Rackle
From the Ogre message board: Webcam Plugin. The source code may inspire you, or you may decide that going the Ogre way is the simplest solution.

Posted: Fri Apr 20, 2007 12:07
by jojomillenium
I did it! now i can live change the texture.
The problem now is that i put i timer in my CEGUI application and a thread, the thread catches the images from the webcams (two webcams actually)
and in my CEGUI application timer, i'm changing the texture of my imageset using the byte array got in the thread.

Probleme is... if i put a 0.5 second delay for my timer, the CEGUI application is good (120fps) but of course, my webcam images are slow... so if i want a pseudo live webcam display, i'm putting the delay at 0.05 secondes ... there the webcam are quite fast.. great but my CEGUI app is now runing at 11 fps which is REAL bad!

Have any idea on where the problem comes from and if i can resolve it?

Thank you very much

Posted: Fri Apr 20, 2007 12:17
by Rackle
Are you running in debug mode?

What about removing the byte array copy, to check if it's that copy routine?

Are there large variables that you are creating each frame?

Otherwise you'd need to run a profiler, to figure out which functions are taking the most time.