16 map<int,Ptr<BOWKMeansTrainer> > obj_;
20 (
"Random", cv::KMEANS_RANDOM_CENTERS)
21 (
"PP", cv::KMEANS_PP_CENTERS);
31 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
37 vector<MxArray> rhs(prhs, prhs+nrhs);
38 int id = rhs[0].toInt();
39 string method(rhs[1].toString());
42 if (method ==
"new") {
43 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
44 int clusterCount = rhs[2].toInt();
45 TermCriteria criteria;
47 int flags = cv::KMEANS_PP_CENTERS;
48 for (
int i=3; i<nrhs; i+=2) {
49 string key(rhs[i].toString());
50 if (key ==
"Criteria")
51 criteria = rhs[i+1].toTermCriteria();
52 else if (key ==
"Attempts")
53 attempts = rhs[i+1].toInt();
54 else if (key ==
"Initialization")
55 flags = KmeansInitMap[rhs[i+1].toString()];
57 mexErrMsgIdAndTxt(
"mexopencv:error",
58 "Unknown option %s",key.c_str());
60 obj_[++last_id] = makePtr<BOWKMeansTrainer>(
61 clusterCount, criteria, attempts, flags);
67 Ptr<BOWKMeansTrainer> obj = obj_[id];
68 if (method ==
"delete") {
72 else if (method ==
"clear") {
76 else if (method ==
"getDescriptors") {
78 vector<Mat> descs(obj->getDescriptors());
81 else if (method ==
"descriptorsCount") {
83 int count = obj->descriptorsCount();
86 else if (method ==
"add") {
88 obj->add(rhs[2].toMat(CV_32F));
90 else if (method ==
"cluster") {
91 nargchk((nrhs==2 || nrhs==3) && nlhs<=1);
94 vocabulary = obj->cluster();
96 vocabulary = obj->cluster(rhs[2].toMat(CV_32F));
100 mexErrMsgIdAndTxt(
"mexopencv:error",
101 "Unrecognized operation %s", method.c_str());
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.