在 iPhone XS(使用 iOS 12.1.2 和 Xcode 10.1)上运行 ARKit 时,我在运行视觉代码以检测面部边界时遇到错误和崩溃/挂起。
我遇到的错误是:
2019-01-04 03:03:03.155867-0800 ARKit Vision Demo[12969:3307770] Execution of the command buffer was aborted due to an error during execution. Caused GPU Timeout Error (IOAF code 2)
2019-01-04 03:03:03.155786-0800 ARKit Vision Demo[12969:3307850] Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5)
[SceneKit] Error: display link thread seems stuck
这发生在 iPhone XS 上,同时运行以下概念验证代码以重现错误(总是在运行应用程序的几秒钟内发生)- https://github.com/xta/ARKit-Vision-Demo
相关的 ViewController.swift 包含有问题的方法:
func classifyCurrentImage() {
guard let buffer = currentBuffer else { return }
let image = CIImage(cvPixelBuffer: buffer)
let options: [VNImageOption: Any] = [:]
let imageRequestHandler = VNImageRequestHandler(ciImage: image, orientation: self.imageOrientation, options: options)
do {
try imageRequestHandler.perform(self.requests)
} catch {
print(error)
}
}
func handleFaces(request: VNRequest, error: Error?) {
DispatchQueue.main.async {
guard let results = request.results as? [VNFaceObservation] else { return }
// TODO - something here with results
print(results)
self.currentBuffer = nil
}
}
通过 VNDetectFaceRectanglesRequest
使用 Apple 的 ARKit + Vision 的正确方法是什么?获取神秘的 IOAF 代码错误是不正确的。
理想情况下,我还想使用 VNTrackObjectRequest 和 VNSequenceRequestHandler 来跟踪请求。
有关于将 VNDetectFaceRectanglesRequest 与 Vision(以及没有 ARKit)一起使用的不错的在线文档。 Apple 在这里有一个页面 ( https://developer.apple.com/documentation/arkit/using_vision_in_real_time_with_arkit ) 我已经关注了,但我仍然遇到错误/崩溃。
最佳答案
对于任何经历过痛苦的人,我只是试图为 VNDetectRectanglesRequest
修复这个确切的错误,这是我的解决方案:
似乎使用 CIImage:
let imageRequestHandler = VNImageRequestHandler(ciImage: image, orientation: self.imageOrientation, options: options)
导致 Metal 在我的内存图中保留了大量的内部函数。
我注意到 Apple 的示例项目都使用这个代替:
let handler: VNImageRequestHandler! = VNImageRequestHandler(cvPixelBuffer: pixelBuffer,
orientation: orientation,
options: requestHandlerOptions)
改用 cvPixelBuffer
而不是 CIImage
修复了我所有的随机 GPU 超时错误!
我使用这些函数来获取方向
(我使用的是后置摄像头。我认为您可能需要为前置摄像头镜像,具体取决于您要执行的操作):
func exifOrientationForDeviceOrientation(_ deviceOrientation: UIDeviceOrientation) -> CGImagePropertyOrientation {
switch deviceOrientation {
case .portraitUpsideDown:
return .right
case .landscapeLeft:
return .down
case .landscapeRight:
return .up
default:
return .left
}
}
func exifOrientationForCurrentDeviceOrientation() -> CGImagePropertyOrientation {
return exifOrientationForDeviceOrientation(UIDevice.current.orientation)
}
和以下作为选项
:
var requestHandlerOptions: [VNImageOption: AnyObject] = [:]
let cameraIntrinsicData = CMGetAttachment(pixelBuffer, key: kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, attachmentModeOut: nil)
if cameraIntrinsicData != nil {
requestHandlerOptions[VNImageOption.cameraIntrinsics] = cameraIntrinsicData
}
希望这可以挽救我失去的一周!
关于ios - 在 iPhone XS 上使用 ARKit2 和 Vision (VNDetectFaceRectanglesRequest) 时如何修复 IOAF 代码 GPU 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54037945/