irrlicht 鬼火引擎导入opencv图片

注意,操作irrlicht device时一定要保证是在irrlicht的主线程操作(irrlicht的初始化线程)

第一种

// 创建空的texture
ITexture *imageTexture = device->getVideoDriver()->addTexture(
                    dimension2d((u32) cameraImageMat->cols,
                                     (u32) cameraImageMat->rows), "cameraImage");

// 将opencv Mat数据copy到texture
auto *tex_buf = (unsigned char *) imageTexture->lock();
            unsigned char *frame_buf = cameraImageMat->data;
            // Convert from RGB to RGBA
            for (int j = 0; j < cameraImageMat->rows * cameraImageMat->cols; j++) {
                *(tex_buf) = *(frame_buf + 2);
                *(tex_buf + 1) = *(frame_buf + 1);
                *(tex_buf + 2) = *(frame_buf);
                *(tex_buf + 3) = 255;
                frame_buf += 3;
                tex_buf += 4;
                // remove accumulator because when product with row*cols it huge time
                // and merge x loop & y loop in one that remove more asm count operation
            }
            imageTexture->unlock();

第二种

// 先创建image
IImage *cameraImage = device->getVideoDriver()->
                    createImageFromData(ECF_R8G8B8,
                                        dimension2d((u32) cameraImageMat->cols,
                                                         (u32) cameraImageMat->rows),
                                        cameraImageMat->data);
// 再创建texture
ITexture *imageTexture = device->getVideoDriver()->addTexture("cameraImage", cameraImage);

你可能感兴趣的:(irrlicht 鬼火引擎导入opencv图片)