mirror of
https://github.com/opencv/opencv.git
synced 2024-11-30 14:29:49 +08:00
fixed kmeans
This commit is contained in:
parent
7e06b18144
commit
74b38e978b
@ -2610,18 +2610,18 @@ double cv::kmeans( InputArray _data, int K,
|
|||||||
double max_dist = 0;
|
double max_dist = 0;
|
||||||
int farthest_i = -1;
|
int farthest_i = -1;
|
||||||
float* new_center = centers.ptr<float>(k);
|
float* new_center = centers.ptr<float>(k);
|
||||||
float* _old_center = centers.ptr<float>(max_k);
|
float* old_center = centers.ptr<float>(max_k);
|
||||||
float* old_center = temp.ptr<float>();
|
float* _old_center = temp.ptr<float>(); // normalized
|
||||||
float scale = 1.f/counters[max_k];
|
float scale = 1.f/counters[max_k];
|
||||||
for( j = 0; j < dims; j++ )
|
for( j = 0; j < dims; j++ )
|
||||||
old_center[j] = _old_center[j]*scale;
|
_old_center[j] = old_center[j]*scale;
|
||||||
|
|
||||||
for( i = 0; i < N; i++ )
|
for( i = 0; i < N; i++ )
|
||||||
{
|
{
|
||||||
if( labels[i] != max_k )
|
if( labels[i] != max_k )
|
||||||
continue;
|
continue;
|
||||||
sample = data.ptr<float>(i);
|
sample = data.ptr<float>(i);
|
||||||
double dist = normL2Sqr_(sample, old_center, dims);
|
double dist = normL2Sqr_(sample, _old_center, dims);
|
||||||
|
|
||||||
if( max_dist <= dist )
|
if( max_dist <= dist )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user