title: opencv .at handle different image types
body: <p>I have some code that I want to be able to handle both 8-bit and 16-bit images.</p>
  
  <p>the only difference between the code right now is that the 8-bit code uses:</p>
  
  <pre><code>filename.at&lt;uchar&gt;(i, j)
  </code></pre>
  
  <p>and the  16-bit code uses:</p>
  
  <pre><code>filename.at&lt;ushort&gt;(i, j)
  </code></pre>
  
  <p>Now the easiest way is to just include an if statement at the top that checks the image type and then I just have two blocks of code that do the same thing, but I would like to aoid this since maintenance becomes kind of a pain.</p>
  
  <p>First, I read through the OpenCV documentation and I may have missed it, but I did not see anything that returns the data type the Mat object uses to store pixel data. So if I missed it I will feel silly, but that would be best.</p>
  
  <p>The other option I looked into was a function pointer, but I am unsure if I can do this for the .at template function.</p>
  
  <p>Any advice on any of these options is greatly appreciated.</p>