19 map<int,Ptr<AgastFeatureDetector> > 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<AgastFeatureDetector> 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<AgastFeatureDetector>(rhs[2].toString(), objname) :
78 Algorithm::load<AgastFeatureDetector>(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");
140 else if (method ==
"get") {
142 string prop(rhs[2].toString());
143 if (prop ==
"NonmaxSuppression")
144 plhs[0] =
MxArray(obj->getNonmaxSuppression());
145 else if (prop ==
"Threshold")
146 plhs[0] =
MxArray(obj->getThreshold());
147 else if (prop ==
"Type")
150 mexErrMsgIdAndTxt(
"mexopencv:error",
151 "Unrecognized property %s", prop.c_str());
153 else if (method ==
"set") {
155 string prop(rhs[2].toString());
156 if (prop ==
"NonmaxSuppression")
157 obj->setNonmaxSuppression(rhs[3].toBool());
158 else if (prop ==
"Threshold")
159 obj->setThreshold(rhs[3].toInt());
160 else if (prop ==
"Type")
163 mexErrMsgIdAndTxt(
"mexopencv:error",
164 "Unrecognized property %s", prop.c_str());
172 mexErrMsgIdAndTxt(
"mexopencv:error",
173 "Unrecognized operation %s",method.c_str());
const ConstMap< std::string, int > AgastTypeMap
AGAST neighborhood types.
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.
cv::Ptr< cv::AgastFeatureDetector > createAgastFeatureDetector(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of AgastFeatureDetector using options in arguments.
Global constant definitions.
const ConstMap< int, std::string > AgastTypeInvMap
inverse AGAST neighborhood types