Merge pull request #11101 from lamantine:fix_11100

* fixed bug #11100 Integer overflow in kmeans

* fixed integer overflow in other divUp-s in kmeans code
fixed warning about size_t to double conversion
This commit is contained in:
Aleksandr Tischenko 2018-03-18 14:11:42 +02:00 committed by Alexander Alekhin
parent 2dac35a97d
commit 22ecdd16ef

View File

@ -128,7 +128,7 @@ static void generateCentersPP(const Mat& data, Mat& _out_centers,
parallel_for_(Range(0, N),
KMeansPPDistanceComputer(tdist2, data, dist, ci),
divUp(dims * N, CV_KMEANS_PARALLEL_GRANULARITY));
(double)divUp((size_t)(dims * N), CV_KMEANS_PARALLEL_GRANULARITY));
double s = 0;
for (int i = 0; i < N; i++)
{
@ -429,14 +429,14 @@ double cv::kmeans( InputArray _data, int K,
if (isLastIter)
{
// don't re-assign labels to avoid creation of empty clusters
parallel_for_(Range(0, N), KMeansDistanceComputer<true>(dists, labels, data, centers), divUp(dims * N, CV_KMEANS_PARALLEL_GRANULARITY));
parallel_for_(Range(0, N), KMeansDistanceComputer<true>(dists, labels, data, centers), (double)divUp((size_t)(dims * N), CV_KMEANS_PARALLEL_GRANULARITY));
compactness = sum(Mat(Size(N, 1), CV_64F, &dists[0]))[0];
break;
}
else
{
// assign labels
parallel_for_(Range(0, N), KMeansDistanceComputer<false>(dists, labels, data, centers), divUp(dims * N * K, CV_KMEANS_PARALLEL_GRANULARITY));
parallel_for_(Range(0, N), KMeansDistanceComputer<false>(dists, labels, data, centers), (double)divUp((size_t)(dims * N * K), CV_KMEANS_PARALLEL_GRANULARITY));
}
}