19 map<int,Ptr<KAZE> > 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") {
42 obj_[++last_id] =
createKAZE(rhs.begin() + 2, rhs.end());
48 Ptr<KAZE> obj = obj_[id];
49 if (method ==
"delete") {
53 else if (method ==
"typeid") {
55 plhs[0] =
MxArray(
string(
typeid(*obj).name()));
57 else if (method ==
"clear") {
61 else if (method ==
"load") {
62 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
64 bool loadFromString =
false;
65 for (
int i=3; i<nrhs; i+=2) {
66 string key(rhs[i].toString());
68 objname = rhs[i+1].toString();
69 else if (key ==
"FromString")
70 loadFromString = rhs[i+1].toBool();
72 mexErrMsgIdAndTxt(
"mexopencv:error",
73 "Unrecognized option %s", key.c_str());
75 obj_[id] = (loadFromString ?
76 Algorithm::loadFromString<KAZE>(rhs[2].toString(), objname) :
77 Algorithm::load<KAZE>(rhs[2].toString(), objname));
79 else if (method ==
"save") {
81 obj->save(rhs[2].toString());
83 else if (method ==
"empty") {
85 plhs[0] =
MxArray(obj->empty());
87 else if (method ==
"getDefaultName") {
89 plhs[0] =
MxArray(obj->getDefaultName());
91 else if (method ==
"defaultNorm") {
95 else if (method ==
"descriptorSize") {
97 plhs[0] =
MxArray(obj->descriptorSize());
99 else if (method ==
"descriptorType") {
103 else if (method ==
"detect") {
104 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
105 if (rhs[2].isNumeric()) {
107 for (
int i=3; i<nrhs; i+=2) {
108 string key(rhs[i].toString());
110 mask = rhs[i+1].toMat(CV_8U);
112 mexErrMsgIdAndTxt(
"mexopencv:error",
113 "Unrecognized option %s", key.c_str());
115 Mat image(rhs[2].toMat(rhs[2].isUint8() ? CV_8U :
116 (rhs[2].isUint16() ? CV_16U : CV_32F)));
117 vector<KeyPoint> keypoints;
118 obj->detect(image, keypoints, mask);
121 else if (rhs[2].isCell()) {
123 for (
int i=3; i<nrhs; i+=2) {
124 string key(rhs[i].toString());
127 vector<MxArray> arr(rhs[i+1].toVector<MxArray>());
129 masks.reserve(arr.size());
130 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
131 masks.push_back(it->toMat(CV_8U));
134 mexErrMsgIdAndTxt(
"mexopencv:error",
135 "Unrecognized option %s", key.c_str());
140 vector<MxArray> arr(rhs[2].toVector<MxArray>());
141 images.reserve(arr.size());
142 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
143 images.push_back(it->toMat(it->isUint8() ? CV_8U :
144 (it->isUint16() ? CV_16U : CV_32F)));
146 vector<vector<KeyPoint> > keypoints;
147 obj->detect(images, keypoints, masks);
151 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
153 else if (method ==
"compute") {
155 if (rhs[2].isNumeric()) {
156 Mat image(rhs[2].toMat(rhs[2].isUint8() ? CV_8U :
157 (rhs[2].isUint16() ? CV_16U : CV_32F))),
159 vector<KeyPoint> keypoints(rhs[3].toVector<KeyPoint>());
160 obj->compute(image, keypoints, descriptors);
161 plhs[0] =
MxArray(descriptors);
165 else if (rhs[2].isCell()) {
167 vector<Mat> images, descriptors;
169 vector<MxArray> arr(rhs[2].toVector<MxArray>());
170 images.reserve(arr.size());
171 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
172 images.push_back(it->toMat(it->isUint8() ? CV_8U :
173 (it->isUint16() ? CV_16U : CV_32F)));
175 vector<vector<KeyPoint> > keypoints(rhs[3].toVector(
176 const_mem_fun_ref_t<vector<KeyPoint>,
MxArray>(
177 &MxArray::toVector<KeyPoint>)));
178 obj->compute(images, keypoints, descriptors);
179 plhs[0] =
MxArray(descriptors);
184 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
186 else if (method ==
"detectAndCompute") {
187 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
189 vector<KeyPoint> keypoints;
190 bool useProvidedKeypoints =
false;
191 for (
int i=3; i<nrhs; i+=2) {
192 string key(rhs[i].toString());
194 mask = rhs[i+1].toMat(CV_8U);
195 else if (key ==
"Keypoints") {
196 keypoints = rhs[i+1].toVector<KeyPoint>();
197 useProvidedKeypoints =
true;
200 mexErrMsgIdAndTxt(
"mexopencv:error",
201 "Unrecognized option %s", key.c_str());
203 Mat image(rhs[2].toMat(rhs[2].isUint8() ? CV_8U :
204 (rhs[2].isUint16() ? CV_16U : CV_32F))),
206 obj->detectAndCompute(image, mask, keypoints, descriptors,
207 useProvidedKeypoints);
210 plhs[1] =
MxArray(descriptors);
212 else if (method ==
"get") {
214 string prop(rhs[2].toString());
215 if (prop ==
"Diffusivity")
217 else if (prop ==
"Extended")
218 plhs[0] =
MxArray(obj->getExtended());
219 else if (prop ==
"NOctaveLayers")
220 plhs[0] =
MxArray(obj->getNOctaveLayers());
221 else if (prop ==
"NOctaves")
222 plhs[0] =
MxArray(obj->getNOctaves());
223 else if (prop ==
"Threshold")
224 plhs[0] =
MxArray(obj->getThreshold());
225 else if (prop ==
"Upright")
226 plhs[0] =
MxArray(obj->getUpright());
228 mexErrMsgIdAndTxt(
"mexopencv:error",
229 "Unrecognized property %s", prop.c_str());
231 else if (method ==
"set") {
233 string prop(rhs[2].toString());
234 if (prop ==
"Diffusivity")
236 else if (prop ==
"Extended")
237 obj->setExtended(rhs[3].toBool());
238 else if (prop ==
"NOctaveLayers")
239 obj->setNOctaveLayers(rhs[3].toInt());
240 else if (prop ==
"NOctaves")
241 obj->setNOctaves(rhs[3].toInt());
242 else if (prop ==
"Threshold")
243 obj->setThreshold(rhs[3].toDouble());
244 else if (prop ==
"Upright")
245 obj->setUpright(rhs[3].toBool());
247 mexErrMsgIdAndTxt(
"mexopencv:error",
248 "Unrecognized property %s", prop.c_str());
251 mexErrMsgIdAndTxt(
"mexopencv:error",
252 "Unrecognized operation %s",method.c_str());
const ConstMap< std::string, int > KAZEDiffusivityType
KAZE Diffusivity type.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
const ConstMap< int, std::string > NormTypeInv
Inverse norm type map for option processing.
cv::Ptr< cv::KAZE > createKAZE(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of KAZE using options in arguments.
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.
const ConstMap< int, std::string > KAZEDiffusivityTypeInv
inverse KAZE Diffusivity type
const ConstMap< int, std::string > ClassNameInvMap
Translates data type definition used in OpenCV to that of MATLAB.
Global constant definitions.