这是我用于ARImageTrackingConfiguration()
的简单对象。
在代码内,我将一个平面和paperPlane添加到已识别的对象上:
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
if let imageAnchor = anchor as? ARImageAnchor {
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width,
height: imageAnchor.referenceImage.physicalSize.height)
plane.firstMaterial?.diffuse.contents = UIColor.green.withAlphaComponent(0.8)
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2
planeNode.position.y = 0
let paperPlaneScene = SCNScene(named: "Scenes.scnassets/paperPlane.scn")!
let paperPlaneNode = paperPlaneScene.rootNode.childNodes.first!
paperPlaneNode.position = SCNVector3Zero
paperPlaneNode.position.z = 0.1
paperPlaneNode.eulerAngles.y = -.pi / 2
paperPlaneNode.eulerAngles.z = .pi
planeNode.addChildNode(paperPlaneNode)
node.addChildNode(planeNode)
}
return node
}
但是结果如下:
为什么一次只能识别一个物体?不是每个人?它们被一一识别,但一次也不会被所有人识别。为什么?
var maximumNumberOfTrackedImages: Int { get set }
或:
guard let reference = ARReferenceImage.referenceImages(inGroupNamed: "ARRes",
bundle: nil)
else {
fatalError("Missing resources.")
}
let config = ARWorldTrackingConfiguration()
config.maximumNumberOfTrackedImages = 4
config.detectionImages = reference
arView.session.run(config, options: [.resetTracking, .removeExistingAnchors])