我正在使用iPhone X并ARFaceKit捕捉用户的脸部.目标是使用用户的图像纹理面部网格.
我只是ARFrame从AR会话中看一帧(一).从ARFaceGeometry,我有一组描述脸部的顶点.我制作了当前帧的jpeg表示capturedImage.
然后我想找到将创建的jpeg映射到网格顶点的纹理坐标.我想:1.将顶点从模型空间映射到世界空间; 2.将顶点从世界空间映射到摄像机空间; 3.除以图像尺寸以获得纹理的像素坐标.
let geometry: ARFaceGeometry = contentUpdater.faceGeometry!
let theCamera = session.currentFrame?.camera
let theFaceAnchor:SCNNode = contentUpdater.faceNode
let anchorTransform = float4x4((theFaceAnchor?.transform)!)
for index in 0..<totalVertices {
let vertex = geometry.vertices[index]
// Step 1: Model space to world space, using the anchor's transform
let vertex4 = float4(vertex.x, vertex.y, vertex.z, 1.0)
let worldSpace = anchorTransform * vertex4
// Step 2: World space to camera space
let world3 = float3(worldSpace.x, worldSpace.y, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将其投射ARAnchor到2D空间,但是我面临着方向问题...
在我的函数下方,将左上角,右上角,左下角,右下角位置投影到2D空间:
/// Returns the projection of an `ARImageAnchor` from the 3D world space
/// detected by ARKit into the 2D space of a view rendering the scene.
///
/// - Parameter from: An Anchor instance for projecting.
/// - Returns: An optional `CGRect` corresponding on `ARImageAnchor` projection.
internal func projection(from anchor: ARImageAnchor,
alignment: ARPlaneAnchor.Alignment,
debug: Bool = false) -> CGRect? {
guard let camera = session.currentFrame?.camera else {
return nil
}
let refImg = anchor.referenceImage
let anchor3DPoint …Run Code Online (Sandbox Code Playgroud) 我正在使用ar参考图像处理名片配置文件信息.当参考检测到它将显示公司首席执行官的详细信息,地址,照片和团队成员信息等.最初检测到图像,飞机将使用runAction amintion 向右移动.
我的问题是检测到的,飞机位置稳定,它在这里和那里移动.如何使用参考图像拟合平面位置.
这是我的结果截图:[![在此输入图像描述] [1]] [1]
这是我使用的代码:
var weboverlayview: CALayer?
var loadWeb: UIWebView?
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
sceneView.autoenablesDefaultLighting = true
let ARScene = SCNScene()
sceneView.scene = ARScene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.vertical, .horizontal]
configuration.detectionImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil)
// Run …Run Code Online (Sandbox Code Playgroud) 我正在SceneKit中显示由几个SNNode组成的3D模型。
我在sceneview-overlay视图上显示2D SpriteKit节点。2D节点的位置应始终在特定3D SCNNode的前面。
如何将3D位置映射到SpriteKit 2D位置?
我试过了let screenPoint = sceneView.projectPoint(my3dNode),但这是行不通的:即使my3dNode位于屏幕中央,该函数也会返回非常奇怪的值(例如,负值或超过1000)。
你有什么想法吗?