3

在此处输入图像描述

'CMSampleBufferGetImageBuffer' 已被属性 '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])
    }

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

4

1 回答 1

4
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
}
于 2018-07-13T09:56:02.243 回答