gpt4 book ai didi

ios - 现在如何使用 CMSampleBufferGetImageBuffer 在 Swift 中正确获取 ImageBuffer?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:53:11 28 4
gpt4 key购买 nike

enter image description here

'CMSampleBufferGetImageBuffer' has been replaced by property 'CMSampleBuffer.imageBuffer'

CMSampleBufferGet.ImageBuffer 不起作用 :) 似乎参数也与 Swift 4.2 有关。

guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }

整个函数。以防万一……

    func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
// print("Camera was able to capture a frame:", Date())

guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
guard let model = try? VNCoreMLModel(for: ARS().model) else { return }
let request = VNCoreMLRequest(model: model) { (finishedReq, err) in

guard let results = finishedReq.results as? [VNClassificationObservation] else { return }
guard let firstObservation = results.first else { return }

print(firstObservation.identifier, firstObservation.confidence)

DispatchQueue.main.async {
self.identifierLabel.text = "\(firstObservation.identifier) \(firstObservation.confidence * 100)"
}

}

try? VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:]).perform([request])
}

有没有人尝试解决这个问题或有新语法的引用?

最佳答案

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {

connection.videoOrientation = AVCaptureVideoOrientation.portrait
let imageBuffer: CVPixelBuffer = sampleBuffer.imageBuffer!
let ciimage : CIImage = CIImage(cvPixelBuffer: imageBuffer)
let image : UIImage = self.convert(cmage: ciimage)

}


// Convert CIImage to CGImage
func convert(cmage:CIImage) -> UIImage {
let context:CIContext = CIContext.init(options: nil)
let cgImage:CGImage = context.createCGImage(cmage, from: cmage.extent)!
let image:UIImage = UIImage.init(cgImage: cgImage)
return image
}

关于ios - 现在如何使用 CMSampleBufferGetImageBuffer 在 Swift 中正确获取 ImageBuffer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51109086/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com