为什么AVCaptureSession中的灰度OpenGL ES纹理被替换?

时间:2022-09-07 09:12:14

Here's the problem, I am working on a little project on the iPhone with OpenGL ES. I started with Brad Larson's ColorTracking App (Big thanks to Brad for providing it) and tuned it to my needs.

问题是,我正在用OpenGL ES做一个关于iPhone的小项目。我从Brad Larson的ColorTracking应用程序开始(感谢Brad提供它),并根据我的需要调整它。

Everything is working fine, however, when I use the kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange for the kCVPixelBufferPixelFormatTypeKey in my AVCaptureVideoDataOutput, since I'll be working on greyscale images and don't need any colors anyway, the resulted image on the screen is translated along the y-axis, and the part which goes off-screen is rendered on the top:

一切工作正常,然而,当我使用的kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange kCVPixelBufferPixelFormatTypeKey AVCaptureVideoDataOutput,因为我会在灰度图像和不需要任何颜色,使得图像在屏幕上是沿着轴,翻译和部分是离屏上呈现的:

Here is a a screenshot:

这里有一个截屏:

为什么AVCaptureSession中的灰度OpenGL ES纹理被替换?

Of course you need to change the data type in the glTexImage2D call from GL_RGBA to GL_LUMINANCE for this to work.

当然,您需要将glTexImage2D调用中的数据类型从GL_RGBA更改为GL_LUMINANCE,以使其工作。

This behavior doesn't occur using the GL_RGBA texture from a kCVPixelFormatType_32BGRA capture session.

使用来自kCVPixelFormatType_32BGRA捕获会话的GL_RGBA纹理不会发生这种行为。

Does anyone know why this happens, and how to fix this? Any help is much appreciated.

有人知道为什么会发生这种情况吗?非常感谢您的帮助。

1 个解决方案

#1


3  

I have found the answer for this problem:

我已经找到了这个问题的答案:

the glTextImage2D call should be changed to get the right base address of the CVImageBufferRef:

应该更改glTextImage2D调用,以获得CVImageBufferRef的正确基本地址:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddressOfPlane(pixelBuffer));

// should become 

glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, bufferWidth, bufferHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0));

In case of the kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange we need to get the first plane which contains the luminance data. Notice the data type is GL_LUMINANCE and the data pointer is CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0)

对于kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,我们需要得到包含亮度数据的第一个平面。注意数据类型是GL_LUMINANCE数据指针是CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0)

#1


3  

I have found the answer for this problem:

我已经找到了这个问题的答案:

the glTextImage2D call should be changed to get the right base address of the CVImageBufferRef:

应该更改glTextImage2D调用,以获得CVImageBufferRef的正确基本地址:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddressOfPlane(pixelBuffer));

// should become 

glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, bufferWidth, bufferHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0));

In case of the kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange we need to get the first plane which contains the luminance data. Notice the data type is GL_LUMINANCE and the data pointer is CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0)

对于kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,我们需要得到包含亮度数据的第一个平面。注意数据类型是GL_LUMINANCE数据指针是CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0)