#include <iostream>
int main( int , char** )
{
const int MAX_CLUSTERS = 5;
{
};
for(;;)
{
int k, clusterCount = rng.
uniform(2, MAX_CLUSTERS+1);
int i, sampleCount = rng.
uniform(1, 1001);
clusterCount =
MIN(clusterCount, sampleCount);
std::vector<Point2f> centers;
for( k = 0; k < clusterCount; k++ )
{
Mat pointChunk = points.
rowRange(k*sampleCount/clusterCount,
k == clusterCount - 1 ? sampleCount :
(k+1)*sampleCount/clusterCount);
}
double compactness =
kmeans(points, clusterCount, labels,
TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 10, 1.0),
img = Scalar::all(0);
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;
}
n-dimensional dense array class
Definition: mat.hpp:811
_Tp & at(int i0=0)
Returns a reference to the specified array element.
int cols
Definition: mat.hpp:2116
Mat rowRange(int startrow, int endrow) const
Creates a matrix header for the specified row span.
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition: mat.hpp:2116
_Tp y
y coordinate of the point
Definition: types.hpp:202
_Tp x
x coordinate of the point
Definition: types.hpp:201
Random Number Generator.
Definition: core.hpp:2833
int uniform(int a, int b)
returns uniformly distributed integer random number from [a,b) range
void fill(InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange=false)
Fills arrays with random numbers.
The class defining termination criteria for iterative algorithms.
Definition: types.hpp:880
void randShuffle(InputOutputArray dst, double iterFactor=1., RNG *rng=0)
Shuffles the array elements randomly.
Scalar_< double > Scalar
Definition: types.hpp:696
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:495
@ circle
Definition: gr_skig.hpp:62
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
@ LINE_AA
antialiased line
Definition: imgproc.hpp:865
@ FILLED
Definition: imgproc.hpp:862
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106