在我的应用程序中,我将 VNImageRequestHandler 与自定义 MLModel 一起用于对象检测。
该应用程序适用于 14.5 之前的 iOS 版本。
当 iOS 14.5 到来时,它打破了一切。
try handler.perform([visionRequest])抛出错误时(Error Domain=com.apple.vis Code=11 "encountered unknown exception" UserInfo={NSLocalizedDescription=encountered unknown exception}),pixelBuffer内存被保留并且永远不会释放,它使 AVCaptureOutput 的缓冲区满然后新帧没来。由于内存泄漏,应用程序在一段时间后崩溃。
请注意,在 iOS 14.5 版本之前,检测工作完美,try handler.perform([visionRequest])永远不会抛出任何错误。
这是我的代码:
private func predictWithPixelBuffer(sampleBuffer: CMSampleBuffer) {
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
return
}
// Get additional info from the camera.
var options: [VNImageOption : Any] = [:]
if let cameraIntrinsicMatrix = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil) {
options[.cameraIntrinsics] = cameraIntrinsicMatrix
} …Run Code Online (Sandbox Code Playgroud)