fix cv::kmeans function

reshape input matrix, since the function works with data
as with [N x dims] matrix
pull/2744/head
Vladislav Vinogradov 11 years ago
parent 09674623cf
commit 55a714c83b
  1. 2
      modules/core/src/matrix.cpp
  2. 2
      samples/cpp/kmeans.cpp

@ -2701,6 +2701,8 @@ double cv::kmeans( InputArray _data, int K,
CV_Assert( data.dims <= 2 && type == CV_32F && K > 0 );
CV_Assert( N >= K );
data = data.reshape(1, N);
_bestLabels.create(N, 1, CV_32S, -1, true);
Mat _labels, best_labels = _bestLabels.getMat();

@ -33,7 +33,7 @@ int main( int /*argc*/, char** /*argv*/ )
{
int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1);
int i, sampleCount = rng.uniform(1, 1001);
Mat points(sampleCount, 2, CV_32F), labels;
Mat points(sampleCount, 1, CV_32FC2), labels;
clusterCount = MIN(clusterCount, sampleCount);
Mat centers;

Loading…
Cancel
Save