开发者

OpenCV: is it possible to perform openGL pixel shading with it?

How to execute OpenGL pixel shaders on top of openCV images开发者_StackOverflow中文版 structures? is there any library or plugin for OpenCV for that?


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:

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);

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

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).

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


Sure you can, just upload your image as a OpenGL texture, draw a texture mapped quad and use a fragment shader to draw into another texture with a Framebuffer Object.

You can do that many times, and then readback the texture data to the CPU to get the final image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜