title: How do I convert from a CVPixelBufferRef to an openCV cv::Mat
body: <p>I would like to perform a few operations to a <code>CVPixelBufferRef</code> and come out with a <code>cv::Mat</code></p>
  
  <ul>
  <li>crop to a region of interest</li>
  <li>scaled to a fixed dimension</li>
  <li>equalised the histogram</li>
  <li>convert to greyscale - 8 bits per pixel (<code>CV_8UC1</code>)</li>
  </ul>
  
  <p>I am not sure what the most efficient order is to do this, however, I do know that all of the operations are available on an open:CV matrix, so I would like to know how to convert it.</p>
  
  <pre><code>- (void) captureOutput:(AVCaptureOutput *)captureOutput 
           didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
           fromConnection:(AVCaptureConnection *)connection
  {
       CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
  
       cv::Mat frame = f(pixelBuffer); // how do I implement f()?
  </code></pre>