【发布时间】:2019-10-09 21:06:28
【问题描述】:
使用 iPhoneX True-Depth 摄像头可以获得任何对象的 3D 坐标并使用该信息来定位和缩放对象,但是对于较旧的 iPhone,我们无法使用前置摄像头上的 AR,我到目前为止,我们所做的是使用 Apple Vison 框架检测人脸并在人脸或地标周围绘制一些 2D 路径。 我制作了一个 SceneView 并将其应用为具有清晰背景的 My view 的前层,在其下方是 AVCaptureVideoPreviewLayer ,在检测到我的面部后,我的 3D 对象出现在屏幕上但是根据面部boundingBox正确定位和缩放它需要取消投影和其他我卡在那里的东西,我也尝试使用CATransform3D将2D BoundingBox转换为3D但我失败了!我想知道我想要实现的目标是否可能?如果我没记错的话,我记得 SnapChat 在 iPhone 上推出 ARKit 之前就已经这样做了!
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(self.sceneView)
self.sceneView.frame = self.view.bounds
self.sceneView.backgroundColor = .clear
self.node = self.scene.rootNode.childNode(withName: "face",
recursively: true)!
}
fileprivate func updateFaceView(for result:
VNFaceObservation, twoDFace: Face2D) {
let box = convert(rect: result.boundingBox)
defer {
DispatchQueue.main.async {
self.faceView.setNeedsDisplay()
}
}
faceView.boundingBox = box
self.sceneView.scene?.rootNode.addChildNode(self.node)
let unprojectedBox = SCNVector3(box.origin.x, box.origin.y,
0.8)
let worldPoint = sceneView.unprojectPoint(unprojectedBox)
self.node.position = worldPoint
/* Here i have to to unprojecting
to convert the value from a 2D point to 3D point also
issue here. */
}
【问题讨论】:
标签: swift xcode 3d face-detection apple-vision