开发者

How to generate an OpenGL texture from non-continous data?

开发者 https://www.devze.com 2023-02-05 11:01 出处:网络
My goal is to create a texture from a webcam image. I get the image via OpenCV\'s new VideoCapture interface from a Logitech QuickCam for Notebooks webcam. The problem is that I get non-continuos data

My goal is to create a texture from a webcam image. I get the image via OpenCV's new VideoCapture interface from a Logitech QuickCam for Notebooks webcam. The problem is that I get non-continuos data this way, which means that each row of the matrix holding my image data has a gap at the end.

The layout of my image data is as following:

width = frame.cols * frame.elemSize(); // 640 * 3 = 1920 byte
step = frame.step[0]; // 2560 byte
gap = step - width; // 640 byte

However, I did not find a way to tell OpenGL to skip the last 640 byte of every row when loading the texture. I wonder if there is a way doing that? If I just load the data as texture anyway, the image does not show correct (no surprise here). See http://picasaweb.google.com/103165673068768416583/Opencv#5562843683120979026

The best solution would be to get continuos data in the first place, but again I could not find out how to do this (with OpenCV). If I copy the data开发者_JS百科 to a continuos matrix, it is displayed correctly (see http://picasaweb.google.com/103165673068768416583/Opencv#5562843692435711522).

However, I don't want to copy data if I dont have to. Any ideas?


You could try a combination of GL_UNPACK_ALIGNMENT and GL_UNPACK_ROW_LENGTH.

In your specific case, this would give :

glPixelStorei(GL_UNPACK_ALIGNMENT, 4)         // as 2560 is a multiple of 4
glPixelStorei(GL_UNPACK_ROW_LENGTH, 2560/3)   // to consider each row having this number of pixels

But all in all, are you sure that each pixel have 3 bytes ?

I've noticed that your step is frame.cols * 4, I would not be surprised if each pixel had a padding byte to have an alignment that is a multiple of 4.

Have you tried instructing OpenGL that your source data is GL_RGBA or GL_BGRA, while leaving the texture internal format to GL_RGB ?

0

精彩评论

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

关注公众号