9 #include "opencv2/saliency.hpp" 19 map<int,Ptr<ObjectnessBING> > 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<ObjectnessBING>();
48 Ptr<ObjectnessBING> 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));
81 (obj.dynamicCast<Saliency>())->read(
82 objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
84 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
87 else if (method ==
"save") {
89 obj->save(rhs[2].toString());
91 else if (method ==
"empty") {
93 plhs[0] =
MxArray(obj->empty());
95 else if (method ==
"getDefaultName") {
97 plhs[0] =
MxArray(obj->getDefaultName());
99 else if (method ==
"getClassName") {
101 plhs[0] =
MxArray(obj->getClassName());
103 else if (method ==
"computeSaliency") {
105 Mat image(rhs[2].toMat(CV_8U));
106 vector<Vec4i> objectnessBoundingBox;
107 bool b = obj->computeSaliency(image, objectnessBoundingBox);
109 mexErrMsgIdAndTxt(
"mexopencv:error",
"computeSaliency failed");
110 plhs[0] =
MxArray(objectnessBoundingBox);
112 else if (method ==
"getobjectnessValues") {
114 vector<float> objectnessValues = obj->getobjectnessValues();
115 plhs[0] =
MxArray(objectnessValues);
117 else if (method ==
"setTrainingPath") {
119 string trainingPath(rhs[2].toString());
120 obj->setTrainingPath(trainingPath);
122 else if (method ==
"setBBResDir") {
124 string resultsDir(rhs[2].toString());
125 obj->setBBResDir(resultsDir);
127 else if (method ==
"get") {
129 string prop(rhs[2].toString());
131 plhs[0] =
MxArray(obj->getBase());
132 else if (prop ==
"NSS")
133 plhs[0] =
MxArray(obj->getNSS());
134 else if (prop ==
"W")
135 plhs[0] =
MxArray(obj->getW());
137 mexErrMsgIdAndTxt(
"mexopencv:error",
138 "Unrecognized property %s", prop.c_str());
140 else if (method ==
"set") {
142 string prop(rhs[2].toString());
144 obj->setBase(rhs[3].toDouble());
145 else if (prop ==
"NSS")
146 obj->setNSS(rhs[3].toInt());
147 else if (prop ==
"W")
148 obj->setW(rhs[3].toInt());
150 mexErrMsgIdAndTxt(
"mexopencv:error",
151 "Unrecognized property %s", prop.c_str());
154 mexErrMsgIdAndTxt(
"mexopencv:error",
155 "Unrecognized operation %s", method.c_str());
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.