19 map<int,Ptr<SimpleBlobDetector> > obj_;
29 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
35 vector<MxArray> rhs(prhs, prhs+nrhs);
36 int id = rhs[0].toInt();
37 string method(rhs[1].toString());
40 if (method ==
"new") {
43 rhs.begin() + 2, rhs.end());
49 Ptr<SimpleBlobDetector> obj = obj_[id];
50 if (method ==
"delete") {
54 else if (method ==
"typeid") {
56 plhs[0] =
MxArray(
string(
typeid(*obj).name()));
58 else if (method ==
"clear") {
62 else if (method ==
"load") {
63 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
65 bool loadFromString =
false;
66 for (
int i=3; i<nrhs; i+=2) {
67 string key(rhs[i].toString());
69 objname = rhs[i+1].toString();
70 else if (key ==
"FromString")
71 loadFromString = rhs[i+1].toBool();
73 mexErrMsgIdAndTxt(
"mexopencv:error",
74 "Unrecognized option %s", key.c_str());
76 obj_[id] = (loadFromString ?
77 Algorithm::loadFromString<SimpleBlobDetector>(rhs[2].toString(), objname) :
78 Algorithm::load<SimpleBlobDetector>(rhs[2].toString(), objname));
80 else if (method ==
"save") {
82 obj->save(rhs[2].toString());
84 else if (method ==
"empty") {
86 plhs[0] =
MxArray(obj->empty());
88 else if (method ==
"getDefaultName") {
90 plhs[0] =
MxArray(obj->getDefaultName());
92 else if (method ==
"detect") {
93 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
94 if (rhs[2].isNumeric()) {
96 for (
int i=3; i<nrhs; i+=2) {
97 string key(rhs[i].toString());
99 mask = rhs[i+1].toMat(CV_8U);
101 mexErrMsgIdAndTxt(
"mexopencv:error",
102 "Unrecognized option %s", key.c_str());
104 Mat image(rhs[2].toMat(CV_8U));
105 vector<KeyPoint> keypoints;
106 obj->detect(image, keypoints, mask);
109 else if (rhs[2].isCell()) {
111 for (
int i=3; i<nrhs; i+=2) {
112 string key(rhs[i].toString());
115 vector<MxArray> arr(rhs[i+1].toVector<MxArray>());
117 masks.reserve(arr.size());
118 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
119 masks.push_back(it->toMat(CV_8U));
122 mexErrMsgIdAndTxt(
"mexopencv:error",
123 "Unrecognized option %s", key.c_str());
128 vector<MxArray> arr(rhs[2].toVector<MxArray>());
129 images.reserve(arr.size());
130 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
131 images.push_back(it->toMat(CV_8U));
133 vector<vector<KeyPoint> > keypoints;
134 obj->detect(images, keypoints, masks);
138 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
146 mexErrMsgIdAndTxt(
"mexopencv:error",
147 "Unrecognized operation %s",method.c_str());
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.
Common definitions for the features2d and xfeatures2d modules.
Global constant definitions.
cv::Ptr< cv::SimpleBlobDetector > createSimpleBlobDetector(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of SimpleBlobDetector using options in arguments.