Apple 已经实现了带有一些附加功能的 ARKit beta 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)
}
}
最佳答案
我不完全确定这是否正确,但希望这对您有所帮助,或者至少让您入门。
我认为您需要查看从相机中获取数据以帮助解决此问题。例如:
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)
}
然后您可以(大致)确定设备是处于水平位置还是垂直位置。
关于swift - ARKit 图像检测方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49047912/