19 map<int,Ptr<ORB> > 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] =
createORB(rhs.begin() + 2, rhs.end());
48 Ptr<ORB> 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<ORB>(rhs[2].toString(), objname) :
77 Algorithm::load<ORB>(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(CV_8U));
116 vector<KeyPoint> keypoints;
117 obj->detect(image, keypoints, mask);
120 else if (rhs[2].isCell()) {
122 for (
int i=3; i<nrhs; i+=2) {
123 string key(rhs[i].toString());
126 vector<MxArray> arr(rhs[i+1].toVector<MxArray>());
128 masks.reserve(arr.size());
129 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
130 masks.push_back(it->toMat(CV_8U));
133 mexErrMsgIdAndTxt(
"mexopencv:error",
134 "Unrecognized option %s", key.c_str());
139 vector<MxArray> arr(rhs[2].toVector<MxArray>());
140 images.reserve(arr.size());
141 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
142 images.push_back(it->toMat(CV_8U));
144 vector<vector<KeyPoint> > keypoints;
145 obj->detect(images, keypoints, masks);
149 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
151 else if (method ==
"compute") {
153 if (rhs[2].isNumeric()) {
154 Mat image(rhs[2].toMat(CV_8U)), descriptors;
155 vector<KeyPoint> keypoints(rhs[3].toVector<KeyPoint>());
156 obj->compute(image, keypoints, descriptors);
157 plhs[0] =
MxArray(descriptors);
161 else if (rhs[2].isCell()) {
163 vector<Mat> images, descriptors;
165 vector<MxArray> arr(rhs[2].toVector<MxArray>());
166 images.reserve(arr.size());
167 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
168 images.push_back(it->toMat(CV_8U));
170 vector<vector<KeyPoint> > keypoints(rhs[3].toVector(
171 const_mem_fun_ref_t<vector<KeyPoint>,
MxArray>(
172 &MxArray::toVector<KeyPoint>)));
173 obj->compute(images, keypoints, descriptors);
174 plhs[0] =
MxArray(descriptors);
179 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
181 else if (method ==
"detectAndCompute") {
182 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
184 vector<KeyPoint> keypoints;
185 bool useProvidedKeypoints =
false;
186 for (
int i=3; i<nrhs; i+=2) {
187 string key(rhs[i].toString());
189 mask = rhs[i+1].toMat(CV_8U);
190 else if (key ==
"Keypoints") {
191 keypoints = rhs[i+1].toVector<KeyPoint>();
192 useProvidedKeypoints =
true;
195 mexErrMsgIdAndTxt(
"mexopencv:error",
196 "Unrecognized option %s", key.c_str());
198 Mat image(rhs[2].toMat(CV_8U)), descriptors;
199 obj->detectAndCompute(image, mask, keypoints, descriptors,
200 useProvidedKeypoints);
203 plhs[1] =
MxArray(descriptors);
205 else if (method ==
"get") {
207 string prop(rhs[2].toString());
208 if (prop ==
"EdgeThreshold")
209 plhs[0] =
MxArray(obj->getEdgeThreshold());
210 else if (prop ==
"FastThreshold")
211 plhs[0] =
MxArray(obj->getFastThreshold());
212 else if (prop ==
"FirstLevel")
213 plhs[0] =
MxArray(obj->getFirstLevel());
214 else if (prop ==
"MaxFeatures")
215 plhs[0] =
MxArray(obj->getMaxFeatures());
216 else if (prop ==
"NLevels")
217 plhs[0] =
MxArray(obj->getNLevels());
218 else if (prop ==
"PatchSize")
219 plhs[0] =
MxArray(obj->getPatchSize());
220 else if (prop ==
"ScaleFactor")
221 plhs[0] =
MxArray(obj->getScaleFactor());
222 else if (prop ==
"ScoreType")
224 else if (prop ==
"WTA_K")
225 plhs[0] =
MxArray(obj->getWTA_K());
227 mexErrMsgIdAndTxt(
"mexopencv:error",
228 "Unrecognized property %s", prop.c_str());
230 else if (method ==
"set") {
232 string prop(rhs[2].toString());
233 if (prop ==
"EdgeThreshold")
234 obj->setEdgeThreshold(rhs[3].toInt());
235 else if (prop ==
"FastThreshold")
236 obj->setFastThreshold(rhs[3].toInt());
237 else if (prop ==
"FirstLevel")
238 obj->setFirstLevel(rhs[3].toInt());
239 else if (prop ==
"MaxFeatures")
240 obj->setMaxFeatures(rhs[3].toInt());
241 else if (prop ==
"NLevels")
242 obj->setNLevels(rhs[3].toInt());
243 else if (prop ==
"PatchSize")
244 obj->setPatchSize(rhs[3].toInt());
245 else if (prop ==
"ScaleFactor")
246 obj->setScaleFactor(rhs[3].toDouble());
247 else if (prop ==
"ScoreType")
249 else if (prop ==
"WTA_K")
250 obj->setWTA_K(rhs[3].toInt());
252 mexErrMsgIdAndTxt(
"mexopencv:error",
253 "Unrecognized property %s", prop.c_str());
256 mexErrMsgIdAndTxt(
"mexopencv:error",
257 "Unrecognized operation %s",method.c_str());
const ConstMap< int, std::string > ORBScoreTypeInv
inverse ORB score types
const ConstMap< int, std::string > NormTypeInv
Inverse norm type map for option processing.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
cv::Ptr< cv::ORB > createORB(std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of ORB 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 > ClassNameInvMap
Translates data type definition used in OpenCV to that of MATLAB.
Global constant definitions.
const ConstMap< std::string, int > ORBScoreType
ORB score types.