ARKit和AVCamera同时使用

6
由于ARKit没有自动对焦功能,我想在屏幕的一半加载ARKit,另一半加载AVFoundation中的AVCamera。 是否可能在同一个应用程序中同时加载AVCamera和ARKit? 谢谢。
3个回答

7

不行。

ARKit在内部使用AVCapture(如介绍ARKit的WWDC演讲中所解释的)。一次只能运行一个AVCaptureSession,因此如果你运行自己的捕获会话,它将挂起ARKit的会话(并破坏跟踪)。

更新: 但是,在iOS 11.3(又名“ARKit 1.5”)中,ARKit默认启用自动对焦,并且您可以选择使用isAutoFocusEnabled选项禁用它。


0

改变相机的焦点会破坏跟踪 - 所以目前肯定不可能。

更新:请参见上面@rickster的答案。


1
自动对焦在iOS 11.3中是可行的,并且默认情况下是开启的(请参见我的更新答案),但在早期的iOS版本中不支持。 - rickster

0

我成功地使用AVFoundation和ARKit,通过在拍照后立即调用self.sceneView.session.run(self.sceneView.session.configuration!)。

在拍照后立即使用self.captureSession?.stopRunning(),以使会话恢复更快。

self.takePhoto()
self.sceneView.session.run(self.sceneView.session.configuration!)

 func startCamera() {
    captureSession = AVCaptureSession()
    captureSession.sessionPreset = AVCaptureSession.Preset.photo
    cameraOutput = AVCapturePhotoOutput()

    if let device = AVCaptureDevice.default(for: .video),
       let input = try? AVCaptureDeviceInput(device: device) {
        if (captureSession.canAddInput(input)) {
            captureSession.addInput(input)
            if (captureSession.canAddOutput(cameraOutput)) {
                captureSession.addOutput(cameraOutput)
                captureSession.startRunning()
            }
        } else {
            print("issue here : captureSesssion.canAddInput")
        }
    } else {
        print("some problem here")
    }
}

func takePhoto() {
    startCamera()
    let settings = AVCapturePhotoSettings()
    cameraOutput.capturePhoto(with: settings, delegate: self)
    self.captureSession?.stopRunning()
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接