I am looking to include images captured from the users webcam into my application so I've been looking into using OpenCV to capture from the webcam and then render it in Irrlicht. I've created a basic app to test and I'm doing this in my main loop to capture and convert to ITexture* to render onto a cube.
if( cv::waitKey(50) >= 0 ) break;
capture >> camera_frame;
if( ! camera_frame.empty() )
{
unsigned char *tex_buf = (unsigned char*)frame_tex->lock();
unsigned char *frame_buf = camera_frame.data;
// Convert from RGB to RGBA
for(int y=0; y < camera_frame.rows; y++) {
for(int x=0; x < camera_frame.cols; x++) {
*(tex_buf++) = *(frame_buf++);
*(tex_buf++) = *(frame_buf++);
*(tex_buf++) = *(frame_buf++);
*(tex_buf++) = 255;
}
}
frame_tex->unlock();
//cube->setMaterialTexture(0, driver->getTexture("../../media/t351sml.jpg"));
cube->setMaterialTexture(0, frame_tex);
cube->setMaterialFlag(video::EMF_LIGHTING, false);
}
...
It works.... BUT... the framerate drops to about 4fps.
Yes, it probably could have been done slightly more efficiently, but it's a massive drop in framerate for something so simple.
Is there another way to do this that won't kill the framerate?