fix cv::kmeans function

reshape input matrix, since the function works with data
as with [N x dims] matrix
This commit is contained in:
Vladislav Vinogradov 2014-05-13 17:59:20 +04:00
parent 09674623cf
commit 55a714c83b
2 changed files with 3 additions and 1 deletions

View File

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

View File

@ -33,7 +33,7 @@ int main( int /*argc*/, char** /*argv*/ )
{ {
int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1); int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1);
int i, sampleCount = rng.uniform(1, 1001); 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); clusterCount = MIN(clusterCount, sampleCount);
Mat centers; Mat centers;