11 #include "opencv2/xfeatures2d.hpp" 21 map<int,Ptr<DAISY> > obj_;
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") {
44 obj_[++last_id] = createDAISY(rhs.begin() + 2, rhs.end());
50 Ptr<DAISY> obj = obj_[id];
51 if (method ==
"delete") {
55 else if (method ==
"typeid") {
57 plhs[0] =
MxArray(
string(
typeid(*obj).name()));
59 else if (method ==
"clear") {
63 else if (method ==
"load") {
64 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
66 bool loadFromString =
false;
67 for (
int i=3; i<nrhs; i+=2) {
68 string key(rhs[i].toString());
70 objname = rhs[i+1].toString();
71 else if (key ==
"FromString")
72 loadFromString = rhs[i+1].toBool();
74 mexErrMsgIdAndTxt(
"mexopencv:error",
75 "Unrecognized option %s", key.c_str());
77 obj_[id] = (loadFromString ?
78 Algorithm::loadFromString<DAISY>(rhs[2].toString(), objname) :
79 Algorithm::load<DAISY>(rhs[2].toString(), objname));
81 else if (method ==
"save") {
83 obj->save(rhs[2].toString());
85 else if (method ==
"empty") {
87 plhs[0] =
MxArray(obj->empty());
89 else if (method ==
"getDefaultName") {
91 plhs[0] =
MxArray(obj->getDefaultName());
93 else if (method ==
"defaultNorm") {
97 else if (method ==
"descriptorSize") {
99 plhs[0] =
MxArray(obj->descriptorSize());
101 else if (method ==
"descriptorType") {
105 else if (method ==
"compute") {
107 if (rhs[2].isNumeric()) {
108 Mat image(rhs[2].toMat(rhs[2].isSingle() ? CV_32F : CV_8U)),
110 vector<KeyPoint> keypoints(rhs[3].toVector<KeyPoint>());
111 obj->compute(image, keypoints, descriptors);
112 plhs[0] =
MxArray(descriptors);
116 else if (rhs[2].isCell()) {
118 vector<Mat> images, descriptors;
120 vector<MxArray> arr(rhs[2].toVector<MxArray>());
121 images.reserve(arr.size());
122 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
123 images.push_back(it->toMat(it->isSingle() ? CV_32F : CV_8U));
125 vector<vector<KeyPoint> > keypoints(rhs[3].toVector(
126 const_mem_fun_ref_t<vector<KeyPoint>,
MxArray>(
127 &MxArray::toVector<KeyPoint>)));
128 obj->compute(images, keypoints, descriptors);
129 plhs[0] =
MxArray(descriptors);
134 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
136 else if (method ==
"compute_all") {
137 nargchk((nrhs==3 || nrhs==4) && nlhs<=1);
138 Mat image(rhs[2].toMat(rhs[2].isSingle() ? CV_32F : CV_8U)),
141 Rect roi(rhs[3].toRect());
142 obj->compute(image, roi, descriptors);
145 obj->compute(image, descriptors);
146 plhs[0] =
MxArray(descriptors);
148 else if (method ==
"GetDescriptor") {
149 nargchk(nrhs>=5 && (nrhs%2)==1 && nlhs<=2);
150 double y = rhs[2].toDouble(),
151 x = rhs[3].toDouble();
152 int orientation = rhs[4].toInt();
153 bool unnormalized =
false;
154 bool useHomography =
false;
156 for (
int i=5; i<nrhs; i+=2) {
157 string key(rhs[i].toString());
158 if (key==
"Unnormalized")
159 unnormalized = rhs[i+1].toBool();
161 H = rhs[i+1].toMatx<double,3,3>();
162 useHomography =
true;
165 mexErrMsgIdAndTxt(
"mexopencv:error",
166 "Unrecognized option %s", key.c_str());
168 vector<float> descriptor(obj->descriptorSize());
172 ret = obj->GetUnnormalizedDescriptor(y, x, orientation,
173 &descriptor[0], H.val);
175 obj->GetUnnormalizedDescriptor(y, x, orientation,
180 ret = obj->GetDescriptor(y, x, orientation,
181 &descriptor[0], H.val);
183 obj->GetDescriptor(y, x, orientation, &descriptor[0]);
192 mexErrMsgIdAndTxt(
"mexopencv:error",
193 "Unrecognized operation %s",method.c_str());
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 > ClassNameInvMap
Translates data type definition used in OpenCV to that of MATLAB.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.