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

查看:143
本文介绍了在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.

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

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?

推荐答案

以下是此问题的关键:

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天全站免登陆