首页 > 利用OpenGL渲染并用OpenCV输出显示二维图像

利用OpenGL渲染并用OpenCV输出显示二维图像

OpenGL所有渲染的结果都输出显示在窗口中,设置OpenCV的图像cv::Mat outimg,并使用OpenGL的glReadPixels从帧缓冲区中加载像素至内存:

//use fast 4-byte alignment (default anyway) if possible
glPixelStorei(GL_PACK_ALIGNMENT, (outimg.step & 3) ? 1 : 4);
//set length of one complete row in destination data (doesn't need to equal img.cols)
glPixelStorei(GL_PACK_ROW_LENGTH, outimg.step / outimg.elemSize());
glReadPixels(0, 0, SCR_WIDTH, SCR_HEIGHT, GL_BGR, GL_UNSIGNED_BYTE, outimg.data);
cv::flip(outimg, outimg, 0);

注意:OpenGL坐标原点是左下方,OpenCV是左上方。

参考:

glDrawPixels(), glCopyPixels(),glReadPixels()

更多相关:

  • 嘿,我已经看过了一个老问题,但它不能回答我的问题我已经安装了libpng,然后尝试安装autopy并得到complie错误。在我对python还不是很在行,所以我不确定如何修复它们。在Ashley:~ ashleyhughes$ sudo easy_install autopySearching for autopyReading h...

  • 在主程序中我们先设置3个采样器名称 pbrShader.use();pbrShader.setInt("irradianceMap", 0);pbrShader.setInt("prefilterMap", 1);pbrShader.setInt("brdfLUT", 2);其中setint是封装函数:void setInt...

  • 操作都是在默认帧缓冲的渲染缓冲上进行的。默认的帧缓冲是在你创建窗口的时候生成和配置的(GLFW帮我们做了这些)。 帧缓存帮助我们离屏渲染,提高渲染速度 unsigned int captureFBO; glGenFramebuffers(1, &captureFBO); glBindFramebuffer(GL_FRAMEBUFF...

  • 为了将坐标从一个坐标系变换到另一个坐标系,我们需要用到几个变换矩阵,最重要的几个分别是模型(Model)、观察(View)、投影(Projection)三个矩阵。我们的顶点坐标起始于局部空间(Local Space),在这里它称为局部坐标(Local Coordinate),它在之后会变为世界坐标(World Coordinate),...

  • opengl原生库 gl* 随opengl一起发布 opengl实用库 glu* 随opengl一起发布 opengl实用工具库glut glut* 需要下载配置安装(太老了!) opengl实用工具库开源版本freeglut glut* 需要下载配置安装(完全兼容glut,算是glut的代替品,但是bug较多!) openg...