OpenCV:是否可以用它执行openGL像素着色? [英] OpenCV: is it possible to perform openGL pixel shading with it?

查看:422
本文介绍了OpenCV:是否可以用它执行openGL像素着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在openCV图像结构上执行OpenGL像素着色器?

How to execute OpenGL pixel shaders on top of openCV images structures? is there any library or plugin for OpenCV for that?

推荐答案

我不会包括设置一个OpenGL上下文,执行实际的渲染操作等。将这看作是伪代码中的大纲,只是试图给你一个如何做的想法(假设你想在OpenCV中重用ouput:

I won't include setting up a OpenGL context, performing actual render operations etc. Consider this as an outline in pseudo code just trying to give you an idea on how you could do it (assuming you'd like to reuse the ouput in OpenCV:

首先你创建一个纹理(只需要做一次,coirse),然后你将图像数据从OpenCV上传到创建的纹理(或更新它)。

At first you create a texture (has to be done once only, of coirse), then you upload the image data from OpenCV to the created texture (or update it).

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, ...parameters based on your image, pointer to raw image data);

现在你的OpenCV图像是OpenGL纹理,

Now your OpenCV image is in an OpenGL texture. Later on you just have to render your image and retrieve the pixel data.

glViewport(0,0,imagewidth,imageheight); // has to be done once
renderTexturedQuadWithShaders();
glReadPixels(..., &pointer); // read the raw image data again

这应该可以工作,但不要忘记不得不使用正确的纹理格式不拧紧你的图像数据,你可能需要使用另一个缓冲区(现在我不能100%确定是否可以将图像数据写入您的OpenCV图像)。

This should work, however don't forget that you'll have to use the correct texture formats to not screw up your image data and you might have to use another buffer (right now I'm not 100% sure if you could write the image data right into your OpenCV image).

编辑:你可以渲染到屏幕或一个framebuffer对象,基本概念保持不变。只要确保渲染到正确的目标。

You can render to screen or a framebuffer object, the basic concept stays the same. Just ensure you render to the correct target.

这篇关于OpenCV:是否可以用它执行openGL像素着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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