9 #include "opencv2/saliency.hpp" 19 map<int,Ptr<MotionSaliencyBinWangApr2014> > 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] = makePtr<MotionSaliencyBinWangApr2014>();
48 Ptr<MotionSaliencyBinWangApr2014> obj = obj_[id];
49 if (method ==
"delete") {
53 else if (method ==
"clear") {
57 else if (method ==
"load") {
58 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
60 bool loadFromString =
false;
61 for (
int i=3; i<nrhs; i+=2) {
62 string key(rhs[i].toString());
64 objname = rhs[i+1].toString();
65 else if (key ==
"FromString")
66 loadFromString = rhs[i+1].toBool();
68 mexErrMsgIdAndTxt(
"mexopencv:error",
69 "Unrecognized option %s", key.c_str());
78 FileStorage fs(rhs[2].toString(), FileStorage::READ +
79 (loadFromString ? FileStorage::MEMORY : 0));
80 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
82 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
85 else if (method ==
"save") {
87 obj->save(rhs[2].toString());
89 else if (method ==
"empty") {
91 plhs[0] =
MxArray(obj->empty());
93 else if (method ==
"getDefaultName") {
95 plhs[0] =
MxArray(obj->getDefaultName());
97 else if (method ==
"getClassName") {
99 plhs[0] =
MxArray(obj->getClassName());
101 else if (method ==
"computeSaliency") {
103 Mat image(rhs[2].toMat(CV_8U)),
105 bool b = obj->computeSaliency(image, saliencyMap);
107 mexErrMsgIdAndTxt(
"mexopencv:error",
"computeSaliency failed");
108 plhs[0] =
MxArray(saliencyMap);
110 else if (method ==
"setImagesize") {
112 int W = rhs[2].toInt(),
114 obj->setImagesize(W, H);
116 else if (method ==
"init") {
118 bool b = obj->init();
120 mexErrMsgIdAndTxt(
"mexopencv:error",
"init failed");
122 else if (method ==
"get") {
124 string prop(rhs[2].toString());
125 if (prop ==
"ImageWidth")
126 plhs[0] =
MxArray(obj->getImageWidth());
127 else if (prop ==
"ImageHeight")
128 plhs[0] =
MxArray(obj->getImageHeight());
130 mexErrMsgIdAndTxt(
"mexopencv:error",
131 "Unrecognized property %s", prop.c_str());
133 else if (method ==
"set") {
135 string prop(rhs[2].toString());
136 if (prop ==
"ImageWidth")
137 obj->setImageWidth(rhs[3].toInt());
138 else if (prop ==
"ImageHeight")
139 obj->setImageHeight(rhs[3].toInt());
141 mexErrMsgIdAndTxt(
"mexopencv:error",
142 "Unrecognized property %s", prop.c_str());
145 mexErrMsgIdAndTxt(
"mexopencv:error",
146 "Unrecognized operation %s", method.c_str());
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.