【问题标题】:ARKit and Vision – How to place a SCNPlane on a found QR-Code?ARKit 和 Vision – 如何在找到的 QR 码上放置 SCNPlane?
【发布时间】:2018-04-15 01:24:00
【问题描述】:

通过Vision 框架,我能够检测到二维码。接下来我想做的是使用 ARKit 将 SCNPlane 准确地放置在 QRCode 上。我编写了下面的代码来查找 QRCode 在现实世界中的位置。但是 SCNPlane 一直添加在错误的位置。下面代码中的barcode变量是VNBarcodeObservation类型。

也许你们中的一个人知道我做错了什么。

let rect = CGPoint(x: barcode.boundingBox.origin.x, y: barcode.boundingBox.origin.y)
let hitTestResults = sceneView.hitTest(rect, types: [.existingPlaneUsingExtent, .existingPlane])
if let hitResult = hitTestResults.first {

    //TODO: change to width and height
    let plane = SCNPlane(width: 0.1, height: 0.1)
    let material = SCNMaterial()
    material.diffuse.contents = UIColor.red
    plane.materials = [material]

    let node = SCNNode()        
    node.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0)

    node.position = SCNVector3(hitResult.worldTransform.columns.3.x,
                                         hitResult.worldTransform.columns.3.y,
                                         hitResult.worldTransform.columns.3.z)

    node.geometry = plane  
    sceneView.scene.rootNode.addChildNode(node)
}

编辑:

添加了当前情况的图片。左上角添加了红色平面。但是,这架飞机必须准确地添加到 te QRCode 上。

【问题讨论】:

  • 嗨,我也在尝试使用 Vision 实现 QR 码扫描,并使用 ARKit 在 QR 码上显示一些对象。你能分享更多关于你是如何做到这一点的细节吗?
  • 嗨@Mithun,请查看:github.com/Koen6095/ARKit

标签: ios scenekit qr-code arkit apple-vision


【解决方案1】:

使用中心点而不是原点对我有用:

let center2 = CGPoint(x: result.boundingBox.midX, y: result.boundingBox.midY)

let hitTestResults2 = frame.hitTest(center2, types: [.featurePoint/*, .estimatedHorizontalPlane, .existingPlane, .existingPlaneUsingExtent*/] )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 2020-06-04
    • 2018-12-22
    • 2019-10-09
    • 2017-12-29
    相关资源
    最近更新 更多