title: openCV k-means call assertion failed
body: <p>I'm have read c++ sample from samples folder of openCV source distribution, and, if omit random picture generation, kmeans call looks pretty simple – author even doesn't allocate centers/labels arrays (you can find it <a href="https://github.com/Itseez/opencv/blob/master/samples/cpp/kmeans.cpp" rel="nofollow">here</a>). However, I can't do the same in C. If I don't allocate labels, I get assertion error:</p>
  
  <blockquote>
    <p>OpenCV Error: Assertion failed (labels.isContinuous() &amp;&amp; labels.type()
    == CV_32S &amp;&amp; (labels.cols == 1 || labels.rows == 1) &amp;&amp; labels.cols + labels.rows - 1 == data.rows) in cvKMeans2, file
    /tmp/opencv-xiht/opencv-2.4.9/modules/core/src/matrix.cpp, line 3094</p>
  </blockquote>
  
  <p>Ok, I tried to create empty <code>labels</code> matrix, but assertion message don't changes at all.</p>
  
  <pre><code>IplImage* image = cvLoadImage("test.jpg", -1);
  IplImage* normal = cvCreateImage(cvGetSize(image), IPL_DEPTH_32F, image-&gt;nChannels);
  cvConvertScale(image, normal, 1/255.0, 0);
  CvMat* points = cvCreateMat(image-&gt;width, image-&gt;height, CV_32F);
  points-&gt;data.fl = normal-&gt;imageData;
  
  CvMat* labels = cvCreateMat(1, points-&gt;cols, CV_32S);
  CvMat* centers = NULL;
  
  CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 10, 1.0);
  
  // KMEANS_PP_CENTERS is undefined
  int KMEANS_PP_CENTERS = 2;
  cvKMeans2(points, 4, labels, criteria, 3, NULL, KMEANS_PP_CENTERS, centers, 0);
  </code></pre>
  
  <p>The thing that drives me nuts:</p>
  
  <pre><code>CvMat* labels = cvCreateMat(1, points-&gt;cols, CV_32S);
  int good = labels-&gt;type == CV_32S; // FALSE here
  </code></pre>
  
  <p>It's obviously one (not sure if the only) issue that causes assertion fail. How this supposed to work? I can't use С++ API since whole application is in plain C.</p>