title: OpenCV: get image data as array
body: <p>I am beginning to learn OpenCV and am having a bit of trouble with some basic operations. So, I can read a video file as follows:</p>
  
  <pre><code>cv::VideoCapture cap("media.avi");
  cv::Mat imgNew;
  while (cap.read(imgNew)) {
  }
  </code></pre>
  
  <p>Now, I have another function that has the following signature:</p>
  
  <pre><code>template&lt;class T&gt; 
  bool get_estimate(const T * image_data, int num_pixels)
  </code></pre>
  
  <p>Now, this takes the image data as this linear array of type <code>const T</code> where <code>T</code> in this case could be <code>unsigned char</code> and the <code>num_pixels</code> is the number of pixels in the image.</p>
  
  <p>Can someone tell me how I can use this <code>cv::Mat</code> type with this method. I am hoping there is some easy way to get the underlying array and its type without copying the data into a temporary array but I am not sure. I can always assume that the video image being read is always converted to grayscale.</p>