菜鸟教程小白 发表于 2022-12-13 15:08:17

ios - 增强现实 : camera stream on OpenGL view


                                            <p><p>AR(增强现实)似乎是当今所有 iO 开发人员都在关注的内容。我正在玩一个非常经典的宠物项目,用纹理滚动骰子,如果可能的话,将相机流放在骰子面上。我在最后一部分面临一些问题,我有一些问题要问专家:</p>

<p>获取视频流需要 AV Foundation : <code>AVCaptureVideoDataOutputSampleBufferDelegate</code> 获取图像缓冲区,然后使用 Quartz 函数(如 <code>CGBitmapContextCreate</code>)构建 <code>UIImage</code>。这在 <a href="http://www.benjaminloulier.com/articles/ios4-and-direct-access-to-the-camera" rel="noreferrer noopener nofollow">http://www.benjaminloulier.com/articles/ios4-and-direct-access-to-the-camera</a> 中得到了证明或在苹果 AV Foundation Programming Guide 中(参见 <a href="https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW30" rel="noreferrer noopener nofollow">https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW30</a>)</p>

<p>然后我可以像为“静止”图像所做的那样创建纹理,并将其与 <code>GLKBaseEffect</code>(或着色器?)一起使用。</p>

<p>问题 1:<code>GLKBaseEffect</code> 看起来真的很简单,但我应该瞄准 OpenGL 2 和着色器吗? </p>

<p>现在来自苹果的 RosyWriter 演示使用 Core Video <code>CVOpenGLESTextureCacheCreateTextureFromImage</code> 函数直接绑定(bind)纹理,而无需创建中间 <code>UIImage</code>。这是 - 如演示说明中所述 - IOS 5 中的新功能。</p>

<p>问题 2:这是映射纹理的更好方法吗?</p>

<p>问题 3:有一些有趣的框架,例如 GPUImage,甚至 3D 游戏框架也可以使用。有人对使用这些有什么反馈吗?到目前为止,苹果提供的框架对我来说似乎相当完整。</p>

<p>非常感谢!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>回答您的各种问题:</p>

<blockquote>
<p>GLKBaseEffect seems really nice and simple, but should I aim for
OpenGL 2 and shaders ?</p>
</blockquote>

<p>GLKBaseEffect 只是一些简单的 OpenGL ES 2.0 着色器的封装,因此它的核心使用 2.0。虽然 GLKit 提供了一些很好的便利,但最终您将需要创建默认情况下无法提供的效果,因此您很可能需要在某个时候学习如何制作自己的顶点和片段着色器。我在 <a href="https://stackoverflow.com/a/8495261/19679" rel="noreferrer noopener nofollow">this answer</a> 中列出了一些学习资源.</p>

<blockquote>
<p>Now the RosyWriter demo from apple uses the Core Video
CVOpenGLESTextureCacheCreateTextureFromImage function to bind directly
the texture without creating an intermediary UIImage. This is - as
stated in the demo description - new in IOS 5.</p>

<p>Question 2: is this a better way to map the texture ?</p>
</blockquote>

<p>是的,在 iOS 5.0 上,使用纹理缓存上传视频帧可以带来一些可靠的性能改进。对于 iPhone 4S,使用纹理缓存时,我看到帧上传时间从 640x480 帧的 9.3 ms 下降到 1.8 ms。使用 <a href="https://stackoverflow.com/questions/9550297/faster-alternative-to-glreadpixels-in-iphone-opengl-es-2-0/9704392#9704392" rel="noreferrer noopener nofollow">reading from the texture caches to encode video</a> 时可以获得更大的好处。 .</p>

<blockquote>
<p>Question 3: There are a few interesting frameworks, like GPUImage, or
even 3D Gaming frameworks that could be used too. Has anyone some
feedback on using these ? The apple provided frameworks seem quite
complete to me so far.</p>
</blockquote>

<p>我建议为此使用 GPUImage,但我有点偏颇,看看我是如何编写它的。作为更具体的一点,我在该框架的示例代码中的 CubeExample 中几乎完全按照您的描述(读取视频帧并将它们映射到旋转立方体的侧面)。 </p>

<p>这个例子有点复杂,因为我拍摄实时视频,通过棕褐色调滤镜运行它,将其作为纹理读入并将其显示在可以用手指旋转的 3-D 立方体上,然后将立方体的渲染 View 通过像素化过滤器运行。但是,您可以仅从该示例中提取您需要的部分。通过这样做,您将节省大量代码,因为我会为您处理视频捕获和上传到 OpenGL ES。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 增强现实 : camera stream on OpenGL view,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/11620346/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/11620346/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 增强现实 : camera stream on OpenGL view