Skip to content

Commit

Permalink
use more accurate reshape
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Vinogradov committed May 15, 2014
1 parent 55a714c commit f165037
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions modules/core/src/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(data0.step));

_bestLabels.create(N, 1, CV_32S, -1, true);

Expand Down

0 comments on commit f165037

Please sign in to comment.