苹果已经推出了ARKit测试版1.5,并增加了一些功能。(垂直平面检测,图像检测,.)
我正在进行图像检测,我想知道在检测图像时我们如何获得定位信息?(垂直/水平图像检测)
获取这些信息的唯一方法是使用ARPlaneAnchor.Alignment。
在Apple示例项目中,他们假设图像在其本地空间是水平的。
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let imageAnchor = anchor as? ARImageAnchor else { return }
let referenceImage = imageAnchor.referenceImage
updateQueue.async {
// Create a plane to visualize the initial position of the detected image.
let plane = SCNPlane(width: referenceImage.physicalSize.width,
height: referenceImage.physicalSize.height)
let planeNode = SCNNode(geometry: plane)
planeNode.opacity = 0.25
/*
`SCNPlane` is vertically oriented in its local coordinate space, but
`ARImageAnchor` assumes the image is horizontal in its local space, so
rotate the plane to match.
*/
planeNode.eulerAngles.x = -.pi / 2
/*
Image anchors are not tracked after initial detection, so create an
animation that limits the duration for which the plane visualization appears.
*/
planeNode.runAction(self.imageHighlightAction)
// Add the plane visualization to the scene.
node.addChildNode(planeNode)
}
}发布于 2018-03-01 14:06:23
我不完全确定这是否正确,但希望这将帮助你,或至少让你开始。
我认为你需要从摄像机中获取数据来帮助解决这个问题。例如:
func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
/*
Get The Pitch (Rotation Around X Axis)
Get The Yaw (Rotation Around Y Axis)
Get The Roll (Rotation Around Z Axis)
*/
guard let pitch = self.augmentedRealityView.session.currentFrame?.camera.eulerAngles.x,
let yaw = self.augmentedRealityView.session.currentFrame?.camera.eulerAngles.y,
let roll = self.augmentedRealityView.session.currentFrame?.camera.eulerAngles.z else { return }
print("""
Pitch = \(degreesFrom(pitch))
Yaw = \(degreesFrom(yaw))
Roll = \(degreesFrom(roll))
""")
}
/// Convert Radians To Degrees
///
/// - Parameter radian: Float
/// - Returns: Float
func degreesFrom( _ radian: Float) -> Float{
return radian * Float(180.0 / Double.pi)
}

然后,您可以确定(大约)设备是处于水平位置还是垂直位置。
发布于 2019-01-28 07:33:09
在使用垂直和水平平面检测的ARKit应用程序中,我们可以使用属性ARPlaneAnchor.Alignment获取平面方向。
https://stackoverflow.com/questions/49047912
复制相似问题