2016-03-30 14 views
1

Bir iPhone'da kamerayı hızlı bir şekilde kullanarak bir ışık yoğunluğu okuyucusu oluşturmaya çalışıyorum. Buradaki fikir, tüm pikseller için yoğunluk bileşenini alır ve bana tek bir değer vermesi için onları ortalama eder. Kameranın ön izine ihtiyacım yok. Çalışmaya çalışmak için birkaç öğreticiyi bir araya getiriyorum ve şu ana kadar aşağıdaki kodla geldim. camDeviceSetup() ViewDidLoad üzerinde çalışır, cameraSetup() bir düğmeye basıldığında çalışır.Örnek Buffer Delegesi Swift 2 Gerçek Zamanlı Video Filtresi için

"videoDeviceOutput! .setSampleBufferDelegate" öğesini başlatan satırda bir hatayla karşılaşıyorum, bu, ilkViewController (görünüm denetleyicisi) değerini beklenen argümana dönüştüremediğini söylüyor. Bu çizginin üzerinde

let captureSession = AVCaptureSession() 
// If we find a device we'll store it here for later use 
var captureDevice : AVCaptureDevice? 
var videoDeviceOutput: AVCaptureVideoDataOutput? 
// AVCaptureVideoPreviewLayer is a subclass of CALayer that you use to display video as it is being captured by an input device. 
var previewLayer = AVCaptureVideoPreviewLayer() 

func camDeviceSetup() { 
    captureSession.sessionPreset = AVCaptureSessionPreset640x480 
    let devices = AVCaptureDevice.devices() 
    for device in devices { 
     // Make sure this particular device supports video 
     if (device.hasMediaType(AVMediaTypeVideo)) { 
      // Finally check the position and confirm we've got the back camera 
      if(device.position == AVCaptureDevicePosition.Back) { 
       captureDevice = device as? AVCaptureDevice 
      } 
     } 
    } 
    if captureDevice != nil { 
     let err : NSError? = nil 
     captureSession.addInput(try! AVCaptureDeviceInput(device: captureDevice)) 

     if err != nil { 
      print("error: \(err?.localizedDescription)") 
     } 

    } 
} 

func cameraSetup() { 
    previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) 
    previewLayer.frame = view.bounds 
    view.layer.addSublayer(previewLayer) 

    videoDeviceOutput = AVCaptureVideoDataOutput() 
    videoDeviceOutput!.videoSettings = [kCVPixelBufferPixelFormatTypeKey:Int(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)] 
    videoDeviceOutput!.alwaysDiscardsLateVideoFrames = true 

//This is the line that gets stuck and not sure why 
    videoDeviceOutput!.setSampleBufferDelegate(self, queue: dispatch_queue_create("VideoBuffer", DISPATCH_QUEUE_SERIAL)) 

    if captureSession.canAddOutput(videoDeviceOutput) { 
     captureSession.addOutput(videoDeviceOutput) 
    } 

    captureSession.startRunning() 
} 

func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) { 
    // Think once the delegate is correctly set my algorithm for finding light intensity goes here 

} 
+0

Bu satırdaki sorunlar, ViewController'ımın en üstündeki sınıfta AVCaptureVideoDataOutputSampleBufferDelegate bildirmeme neden oldu. – rmaspero

cevap

0

sorunlar benim ViewController üstündeki sınıfında AVCaptureVideoDataOutputSampleBufferDelegate ilan etmiyoruz aşağı oldu.

+0

, AVCaptureVideoDataOutputSampleBufferDelegate öğesini vc'ye atadı mı? –

İlgili konular