使用 ARCore/ARKit 基于标记的初始定位? [英] Marker based initial positioning with ARCore/ARKit?

查看:29
本文介绍了使用 ARCore/ARKit 基于标记的初始定位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题情况:始终在同一个地方(在桌子上)以舒适的方式创建 AR 可视化.我们不希望客户像在无数 ARCore/ARKit 示例中那样自行放置对象.

problem situation: Creating AR-Visualizations always at the same place (on a table) in a comfortable way. We don't want the customer to place the objects themselves like in countless ARCore/ARKit examples.

我想知道是否有办法实现这些步骤:

I'm wondering if there is a way to implement those steps:

  1. 检测桌子上的标记
  2. 使用标记的位置作为 AR-Visualization 的初始位置并继续进行 SLAM-Tracking

我知道最新版本的 TangoSDK 中包含类似标记检测 API 的内容.但这项技术仅限于少量设备(准确地说是两个......).

I know there is something like an Marker-Detection API included in the latest build of the TangoSDK. But this technology is limited to a small amount of devices (two to be exact...).

最好的问候并提前感谢您的任何想法

best regards and thanks in advance for any idea

推荐答案

这是我目前为 ARKit 所做的.

This is what i got so far for ARKit.

@objc func tap(_ sender: UITapGestureRecognizer){
    let touchLocation = sender.location(in: sceneView)
    let hitTestResult = sceneView.hitTest(touchLocation, types: .featurePoint)

    if let hitResult = hitTestResult.first{
        if first == nil{
            first = SCNVector3Make(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)
        }else if second == nil{
            second = SCNVector3Make(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)
        }else{
            third = SCNVector3Make(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)

            let x2 = first!.x
            let z2 = -first!.z
            let x1 = second!.x
            let z1 = -second!.z
            let z3 = -third!.z

            let m = (z1-z2)/(x1-x2)
            var a = atan(m)

            if (x1 < 0 && z1 < 0){
                a = a + (Float.pi*2)
            }else if(x1 > 0 && z1 < 0){
                a = a - (Float.pi*2)
            }

            sceneView.scene.rootNode.addChildNode(yourNode)
            let rotate = SCNAction.rotateBy(x: 0, y: CGFloat(a), z: 0, duration: 0.1)
            yourNode.runAction(rotate)
            yourNode.position = first!

            if z3 - z1 < 0{
                let rotate = SCNAction.rotateBy(x: 0, y: CGFloat.pi, z: 0, duration: 0.1)
                yourNode.runAction(rotate)
            }
        }
    }
}

理论是:
做三个点 A、B、C,使 AB 垂直于 AC.按 A-B-C 的顺序点按点.
在 ARSceneView 的 x=0 中找到 AB 的角度,这给出了节点所需的旋转.
可以参考任意一个点来计算放置节点的位置.
从 C 中查找节点是否需要翻转.

Theory is:
Make three dots A,B,C such that AB is perpendicular to AC. Tap dots in order A-B-C.
Find angle of AB in x=0 of ARSceneView which gives required rotation for node.
Any one of the point can be refrenced to calculate position to place node.
From C find if node needs to be flipped.

我仍在处理一些需要满足的例外情况.

I am still working on some exceptions that needs to be satisfied.

这篇关于使用 ARCore/ARKit 基于标记的初始定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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