title: How/Why is imagedata stored as char - OpenCV
body: <p>I'm a tad confused.</p>
  
  <p>I am just getting started with OpenCV and its image data is pointed to by a char pointer.  I can't quite work out how that works considering the actual data itself could be any number of data types, e.g. uint, float, double.  As far as I knew, a pointer had to be of the same type as the pointer it represents.</p>
  
  <p>It's probably worth noting that openCV is a C library and my background is C++, so I am unaware of how these problems of needing variable types are solved in C.</p>
  
  <p>For example the follwing code taken from Learning OpenCV illustrates my confusion:</p>
  
  <pre><code>void saturate_sv( IplImage* img ) {
      for( int y=0; y&lt;img-&gt;height; y++ ) {
      uchar* ptr = (uchar*) (
      img-&gt;imageData + y * img-&gt;widthStep
      );
         for( int x=0; x&lt;img-&gt;width; x++ ) {
             ptr[3*x+1] = 255;
             ptr[3*x+2] = 255;
         }
      }
  }
  </code></pre>
  
  <p>So this works, but when I try to operate on a iplImage of type IPL_DEPTH_64F and use ptr[3*x+1] = 1 The results are incorrect.  So to distil my problems: how can I work on integer or floating point data through char pointers and specifically how could I rectify the above example to work with a double precision data.</p>
  
  <p>Thanks</p>