1

我正在尝试将片段着色器生成的纹理转换为opencv。我在 beagleboard 上使用 opengles2 运行着色器。我认为我的驱动程序存在一些兼容性问题,或者在与 OpenCV 结合时出现了一些错误。所以基本上,我有一个着色纹理,然后我对它进行了一些处理,然后我将它保存,我需要再次将结果显示在四边形上。这是绘图的代码。它每帧执行一次。

       // Bind the base map
        glActiveTexture ( GL_TEXTURE0 );
        glBindTexture ( GL_TEXTURE_2D, userData->baseMapTexId );
       //  Set the base map sampler to texture unit to 0
        glUniform1i ( userData->baseMapLoc, 0 );
        cv::Mat img(1024, 1024, CV_8UC3);
        //cv::Mat flipped;
        cv::Mat thresholded;
        glPixelStorei(GL_PACK_ALIGNMENT, (img.step & 3) ? 1 : 4);
        glReadPixels(0, 0, img.cols, img.rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, img.data);
       // cv::flip(img, flipped, 0);
        cv::threshold(img, thresholded, 20, 255, CV_THRESH_BINARY );

        GLuint textureID;
        glGenTextures(1, &textureID);
        glBindTexture(GL_TEXTURE_2D, textureID);
        GLenum inputColourFormat = GL_LUMINANCE;

        // 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
                     thresholded.cols,          // Image width  i.e. 640 for Kinect in standard mode
                     thresholded.rows,          // Image height i.e. 480 for Kinect in standard mode
                     0,                 // Border width in pixels (can either be 1 or 0)
                     inputColourFormat, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.)
                     GL_UNSIGNED_BYTE,  // Image data type
                     thresholded.ptr());        // The actual image data itself
        // Bind texture
        glBindTexture(GL_TEXTURE_2D, textureID);

        glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );


        glDeleteTextures(1, &textureID);

       eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
4

0 回答 0