我目前正在尝试为我的应用实施相机实时供稿。我已经设置好了,但不知怎么了。据我了解,captureOutput
应该在每次识别到帧时执行,并且打印消息应该在控制台中输出,但是不知何故-控制台不会显示print命令。
有人在代码内部看到任何可能的错误吗?
我不知道这是否与我的问题有关,但是在应用程序启动时,控制台显示以下内容:
[BoringSSL] nw_protocol_boringssl_get_output_frames(1301)[C1.1:2] [0x106b24530]获取输出帧失败,状态8196
import UIKit
import AVKit
import Vision
class CameraViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let captureSession = AVCaptureSession()
guard let captureDevice = AVCaptureDevice.default(for: .video) else { return }
guard let input = try? AVCaptureDeviceInput(device: captureDevice) else{ return }
captureSession.addInput(input)
captureSession.startRunning()
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
view.layer.addSublayer(previewLayer)
previewLayer.frame = view.frame
let dataOutput = AVCaptureVideoDataOutput()
dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
captureSession.addOutput(dataOutput)
// let request = VNCoreMLRequest
// VNImageRequestHandler(cgImage: <#T##CGImage#>, options: [:]).perform(request)
}
func captureOutput(_ output: AVCaptureOutput, didDrop sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
print("Es hat funktioniert")
}
}
答案 0 :(得分:0)
您需要实现captureOutput(_:didOutput:from:)
而不是captureOutput(_:didDrop:from:)
func captureOutput(_ output: AVCaptureOutput,
didOutput sampleBuffer: CMSampleBuffer,
from connection: AVCaptureConnection) {
print("Es hat funktioniert")
}