title: How to determine the data type of a CvMat
body: <p>When using the <code>CvMat</code> type, the type of data is crucial to keeping your program running.</p>
  
  <p>For example, depending on whether your data is type <code>float</code> or <code>unsigned char</code>, you would choose one of these two commands:</p>
  
  <pre><code>cvmGet(mat, row, col);
  cvGetReal2D(mat, row, col);
  </code></pre>
  
  <p>Is there a universal approach to this?  If the wrong data type matrix is passed to these calls, they crash at runtime.  This is becoming an issue, since a function I have defined is getting passed several different types of matrices.</p>
  
  <p>How do you determine the data type of a matrix so you can always access its data?</p>
  
  <p>I tried using the "type()" function as such.</p>
  
  <pre><code>CvMat* tmp_ptr = cvCreateMat(t_height,t_width,CV_8U);
  std::cout &lt;&lt; "type = " &lt;&lt; tmp_ptr-&gt;type() &lt;&lt; std::endl;
  </code></pre>
  
  <p>This does not compile, saying <code>"term does not evaluate to a function taking 0 arguments"</code>.  If I remove the brackets after the word <code>type</code>, I get a type of 1111638032</p>
  
  <p><em>EDIT</em> minimal application that reproduces this...</p>
  
  <pre><code>int main( int argc, char** argv )
  {
      CvMat *tmp2 = cvCreateMat(10,10, CV_32FC1);
      std::cout &lt;&lt; "tmp2 type = " &lt;&lt; tmp2-&gt;type &lt;&lt; " and CV_32FC1 = " &lt;&lt; CV_32FC1 &lt;&lt; " and " &lt;&lt; (tmp2-&gt;type == CV_32FC1) &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Output: <code>tmp2 type = 1111638021 and CV_32FC1 = 5 and 0</code></p>