title: Real time face detection/tracking with CIDetector
body: <p>I have made a face detection app that is "functional". However, the problem is that <code>.featuresInImage()</code> in <code>CIdetector</code> is not detecting faces every time <code>func captureOutput()</code> is called. I have already tried setting <code>CIDetectorAccuracyLow</code> too which didn't improve anything significantly.</p>
  
  <p>I have tried both my application and the native iPhone camera which the latter can detect faces in an instance, even with faces that are slightly blocked (e.g. glasses). Why is this? Is Apple using a different face detecting algorithm from this one? Or is there some optimizing I should do before sending to <code>CIDetector</code>?</p>
  
  <p>Code as below for further reference:</p>
  
  <pre><code>private var faceDetector: CIDetector?
  dynamic var faceFeature: CGRect
  
  ...
  
  func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
      // This function is called whenever a new frame is available
      let pixelBuffer: CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)!
      let inputImage = CIImage(CVPixelBuffer: pixelBuffer)
      let features = self.faceDetector!.featuresInImage(inputImage)
  
      for feature in features as! [CIFaceFeature] {
          faceFeature = feature.bounds
          print("\(faceFeature)")
      }
  }
  </code></pre>
  
  <p>.</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have further tested my "functional" code, and it seems that there are certain times when my face is at a certain angle and size, <code>.featuresInImage()</code> will detect my face with the video frame rate.</p>
  
  <p>Does this mean the CIDetector is working correctly but I'll have to do some adjustments to the input sample? Make it more easy for the algorithm to run?</p>