Итак, моя цель:
Найти известное изображение
guard let referenceImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil) else { return }
let configuration = ARWorldTrackingConfiguration()
configuration.detectionImages = referenceImages
.
сделать снимок из sceneView
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
let image = sceneView.snapshot() // or else self.sceneView.session.currentFrame?.capturedImage
Мне нужно извлечь изображение из SceneView.
Это мой код, я использую метод renderer.projectPoint.
guard let imageAnchor = anchor as? ARImageAnchor else {
return
}
let posx = anchorTr.x// fnode.convertPosition(node.position, to: node).x //self.positionFromTransform(node.simdTransform).x// node.simdTransform.columns.3.x
let posy = anchorTr.y//fnode.convertPosition(node.position, to: node).y //self.positionFromTransform(node.simdTransform).y//node.simdTransform.columns.3.y
let posz = anchorTr.z //node.simdTransform.columns.3.z
let width = referenceImage.physicalSize.width
let height = referenceImage.physicalSize.height
let topLeftPosition = SCNVector3(posx - Float(width / 2), posy - Float(height / 2), posz )
let topRightPosition = SCNVector3(posx + Float(width / 2), posy - Float(height / 2), posz )
let bottomLeftPosition = SCNVector3(posx - Float(width / 2), posy + Float(height / 2), posz )
let bottomRightPosition = SCNVector3(posx + Float(width / 2), posy + Float(height / 2), posz)
let topLeftProjection = renderer.projectPoint(topLeftPosition)
let topRightProjection = '''
let bottomLeftProjection = '''
let bottomRightProjection = '''
let topLeft = CGPoint(x: CGFloat(topLeftProjection.x), y: CGFloat( topLeftProjection.y))
let topRight = ''
let bottomLeft = ''''''
let bottomRight = '''
let points = [topLeft, topRight, bottomRight, bottomLeft]
self.drawPolygon(points, color:.green)
но похоже, что этот метод зависит от положения сотового телефона,