大佬教程收集整理的这篇文章主要介绍了ios – 在Swift中,改编了AVCaptureVideoDataOutputSampleBufferDelegate,但是captureOutput永远不会被调用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码:
import UIKit import AVFoundation class ViewController: UIViewController,AVCaptureVideoDataOutputSampleBufferDelegate { @IBOutlet weak var imageView: UIImageView! @IBOutlet var cameraView: UIView! var selectedImage :UIImage! let captureSession = AVCaptureSession() var captureDevice : AVCaptureDevice? var videoCaptureOutput : AVCaptureVideoDataOutput! override func viewDidLoad() { super.viewDidLoad() captureSession.sessionPreset = AVCaptureSessionPresetLow self.captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) if(captureDevice != nil){ beginSession() } } func beginSession() { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0),{ self.videoCaptureOutput = AVCaptureVideoDataOutput() self.videoCaptureOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey:kCVPixelFormatType_32BGRA] self.videoCaptureOutput.alwaysDiscardsLateVideoFrames = true self.captureSession.addOutput(self.videoCaptureOutput) var err : NSError? = nil self.captureSession.addInput(AVCaptureDeviceInput(device: self.captureDevice,error: &err)) self.captureSession.sessionPreset = AVCaptureSessionPresetPhoto if err != nil { println("error: \(err?.localizedDescription)") } var previewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession) previewLayer?.frame = self.cameraView.layer.bounds previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill dispatch_async(dispatch_get_main_queue(),{ // 2 // 3 self.cameraView.layer.addSublayer(previewLayer) self.captureSession.startRunning() }); }); } func captureOutput(captureOutput: AVCaptureOutput!,didOutputSampleBuffer sampleBuffer: CMSampleBuffer!,fromConnection connection: AVCaptureConnection!) { println("capture delegation called") var imageProcessor = ImageProcessor() imageView.image = imageProcessor.imageFromSampleBuffer(sampleBuffer) } }
正如您所看到的,我正在尝试处理图像并在imageview上显示实时捕获帧,假设我的ImageProcessor()工作正常….
任何帮助将不胜感激,谢谢.
以上是大佬教程为你收集整理的ios – 在Swift中,改编了AVCaptureVideoDataOutputSampleBufferDelegate,但是captureOutput永远不会被调用全部内容,希望文章能够帮你解决ios – 在Swift中,改编了AVCaptureVideoDataOutputSampleBufferDelegate,但是captureOutput永远不会被调用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。