19 map<int,Ptr<AKAZE> > 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] =
createAKAZE(rhs.begin() + 2, rhs.end());
48 Ptr<AKAZE> 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<AKAZE>(rhs[2].toString(), objname) :
77 Algorithm::load<AKAZE>(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 ==
"DescriptorChannels")
216 plhs[0] =
MxArray(obj->getDescriptorChannels());
217 else if (prop ==
"DescriptorSize")
218 plhs[0] =
MxArray(obj->getDescriptorSize());
219 else if (prop ==
"DescriptorType")
221 else if (prop ==
"Diffusivity")
223 else if (prop ==
"NOctaveLayers")
224 plhs[0] =
MxArray(obj->getNOctaveLayers());
225 else if (prop ==
"NOctaves")
226 plhs[0] =
MxArray(obj->getNOctaves());
227 else if (prop ==
"Threshold")
228 plhs[0] =
MxArray(obj->getThreshold());
230 mexErrMsgIdAndTxt(
"mexopencv:error",
231 "Unrecognized property %s", prop.c_str());
233 else if (method ==
"set") {
235 string prop(rhs[2].toString());
236 if (prop ==
"DescriptorChannels")
237 obj->setDescriptorChannels(rhs[3].toInt());
238 else if (prop ==
"DescriptorSize")
239 obj->setDescriptorSize(rhs[3].toInt());
240 else if (prop ==
"DescriptorType")
242 else if (prop ==
"Diffusivity")
244 else if (prop ==
"NOctaveLayers")
245 obj->setNOctaveLayers(rhs[3].toInt());
246 else if (prop ==
"NOctaves")
247 obj->setNOctaves(rhs[3].toInt());
248 else if (prop ==
"Threshold")
249 obj->setThreshold(rhs[3].toDouble());
251 mexErrMsgIdAndTxt(
"mexopencv:error",
252 "Unrecognized property %s", prop.c_str());
255 mexErrMsgIdAndTxt(
"mexopencv:error",
256 "Unrecognized operation %s",method.c_str());
const ConstMap< std::string, int > KAZEDiffusivityType
KAZE Diffusivity type.
cv::Ptr< cv::AKAZE > createAKAZE(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of AKAZE using options in arguments.
const ConstMap< std::string, int > AKAZEDescriptorType
AKAZE descriptor type.
const ConstMap< int, std::string > NormTypeInv
Inverse norm type map for option processing.
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.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.
const ConstMap< int, std::string > AKAZEDescriptorTypeInv
inverse AKAZE descriptor type