c++ - 从帧缓冲区 GLSL 读取到 OpenCV

标签 c++ opengl opencv opengl-es

我只是想给 cvMat 提供一个由片段着色器生成的纹理,屏幕上什么也没有出现,我不知道问题出在哪里,是在驱动程序中还是在 glreadPixels 中。我只是加载一个 TGA 图像,到一个片段着色器,然后纹理化一个四边形,我想将该纹理提供给一个 cvMat,所以我使用 glReadPixesl 然后生成一个新纹理,并将它绘制在四边形上,但没有出现。

请注意,以下代码会在每一帧执行。

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 看起来像 incomplete texture .

GL_TEXTURE_MIN_FILTER 设置为 GL_NEARESTGL_LINEAR

或提供一套完整的 mipmap。

关于c++ - 从帧缓冲区 GLSL 读取到 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14981881/

相关文章:

c++ - 指向类中方法的函数指针数组

python - 为什么pyglet.image和texture这么重?

c++ - 在 Visual Studio 中使用 C++17 静态内联成员时的奇怪行为

C++ 模板实例 : using enable_if directly, 或带有辅助类

VBO 中普通数据的 OpenGL 排列

c - 使用 Glut 和 C 时纹理扭曲

c++ - 如何在 opencv 中将 QPointf 转换为 Point?

c++ - 使用 OpenCV 写入 16 位未压缩图像

opencv - 生成文件:160: recipe for target 'all' failed

c++ - 使用 CFileDialog 选择文件时的绘画问题