15 (
"Random", cv::KMEANS_RANDOM_CENTERS)
16 (
"PP", cv::KMEANS_PP_CENTERS);
26 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
29 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=3);
32 vector<MxArray> rhs(prhs, prhs+nrhs);
36 TermCriteria criteria;
38 int flags = cv::KMEANS_RANDOM_CENTERS;
39 for (
int i=2; i<nrhs; i+=2) {
40 string key(rhs[i].toString());
41 if (key==
"InitialLabels") {
42 bestLabels = rhs[i+1].toMat(CV_32S);
43 flags |= cv::KMEANS_USE_INITIAL_LABELS;
45 else if (key==
"Criteria")
46 criteria = rhs[i+1].toTermCriteria();
47 else if (key==
"Attempts")
48 attempts = rhs[i+1].toInt();
49 else if (key==
"Initialization")
50 flags = Initialization[rhs[i+1].toString()];
52 mexErrMsgIdAndTxt(
"mexopencv:error",
53 "Unrecognized option %s", key.c_str());
57 Mat data(rhs[0].toMat(CV_32F)), centers;
58 int K = rhs[1].toInt();
59 double compactness = kmeans(data, K, bestLabels, criteria, attempts,
60 flags, (nlhs>1 ? centers : noArray()));
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.