diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 4b2d91e1d..8e32b0fbe 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2691,17 +2691,17 @@ double cv::kmeans( InputArray _data, int K, int flags, OutputArray _centers ) { const int SPP_TRIALS = 3; - Mat data = _data.getMat(); - bool isrow = data.rows == 1 && data.channels() > 1; - int N = !isrow ? data.rows : data.cols; - int dims = (!isrow ? data.cols : 1)*data.channels(); - int type = data.depth(); + 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(); + int type = data0.depth(); attempts = std::max(attempts, 1); - CV_Assert( data.dims <= 2 && type == CV_32F && K > 0 ); + CV_Assert( data0.dims <= 2 && type == CV_32F && K > 0 ); CV_Assert( N >= K ); - data = data.reshape(1, N); + Mat data(N, dims, CV_32F, data0.data, isrow ? dims * sizeof(float) : static_cast(data0.step)); _bestLabels.create(N, 1, CV_32S, -1, true);