|
|
|
@ -276,7 +276,7 @@ public: |
|
|
|
|
public: |
|
|
|
|
KMeansDistanceComputer(Distance _distance, const Matrix<ElementType>& _dataset, |
|
|
|
|
const int _branching, const int* _indices, const Matrix<double>& _dcenters, const size_t _veclen, |
|
|
|
|
int* _count, int* _belongs_to, std::vector<DistanceType>& _radiuses, bool& _converged, cv::Mutex& _mtx) |
|
|
|
|
int* _count, int* _belongs_to, std::vector<DistanceType>& _radiuses, bool& _converged) |
|
|
|
|
: distance(_distance) |
|
|
|
|
, dataset(_dataset) |
|
|
|
|
, branching(_branching) |
|
|
|
@ -287,7 +287,6 @@ public: |
|
|
|
|
, belongs_to(_belongs_to) |
|
|
|
|
, radiuses(_radiuses) |
|
|
|
|
, converged(_converged) |
|
|
|
|
, mtx(_mtx) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -311,12 +310,10 @@ public: |
|
|
|
|
radiuses[new_centroid] = sq_dist; |
|
|
|
|
} |
|
|
|
|
if (new_centroid != belongs_to[i]) { |
|
|
|
|
count[belongs_to[i]]--; |
|
|
|
|
count[new_centroid]++; |
|
|
|
|
CV_XADD(&count[belongs_to[i]], -1); |
|
|
|
|
CV_XADD(&count[new_centroid], 1); |
|
|
|
|
belongs_to[i] = new_centroid; |
|
|
|
|
mtx.lock(); |
|
|
|
|
converged = false; |
|
|
|
|
mtx.unlock(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -332,7 +329,6 @@ public: |
|
|
|
|
int* belongs_to; |
|
|
|
|
std::vector<DistanceType>& radiuses; |
|
|
|
|
bool& converged; |
|
|
|
|
cv::Mutex& mtx; |
|
|
|
|
KMeansDistanceComputer& operator=( const KMeansDistanceComputer & ) { return *this; } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -801,8 +797,7 @@ private: |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// reassign points to clusters
|
|
|
|
|
cv::Mutex mtx; |
|
|
|
|
KMeansDistanceComputer invoker(distance_, dataset_, branching, indices, dcenters, veclen_, count, belongs_to, radiuses, converged, mtx); |
|
|
|
|
KMeansDistanceComputer invoker(distance_, dataset_, branching, indices, dcenters, veclen_, count, belongs_to, radiuses, converged); |
|
|
|
|
parallel_for_(cv::Range(0, (int)indices_length), invoker); |
|
|
|
|
|
|
|
|
|
for (int i=0; i<branching; ++i) { |
|
|
|
|