20 map<int,Ptr<FeatureDetector> > obj_;
30 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
36 vector<MxArray> rhs(prhs, prhs+nrhs);
37 int id = rhs[0].toInt();
38 string method(rhs[1].toString());
41 if (method ==
"new") {
44 rhs[2].toString(), rhs.begin() + 3, rhs.end());
50 Ptr<FeatureDetector> 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 FileStorage fs(rhs[2].toString(), FileStorage::READ +
78 (loadFromString ? FileStorage::MEMORY : 0));
79 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
81 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
83 else if (method ==
"save") {
85 obj->save(rhs[2].toString());
87 else if (method ==
"empty") {
89 plhs[0] =
MxArray(obj->empty());
91 else if (method ==
"getDefaultName") {
93 plhs[0] =
MxArray(obj->getDefaultName());
95 else if (method ==
"detect") {
96 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
97 if (rhs[2].isNumeric()) {
99 for (
int i=3; i<nrhs; i+=2) {
100 string key(rhs[i].toString());
102 mask = rhs[i+1].toMat(CV_8U);
104 mexErrMsgIdAndTxt(
"mexopencv:error",
105 "Unrecognized option %s", key.c_str());
107 Mat image(rhs[2].toMat(CV_8U));
108 vector<KeyPoint> keypoints;
109 obj->detect(image, keypoints, mask);
112 else if (rhs[2].isCell()) {
114 for (
int i=3; i<nrhs; i+=2) {
115 string key(rhs[i].toString());
118 vector<MxArray> arr(rhs[i+1].toVector<MxArray>());
120 masks.reserve(arr.size());
121 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
122 masks.push_back(it->toMat(CV_8U));
125 mexErrMsgIdAndTxt(
"mexopencv:error",
126 "Unrecognized option %s", key.c_str());
131 vector<MxArray> arr(rhs[2].toVector<MxArray>());
132 images.reserve(arr.size());
133 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
134 images.push_back(it->toMat(CV_8U));
136 vector<vector<KeyPoint> > keypoints;
137 obj->detect(images, keypoints, masks);
141 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid arguments");
149 mexErrMsgIdAndTxt(
"mexopencv:error",
150 "Unrecognized operation %s",method.c_str());
cv::Ptr< cv::FeatureDetector > createFeatureDetector(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Factory function for FeatureDetector creation.
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.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.