From 14c0bfce2f3830999ef2ea4775089417db662042 Mon Sep 17 00:00:00 2001 From: Philipp Hasper Date: Fri, 21 Aug 2015 14:20:00 +0200 Subject: [PATCH] kmeans and one-dimensional vectors Clustering one-dimensional data was only possible when storing it column-based. But a std::vector is interpreted as matrix with height=1 Additionally, made conditionals more readable --- modules/core/src/kmeans.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/src/kmeans.cpp b/modules/core/src/kmeans.cpp index fe5a0cf6e9..a81334aa8f 100644 --- a/modules/core/src/kmeans.cpp +++ b/modules/core/src/kmeans.cpp @@ -221,9 +221,9 @@ double cv::kmeans( InputArray _data, int K, { const int SPP_TRIALS = 3; Mat data0 = _data.getMat(); - bool isrow = data0.rows == 1 && data0.channels() > 1; - int N = !isrow ? data0.rows : data0.cols; - int dims = (!isrow ? data0.cols : 1)*data0.channels(); + bool isrow = data0.rows == 1; + int N = isrow ? data0.cols : data0.rows; + int dims = (isrow ? 1 : data0.cols)*data0.channels(); int type = data0.depth(); attempts = std::max(attempts, 1);