所以,我的目标是:
使用 ARReferenceImage 很容易完成第一步:
guard let referenceImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil) else { return }
let configuration = ARWorldTrackingConfiguration()
configuration.detectionImages = referenceImages
但现在我不知道如何从 SceneView 中提取图像。我已将平面节点添加到 imageAnchor:
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
DispatchQueue.main.async { [unowned self] in
guard let imageAnchor = anchor as? ARImageAnchor
else { return }
let planeNode = self.getPlaneNode(withReferenceImage: imageAnchor.referenceImage)
planeNode.opacity = 0.5
planeNode.eulerAngles.x = -.pi / 2
node.addChildNode(planeNode)
}
}
所以,我需要planeNode 在屏幕上的投影 来获取节点的2D 屏幕坐标,然后剪切图像。我找到了这个方法: renderer.projectPoint(node.position)
但它对我没有帮助。当整个图片在屏幕上时,它甚至可以返回负值..
我的做法是否正确?任何帮助将不胜感激 .
就我而言,我解决了。
let transform = node.simdConvertTransform(node.simdTransform, to: node.parent!)
let x = transform.columns.3.x
let y = transform.columns.3.y
let z = transform.columns.3.z
let position = SCNVector3(x, y, z)
let projection = renderer.projectPoint(position)
let screenPoint = CGPoint(x: CGFloat(projection.x), y: CGFloat( projection.y))
更多信息
ARKit 2 - Crop Recognizing Images
iOS 8 Core Image saving a section of an Image via Swift
https://nacho4d-nacho4d.blogspot.com/2012/03/coreimage-and-uikit-coordinates.html
关于ios - ARKit 1.5 : Extract the recognized image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50871959/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |