KMeans improvement

- fixed returned compactness value
- added centers drawing to the example app
- added compactness test
This commit is contained in:
Maksim Shabunin
2017-01-31 12:05:08 +03:00
parent 74defefd61
commit b417b4dbee
3 changed files with 68 additions and 28 deletions
+7 -1
View File
@@ -53,7 +53,7 @@ int main( int /*argc*/, char** /*argv*/ )
randShuffle(points, 1, &rng);
kmeans(points, clusterCount, labels,
double compactness = kmeans(points, clusterCount, labels,
TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 10, 1.0),
3, KMEANS_PP_CENTERS, centers);
@@ -65,6 +65,12 @@ int main( int /*argc*/, char** /*argv*/ )
Point ipt = points.at<Point2f>(i);
circle( img, ipt, 2, colorTab[clusterIdx], FILLED, LINE_AA );
}
for (i = 0; i < centers.rows; ++i)
{
Point2f c = centers.at<Point2f>(i);
circle( img, c, 40, colorTab[i], 1, LINE_AA );
}
cout << "Compactness: " << compactness << endl;
imshow("clusters", img);