CVPixelBufferを取得する場合はCVPixelBufferLockBaseAddress
でロックを確保してpixelBufferにアクセス、終わったらCVPixelBufferUnlockBaseAddress
でアンロックする
Detecting Human Body Poses in an Image より
// Attempt to lock the image buffer to gain access to its memory.
guard CVPixelBufferLockBaseAddress(pixelBuffer, .readOnly) == kCVReturnSuccess
else {
return
}
// Create Core Graphics image placeholder.
var image: CGImage?
// Create a Core Graphics bitmap image from the pixel buffer.
VTCreateCGImageFromCVPixelBuffer(pixelBuffer, options: nil, imageOut: &image)
// Release the image buffer.
CVPixelBufferUnlockBaseAddress(pixelBuffer, .readOnly)
DispatchQueue.main.sync {
delegate.videoCapture(self, didCaptureFrame: image)
}
captureOutput(_:didOutput:from:) | Apple Developer Documentation