9 #include "opencv2/saliency.hpp" 19 map<int,Ptr<StaticSaliencySpectralResidual> > 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<StaticSaliencySpectralResidual>();
48 Ptr<StaticSaliencySpectralResidual> 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()),
105 bool b = obj->computeSaliency(image, saliencyMap);
107 mexErrMsgIdAndTxt(
"mexopencv:error",
"computeSaliency failed");
108 plhs[0] =
MxArray(saliencyMap);
110 else if (method ==
"computeBinaryMap") {
112 Mat saliencyMap(rhs[2].toMat(CV_32F)),
114 bool b = obj->computeBinaryMap(saliencyMap, binaryMap);
116 mexErrMsgIdAndTxt(
"mexopencv:error",
"computeBinaryMap failed");
119 else if (method ==
"get") {
121 string prop(rhs[2].toString());
122 if (prop ==
"ImageWidth")
123 plhs[0] =
MxArray(obj->getImageWidth());
124 else if (prop ==
"ImageHeight")
125 plhs[0] =
MxArray(obj->getImageHeight());
127 mexErrMsgIdAndTxt(
"mexopencv:error",
128 "Unrecognized property %s", prop.c_str());
130 else if (method ==
"set") {
132 string prop(rhs[2].toString());
133 if (prop ==
"ImageWidth")
134 obj->setImageWidth(rhs[3].toInt());
135 else if (prop ==
"ImageHeight")
136 obj->setImageHeight(rhs[3].toInt());
138 mexErrMsgIdAndTxt(
"mexopencv:error",
139 "Unrecognized property %s", prop.c_str());
142 mexErrMsgIdAndTxt(
"mexopencv:error",
143 "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.