27 const char *fields[] = {
"angle",
"class_id",
"octave",
"pt",
"response",
28 "size",
"startPoint",
"endPoint",
"startPointInOctave",
29 "endPointInOctave",
"lineLength",
"numOfPixels"};
32 s.
set(
"angle", keylines[i].angle, i);
33 s.
set(
"class_id", keylines[i].class_id, i);
34 s.
set(
"octave", keylines[i].octave, i);
35 s.
set(
"pt", keylines[i].pt, i);
36 s.
set(
"response", keylines[i].response, i);
37 s.
set(
"size", keylines[i].
size, i);
38 s.
set(
"startPoint", keylines[i].getStartPoint(), i);
39 s.
set(
"endPoint", keylines[i].getEndPoint(), i);
40 s.
set(
"startPointInOctave", keylines[i].getStartPointInOctave(), i);
41 s.
set(
"endPointInOctave", keylines[i].getEndPointInOctave(), i);
42 s.
set(
"lineLength", keylines[i].lineLength, i);
43 s.
set(
"numOfPixels", keylines[i].numOfPixels, i);
55 for (
mwIndex i = 0; i < keylines.size(); ++i)
68 keyline.
angle = arr.
at(
"angle", idx).toFloat();
69 keyline.
class_id = arr.
at(
"class_id", idx).toInt();
70 keyline.
octave = arr.
at(
"octave", idx).toInt();
71 keyline.
pt = arr.
at(
"pt", idx).toPoint2f();
72 keyline.
response = arr.
at(
"response", idx).toFloat();
73 keyline.
size = arr.
at(
"size", idx).toFloat();
74 keyline.
startPointX = arr.
at(
"startPoint", idx).toPoint2f().x;
75 keyline.
startPointY = arr.
at(
"startPoint", idx).toPoint2f().y;
76 keyline.
endPointX = arr.
at(
"endPoint", idx).toPoint2f().x;
77 keyline.
endPointY = arr.
at(
"endPoint", idx).toPoint2f().y;
82 keyline.
lineLength = arr.
at(
"lineLength", idx).toFloat();
100 for (
mwIndex i = 0; i < n; ++i)
104 "MxArray unable to convert to std::vector<cv::line_descriptor::KeyLine>");
137 int id = rhs[0].toInt();
138 string method(rhs[1].toString());
141 if (method ==
"new") {
142 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
144 for (
int i=2; i<nrhs; i+=2) {
145 string key(rhs[i].toString());
147 parameters.
ksize_ = rhs[i+1].toInt();
148 else if (key ==
"NumOfOctave")
150 else if (key ==
"ReductionRatio")
152 else if (key ==
"WidthOfBand")
156 "Unrecognized option %s", key.
c_str());
158 obj_[++
last_id] = BinaryDescriptor::createBinaryDescriptor(parameters);
168 if (method ==
"delete") {
173 else if (method ==
"clear") {
177 else if (method ==
"load") {
178 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
180 bool loadFromString =
false;
181 for (
int i=3; i<nrhs; i+=2) {
182 string key(rhs[i].toString());
183 if (key ==
"ObjName")
184 objname = rhs[i+1].toString();
185 else if (key ==
"FromString")
186 loadFromString = rhs[i+1].toBool();
189 "Unrecognized option %s", key.
c_str());
198 FileStorage fs(rhs[2].toString(), FileStorage::READ +
199 (loadFromString ? FileStorage::MEMORY : 0));
208 else if (method ==
"save") {
210 obj->
save(rhs[2].toString());
212 else if (method ==
"empty") {
216 else if (method ==
"getDefaultName") {
220 else if (method ==
"defaultNorm") {
224 else if (method ==
"descriptorSize") {
228 else if (method ==
"descriptorType") {
232 else if (method ==
"detect") {
233 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
234 if (rhs[2].isNumeric()) {
236 for (
int i=3; i<nrhs; i+=2) {
237 string key(rhs[i].toString());
239 mask = rhs[i+1].toMat(
CV_8U);
242 "Unrecognized option %s", key.
c_str());
246 obj->
detect(image, keylines, mask);
249 else if (rhs[2].isCell()) {
251 for (
int i=3; i<nrhs; i+=2) {
252 string key(rhs[i].toString());
263 "Unrecognized option %s", key.
c_str());
279 obj->
detect(images, keylines, masks);
285 else if (method ==
"compute") {
286 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
287 bool returnFloatDescr =
false;
288 for (
int i=4; i<nrhs; i+=2) {
289 string key(rhs[i].toString());
290 if (key ==
"ReturnFloatDescr")
291 returnFloatDescr = rhs[i+1].toBool();
294 "Unrecognized option %s", key.
c_str());
296 if (rhs[2].isNumeric()) {
299 obj->
compute(image, keylines, descriptors, returnFloatDescr);
300 plhs[0] =
MxArray(descriptors);
304 else if (rhs[2].isCell()) {
315 if (keylines.
size() != images.
size())
319 obj->
compute(images, keylines, descriptors, returnFloatDescr);
320 plhs[0] =
MxArray(descriptors);
327 else if (method ==
"detectAndCompute") {
328 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
331 bool useProvidedKeyLines =
false;
332 bool returnFloatDescr =
false;
333 for (
int i=3; i<nrhs; i+=2) {
334 string key(rhs[i].toString());
336 mask = rhs[i+1].toMat(
CV_8U);
337 else if (key ==
"KeyLines") {
339 useProvidedKeyLines =
true;
341 else if (key ==
"ReturnFloatDescr")
342 returnFloatDescr = rhs[i+1].toBool();
345 "Unrecognized option %s", key.
c_str());
348 obj->operator()(image, mask, keylines, descriptors,
349 useProvidedKeyLines, returnFloatDescr);
352 plhs[1] =
MxArray(descriptors);
354 else if (method ==
"get") {
356 string prop(rhs[2].toString());
357 if (prop ==
"NumOfOctaves")
359 else if (prop ==
"ReductionRatio")
361 else if (prop ==
"WidthOfBand")
365 "Unrecognized property %s", prop.
c_str());
367 else if (method ==
"set") {
369 string prop(rhs[2].toString());
370 if (prop ==
"NumOfOctaves")
372 else if (prop ==
"ReductionRatio")
374 else if (prop ==
"WidthOfBand")
378 "Unrecognized property %s", prop.
c_str());
382 "Unrecognized operation %s",method.
c_str());
vector< KeyLine > MxArrayToVectorKeyLine(const MxArray &arr)
Convert an MxArray to std::vector<cv::line_descriptor::KeyLine>
int descriptorType() const
map< int, Ptr< BinaryDescriptor > > obj_
Object container.
MxArray toCellOfStruct(const vector< vector< KeyLine > > &keylines)
Convert set of keylines to cell-array of struct-arrays.
mwSize numel() const
Number of elements in an array.
T at(mwIndex index) const
Template for numeric array element accessor.
vector< vector< KeyLine > > MxArrayToVectorVectorKeyLine(const MxArray &arr)
Convert an MxArray to std::vector<std::vector<cv::line_descriptor::KeyLine>>
void compute(const Mat &image, std::vector< KeyLine > &keylines, Mat &descriptors, bool returnFloatDescr=false) const
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
const ConstMap< int, std::string > NormTypeInv
Inverse norm type map for option processing.
KeyLine MxArrayToKeyLine(const MxArray &arr, mwIndex idx=0)
Convert an MxArray to cv::line_descriptor::KeyLine.
int descriptorSize() const
void setReductionRatio(int rRatio)
virtual bool isOpened() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
virtual void read(const cv::FileNode &fn)
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
MxArray toStruct(const vector< KeyLine > &keylines)
Convert keylines to struct array.
bool isCell() const
Determine whether input is cell array.
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
FileNode getFirstTopLevelNode() const
bool isStruct() const
Determine whether input is structure array.
void detect(const Mat &image, std::vector< KeyLine > &keypoints, const Mat &mask=Mat())
static MxArray Cell(mwSize m=1, mwSize n=1)
Create a new cell array.
const ConstMap< int, std::string > ClassNameInvMap
Translates data type definition used in OpenCV to that of MATLAB.
std::vector< T > toVector() const
Convert MxArray to std::vector<T> of primitive types.
virtual String getDefaultName() const
Global constant definitions.
void setNumOfOctaves(int octaves)
int last_id
Last object id to allocate.
void setWidthOfBand(int width)
virtual void save(const String &filename) const
virtual bool empty() const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.