RealityKit 中的多面检测 [英] Multi-face detection in RealityKit

查看:34
本文介绍了RealityKit 中的多面检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Reality Composer 中向面部锚点添加了内容,稍后,在加载我在 Reality Composer 上创建的 Experience 后,我创建了这样的面部跟踪会话:

I have added content to the face anchor in Reality Composer, later on, after loading the Experience that i created on Reality Composer, i create a face tracking session like this:

guard ARFaceTrackingConfiguration.isSupported else { return }
let configuration = ARFaceTrackingConfiguration()
configuration.maximumNumberOfTrackedFaces = ARFaceTrackingConfiguration.supportedNumberOfTrackedFaces
configuration.isLightEstimationEnabled = true

arView.session.delegate = self
arView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])

它没有将内容添加到正在检测的所有面孔中,我知道它正在检测多个面孔,因为其他面孔遮挡了粘在另一张面孔上的内容,这是对 的限制RealityKit 或者我在作曲家中遗漏了什么?实际上很难错过一些东西,因为它非常基本和简单.

It is not adding the content to all the faces that is detecting, and i know it is detecting more than one face because the other faces occlude the content that is stick to the other face, is this a limitation on RealityKit or i am missing something in the composer? actually is pretty hard to miss somehting since it is so basic and simple.

谢谢.

推荐答案

如果您使用带有嵌入式 Face Anchor 的模型,即来自 Reality Composer' Face Tracking 的模型,您将无法在 RealityKit 中成功进行多面跟踪预设(您只能使用一个带有 .face 锚点的模型,而不是三个).或者您可以使用此类模型,但您需要删除这些嵌入的 AnchorEntity(.face) 锚点.尽管有更好的方法 - 只需以 .usdz 格式加载模型.

You can't succeed in multi-face tracking in RealityKit in case you use models with embedded Face Anchor, i.e. the models that came from Reality Composer' Face Tracking preset (you can use just one model with .face anchor, not three). Or you MAY USE such models but you need to delete these embedded AnchorEntity(.face) anchors. Although there's a better approach – simply load models in .usdz format.

让我们看看 Apple 文档关于嵌入式锚点:

Let's see what Apple documentation says about embedded anchors:

您可以使用代码手动加载和锚定 Reality Composer 场景,就像处理其他 ARKit 内容一样.当您在代码中锚定场景时,RealityKit 会忽略场景的锚定信息.

You can manually load and anchor Reality Composer scenes using code, like you do with other ARKit content. When you anchor a scene in code, RealityKit ignores the scene's anchoring information.

Reality Composer 支持 5 种锚点类型:Horizo​​ntalVerticalImageFace &<代码>对象.它为每种锚点类型显示一组不同的指南,以帮助您放置内容.如果您选择了错误的选项或改变了如何锚定场景的想法,您可以稍后更改锚点类型.

Reality Composer supports 5 anchor types: Horizontal, Vertical, Image, Face & Object. It displays a different set of guides for each anchor type to help you place your content. You can change the anchor type later if you choose the wrong option or change your mind about how to anchor your scene.

有两种选择:

  1. 在新的 Reality Composer 项目中,取消选中您在启动时看到的操作表左下角的使用默认内容创建复选框.

在 RealityKit 代码中,删除现有的 Face Anchor 并分配一个新的.后一个选项不太好,因为您需要从头开始重新创建对象位置:

In RealityKit code, delete existing Face Anchor and assign a new one. The latter option is not great because you need to recreate objects positions from scratch:

 boxAnchor.removeFromParent()

尽管如此,我已经在 session(:didUpdate:) 实例中使用 AnchorEntity()ARAnchor 初始化器实现了多面跟踪方法(就像 SceneKit 的 renderer() 实例方法).

Nevertheless, I've achieved a multi-face tracking using AnchorEntity() with ARAnchor intializer inside session(:didUpdate:) instance method (just like SceneKit's renderer() instance method).

这是我的代码:

import ARKit
import RealityKit

extension ViewController: ARSessionDelegate {
        
    func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
        
        guard let faceAnchor = anchors.first as? ARFaceAnchor
        else { return }
        
        let anchor1 = AnchorEntity(anchor: faceAnchor)
        let anchor2 = AnchorEntity(anchor: faceAnchor)
        
        anchor1.addChild(model01)
        anchor2.addChild(model02)           
        arView.scene.anchors.append(anchor1)
        arView.scene.anchors.append(anchor2)
    }
}
class ViewController: UIViewController {

    @IBOutlet var arView: ARView!
    let model01 = try! Entity.load(named: "angryFace")     // USDZ file
    let model02 = try! FacialExpression.loadSmilingFace()  // RC scene

    override func viewDidLoad() {
        super.viewDidLoad()
        arView.session.delegate = self

        guard ARFaceTrackingConfiguration.isSupported else {
            fatalError("Alas, Face Tracking isn't supported")
        }
    }    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let config = ARFaceTrackingConfiguration()
        config.maximumNumberOfTrackedFaces = 2
        arView.session.run(config)
    }
}

这篇关于RealityKit 中的多面检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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