texture update doesn't work

Deepfreeze

01-10-2013 07:58:04

Hello,

What I would like to do is to grab the image stream from the kinect camera and show this
in a MyGUI::ImageBox using MyGUI::ITexture. The code that I use is a copy of the colourPanel.cpp
and it works to set the initial colour to (128,128,128) -> gray.
After the initialization the texture and imageBox should be updated to the frames that are captured
by the kinect. But this updating doesn't work. In order to find the issue with the updating, at the moment
I have a short *.avi that I grab and try to display using OpenCV. Once this is working changing to the
kinect interface is easy.


void BasicTutorial05::createScene(void)
{
// First create the GUI
mPlatform = new MyGUI::OgrePlatform;
mPlatform->initialise(mWindow, mSceneMgr); //mWindow is Ogre::RenderWindow*, mSceneMgr is Ogre::SceneManager*
mGUI = new MyGUI::Gui();
mGUI->initialise();

// load the new layout
mLayout = MyGUI::LayoutManager::getInstance().loadLayout("bodyScanPage3.layout");


kinectLive liveObject;
liveObject.init(mGUI);
boost::thread workerThread(liveObject);

.... and rest of this function


kinectLive class

class kinectLive
{
private:
MyGUI::ImageBox* mColourRect;
MyGUI::Gui* mGUI;
MyGUI::ITexture* mTexture;
MyGUI::uint height;
MyGUI::uint width;
pcl::Grabber* _grabber;
MyGUI::uint8* pDest;

public:
kinectLive() {}

~kinectLive()
{
}

// Find the "liveKinect" widget and connect it to mColourRect
void init(MyGUI::Gui* &parentGUI)
{
mGUI = parentGUI;
mColourRect = mGUI->findWidget<MyGUI::ImageBox>("page3KinectLive");
// Set texture stuff
height = 480;
width = 640;
mTexture = MyGUI::RenderManager::getInstance().createTexture("kinectImage");
mTexture->createManual(width, height,
MyGUI::TextureUsage::Static | MyGUI::TextureUsage::Write,
MyGUI::PixelFormat::R8G8B8A8);

// Connect texture to mColourRect
mColourRect->setImageTexture("kinectImage");

// Fill texture pixel buffer
pDest = static_cast<MyGUI::uint8*>(mTexture->lock(MyGUI::TextureUsage::Write));
for (size_t j = 0; j < height; j++)
{
for (size_t i = 0; i < width; i++)
{
float x = (float)i / width;
float y = (float)j / height;
*pDest++ = MyGUI::uint8(128); // B
*pDest++ = MyGUI::uint8(128); // B
*pDest++ = MyGUI::uint8(128); // B
*pDest++ = 255; // A
}
}
// Unlock the pixel buffer
mTexture->unlock();
}

void operator()()
{
cv::VideoCapture video;
video.open("./movies/test_1.avi");
// MyGUI::utility::toString<double>(length)
mGUI->findWidget<MyGUI::TextBox>("page3AfstandOutput")->setCaption(MyGUI::utility::toString<bool>(video.isOpened()));
cv::Mat frameBGR;

int frames = int(video.get(CV_CAP_PROP_FRAME_COUNT)/4);


for(int frameNr=0; frameNr<frames ;frameNr++)
{
video >> frameBGR;
Sleep(200);
mGUI->findWidget<MyGUI::TextBox>("page3AfstandOutput")->setCaption(MyGUI::utility::toString<int>(frameNr));

// Connect texture to mColourRect
mColourRect->setImageTexture("kinectImage");

/// Now lock the pixel buffer and change pixel colors from grabbed image
pDest = static_cast<MyGUI::uint8*>(mTexture->lock(MyGUI::TextureUsage::Write));

for (size_t j = 0; j < height; j++)
{
for (size_t i = 0; i < width; i++)
{
float x = (float)i / width;
float y = (float)j / height;
//*pDest++ = MyGUI::uint8(0); // B
//*pDest++ = MyGUI::uint8(255); // B
//*pDest++ = MyGUI::uint8(0); // B
*pDest++ = frameBGR.at<cv::Vec3b>(j,i)[0]; // Blue
*pDest++ = frameBGR.at<cv::Vec3b>(j,i)[1]; // Green
*pDest++ = frameBGR.at<cv::Vec3b>(j,i)[2]; // Red
*pDest++ = 255; // A
}
}

// Unlock the pixel buffer
mTexture->unlock();
}
}
};


Does anyone have some suggestions to get the updating to work?

scrawl

06-10-2013 08:03:51

Not sure why that doesn't work, but you could try updating it on the Ogre level instead, see post http://www.ogre3d.org/forums/viewtopic. ... 74#p496270