#include <iostream>
using namespace std;
int main( int , char** )
{
const int MAX_CLUSTERS = 5;
{
};
RNG rng(12345);
for(;;)
{
int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1);
int i, sampleCount = rng.uniform(1, 1001);
Mat points(sampleCount, 1,
CV_32FC2), labels;
clusterCount =
MIN(clusterCount, sampleCount);
std::vector<Point2f> centers;
for( k = 0; k < clusterCount; k++ )
{
center.
x = rng.uniform(0, img.cols);
center.y = rng.uniform(0, img.rows);
Mat pointChunk = points.rowRange(k*sampleCount/clusterCount,
k == clusterCount - 1 ? sampleCount :
(k+1)*sampleCount/clusterCount);
}
double compactness =
kmeans(points, clusterCount, labels,
for( i = 0; i < sampleCount; i++ )
{
int clusterIdx = labels.at<int>(i);
}
for (i = 0; i < (int)centers.size(); ++i)
{
}
cout << "Compactness: " << compactness << endl;
if( key == 27 || key == 'q' || key == 'Q' )
break;
}
return 0;
}
_Tp x
x coordinate of the point
Definition: types.hpp:196
@ NORMAL
Definition: core.hpp:2786
static Scalar_< double > all(double v0)
returns a scalar with all elements set to v0
@ EPS
the desired accuracy or change in parameters at which the iterative algorithm stops
Definition: types.hpp:884
@ COUNT
the maximum number of iterations or elements to compute
Definition: types.hpp:882
void randShuffle(InputOutputArray dst, double iterFactor=1., RNG *rng=0)
Shuffles the array elements randomly.
Point2i Point
Definition: types.hpp:204
Scalar_< double > Scalar
Definition: types.hpp:691
Point_< float > Point2f
Definition: types.hpp:202
double kmeans(InputArray data, int K, InputOutputArray bestLabels, TermCriteria criteria, int attempts, int flags, OutputArray centers=noArray())
Finds centers of clusters and groups input samples around the clusters.
@ KMEANS_PP_CENTERS
Definition: core.hpp:217
#define CV_32FC2
Definition: interface.h:119
#define CV_8UC3
Definition: interface.h:90
#define MIN(a, b)
Definition: cvdef.h:489
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void circle(InputOutputArray img, Point center, int radius, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a circle.
@ LINE_AA
antialiased line
Definition: imgproc.hpp:816
@ FILLED
Definition: imgproc.hpp:813
"black box" representation of the file storage associated with a file on disk.
Definition: affine.hpp:52