从帧缓冲区GLSL读取到OpenCV [英] Reading from framebuffer GLSL to OpenCV

查看:112
本文介绍了从帧缓冲区GLSL读取到OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在尝试向cvMat提供由片段着色器生成的纹理,屏幕上没有任何显示,我不知道问题出在哪里,是驱动程序还是glreadPixels中的问题..我只是将TGA图像加载到片段着色器,然后对四边形进行纹理处理,我想将该纹理提供给cvMat,所以我使用glReadPixesl然后生成了一个新纹理,并将其绘制在四边形上,但是什么都没有出现.

I'm just trying to feed a cvMat a texture that is generated by fragment shader, there is nothing appears on the screen, I don't know where is the problem, is this in the driver or glreadPixels.. I just loaded a TGA Image, to a fragment shader, then textured a quad, I wanted to feed that texture to a cvMat, so I used glReadPixesl then genereated a new texture, and drew it on the quad, but nothing appears.

请注意,以下代码在每个帧处执行.

Kindly note that the following code is executed at each frame.

cv::Mat pixels;
    glPixelStorei(GL_PACK_ALIGNMENT, (pixels.step & 3) ? 1 : 4);
    glReadPixels(0, 0, 1024, 1024, GL_RGB, GL_UNSIGNED_BYTE, pixels.data);

    glEnable(GL_TEXTURE_2D);
    GLuint textureID;
    glGenTextures(1, &textureID);
       //glDeleteTextures(1, &textureID);

    // Create the texture
    glTexImage2D(GL_TEXTURE_2D,     // Type of texture
                 0,                 // Pyramid level (for mip-mapping) - 0 is the top level
                 GL_RGB,            // Internal colour format to convert to
                 1024,          // Image width  i.e. 640 for Kinect in standard mode
                 1024,          // Image height i.e. 480 for Kinect in standard mode
                 0,                 // Border width in pixels (can either be 1 or 0)
                 GL_RGB, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.)
                 GL_UNSIGNED_BYTE,  // Image data type
                 pixels.data);        // The actual image data itself

     glActiveTexture ( textureID );
     glBindTexture ( GL_TEXTURE_2D,textureID );
     glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );

推荐答案

textureID看起来像纹理不完整.

GL_TEXTURE_MIN_FILTER设置为GL_NEARESTGL_LINEAR.

或提供完整的mipmap集.

Or supply a complete set of mipmaps.

这篇关于从帧缓冲区GLSL读取到OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆