美文网首页
irrlicht 鬼火引擎导入opencv图片

irrlicht 鬼火引擎导入opencv图片

作者: VellBibi | 来源:发表于2019-04-04 19:43 被阅读0次

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

    第一种

    // 创建空的texture
    ITexture *imageTexture = device->getVideoDriver()->addTexture(
                        dimension2d<u32>((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>((u32) cameraImageMat->cols,
                                                             (u32) cameraImageMat->rows),
                                            cameraImageMat->data);
    // 再创建texture
    ITexture *imageTexture = device->getVideoDriver()->addTexture("cameraImage", cameraImage);
    

    相关文章

      网友评论

          本文标题:irrlicht 鬼火引擎导入opencv图片

          本文链接:https://www.haomeiwen.com/subject/gcoqiqtx.html