title: OpenCV Visual-C++ cvSplit Problem
body: <p>I tried several methods to open an image and split the channels. I just want 3 Matrix to work with. I don't know whats wrong. 
  Here my code:</p>
  
  <pre><code>    IplImage* img = cvLoadImage( "C:\\foo.jpg" ); 
  cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE ); 
  cvShowImage( "Example1", img );
  std::cout &lt;&lt; "Hight: " &lt;&lt; img-&gt;height &lt;&lt; " Width: " &lt;&lt; img-&gt;width;
  
  CvMat* imgR= cvCreateMat(img-&gt;width,img-&gt;height,CV_8UC1);
  CvMat* imgG= cvCreateMat(img-&gt;width,img-&gt;height,CV_8UC1);
  CvMat* imgB= cvCreateMat(img-&gt;width,img-&gt;height,CV_8UC1);
  
  cvSplit(&amp;img, imgB, imgG, imgR, NULL);
  
  cvWaitKey(0);
  cvReleaseImage( &amp;img );
  cvDestroyWindow( "Example1" );
  return 0;
  </code></pre>
  
  <p>The problem is the line <code>cvSplit(&amp;img, imgB, imgG, imgR, NULL);</code>. The program always crash and I don't know why. </p>
  
  <p>Edit1: Exception: </p>
  
  <blockquote>
    <p>error -(206) Unrecognized or unsupported array type</p>
  </blockquote>
  
  <p>Edit2: If i use <code>img</code> instead of <code>&amp;img</code> I get this exception:</p>
  
  <pre><code>An error occurred.
  ..\..\..\..\ocv\opencv\src\cxcore\cxconvert.cpp:877: error: (-215) dvec[j].size(
  ) == src.size() &amp;&amp; dvec[j].depth() == src.depth() &amp;&amp; dvec[j].channels() == 1 &amp;&amp;
  i &lt; src.channels()
  </code></pre>
  
  <p><strong>Solution</strong>:
  I was a not aware of the differnce between cv::Mat, cvMat and IplImage.
  This is the solution:</p>
  
  <pre><code>    IplImage *r = cvCreateImage(cvGetSize(img), img-&gt;depth, 1);
      IplImage *g = cvCreateImage(cvGetSize(img), img-&gt;depth, 1);
      IplImage *b = cvCreateImage(cvGetSize(img), img-&gt;depth, 1);
  
      cvSplit(img, b, g, r, NULL);
  </code></pre>