我正在尝试使用ARKit 1.5进行图像识别,正如我们可以在苹果的样本项目代码中看到的那样:图像锚在初始检测后不会被跟踪,所以创建一个动画来限制平面可视化出现的持续时间。
ARImageAnchor没有像ARPlaneAnchor那样的center: vector_float3,我也找不到如何跟踪检测到的图像锚点。
我想在这个视频中实现类似的东西,即有一个固定映像、按钮、标签等等,保持在检测到的图像上,我不知道我怎么能做到这一点。
以下是图像检测结果的代码:
// MARK: - ARSCNViewDelegate (Image detection results)
/// - Tag: ARImageAnchor-Visualizing
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)
plane.materials.first?.diffuse.contents = UIColor.blue.withAlphaComponent(0.20)
self.planeNode = SCNNode(geometry: plane)
self.planeNode?.opacity = 1
/*
`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.
*/
self.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.
*/
// Add the plane visualization to the scene.
if let planeNode = self.planeNode {
node.addChildNode(planeNode)
}
if let imageName = referenceImage.name {
plane.materials = [SCNMaterial()]
plane.materials[0].diffuse.contents = UIImage(named: imageName)
}
}
DispatchQueue.main.async {
let imageName = referenceImage.name ?? ""
self.statusViewController.cancelAllScheduledMessages()
self.statusViewController.showMessage("Detected image “\(imageName)”")
}
}发布于 2018-03-08 18:36:10
首先,我还没有完全完成您想要做的事情,因此,如果我要实现它,这只是我要开始的地方--…
根据您列出的代码,您正在使用Apple的示例代码来识别AR体验中的图像。该项目设置为使用没有标签、按钮或图像的SceneKit。这意味着您需要使用SpriteKit,它具有可以显示标签和图像的节点。
这意味着您的第一步是创建一个全新的项目,并选择内容技术设置为SpriteKit的增强现实模板。
您可以从苹果的图像识别示例中查看resetTracking(),了解如何设置图像识别部分。您还需要手动将AR资源文件夹添加到资产目录中,以保存所有引用图像。
对于项目的放置,您将使用SpriteKit版本的renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor),即view(_ view: ARSKView, didAdd node: SKNode, for anchor: ARAnchor)。
苹果的图像识别示例代码在参考图像的中心添加了新的SceneKit对象,并且如果图像不被移动,虚拟对象就会停留在中心(-ish)。
我们还知道,我们可以获得参考图像的高度和宽度(如您发布的代码所示)。
很可能我们也可以用SpriteKit获得参考图像的尺寸,而新放置的SKNodes将以SCNNodes的方式在检测到的图像的中心结束。这意味着我们应该能够创建一个新的SKNode (用于图像的SKSpriteNode或用于标签的SKLabelNode ),并将其转换到参考图像高度的一半以获得图像的顶部中心。一旦节点被放置,它就应该被贴在海报上(ARKit并不完美,所以会发生一些小的移动)。
发布于 2019-11-12 09:27:13
https://stackoverflow.com/questions/49176796
复制相似问题