diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 517ee9dac..4b2d91e1d 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.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(); diff --git a/samples/cpp/kmeans.cpp b/samples/cpp/kmeans.cpp index 19e998379..d475cf175 100644 --- a/samples/cpp/kmeans.cpp +++ b/samples/cpp/kmeans.cpp @@ -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;