在 SceneKit 下可靠地访问和修改捕获的相机帧 [英] Reliable access and modify captured camera frames under SceneKit

查看:29
本文介绍了在 SceneKit 下可靠地访问和修改捕获的相机帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试向 ARSCNView 的相机图像添加黑白滤镜,然后在其上渲染彩色 AR 对象.

I try to add a B&W filter to the camera images of an ARSCNView, then render colored AR objects over it.

我快到了,在 - (void)renderer:(id<SCNSceneRenderer>)aRenderer updateAtTime:(NSTimeInterval)time

CVPixelBufferRef bg=self.sceneView.session.currentFrame.capturedImage;

if(bg){
    char* k1 = CVPixelBufferGetBaseAddressOfPlane(bg, 1);
    if(k1){
        size_t x1 = CVPixelBufferGetWidthOfPlane(bg, 1);
        size_t y1 = CVPixelBufferGetHeightOfPlane(bg, 1);
        memset(k1, 128, x1*y1*2);
    }
}

这在移动设备上运行得非常快,但问题是:有时会显示一个彩色框架.我已经检查并执行了我的过滤代码,但我认为为时已晚,SceneKit 的管道已经处理了相机输入.

This works really fast on mobile, but here's the thing: sometimes a colored frame is displayed. I've checked and my filtering code is executed but I assume it's too late, SceneKit's pipeline already processed camera input.

提前调用代码会有所帮助,但 updateAtTime 是可以逐帧代码添加自定义帧的最早点.

Calling the code earlier would help, but updateAtTime is the earliest point one can add custom frame by frame code.

获取有关帧捕获的通知可能会有所帮助,但看起来整个 AVCapturesession 都无法访问.

Getting notifications on frame captures might help, but looks like the whole AVCapturesession is unaccessible.

Metal ARKit 示例展示了如何将相机图像转换为 RGB,这是我将进行过滤的地方,但在使用 SceneKit 时该着色器是隐藏的.

The Metal ARKit example shows how to convert the camera image to RGB and that is the place where I would do filtering, but that shader is hidden when using SceneKit.

我已经尝试过这个可能的答案,但速度太慢了.

I've tried this possible answer but it's way too slow.

那么我怎样才能克服失帧并将相机输入可靠地转换为黑白?

So how can I overcome the frame misses and convert the camera feed reliably to BW?

推荐答案

这里是这个问题的关键:

Here's the key for this problem:

session:didUpdateFrame:

向代表提供新捕获的相机图像和随附的 AR 信息.

Provides a newly captured camera image and accompanying AR information to the delegate.

所以刚刚移动了CVPixelBufferRef操作,图像过滤代码来自

So just moved CVPixelBufferRef manipulation, the image filtering code from

- (void)renderer:(id<SCNSceneRenderer>)aRenderer updateAtTime:(NSTimeInterval)time

- (void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame

确保设置 self.sceneView.session.delegate = self 以调用此委托.

Made sure to set self.sceneView.session.delegate = self to have this delegate called.

这篇关于在 SceneKit 下可靠地访问和修改捕获的相机帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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