9 #include "opencv2/photo.hpp" 18 map<int,Ptr<MergeRobertson> > obj_;
28 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
34 vector<MxArray> rhs(prhs, prhs+nrhs);
35 int id = rhs[0].toInt();
36 string method(rhs[1].toString());
39 if (method ==
"new") {
41 obj_[++last_id] = createMergeRobertson();
47 Ptr<MergeRobertson> obj = obj_[id];
48 if (method ==
"delete") {
52 else if (method ==
"clear") {
56 else if (method ==
"load") {
57 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
59 bool loadFromString =
false;
60 for (
int i=3; i<nrhs; i+=2) {
61 string key(rhs[i].toString());
63 objname = rhs[i+1].toString();
64 else if (key ==
"FromString")
65 loadFromString = rhs[i+1].toBool();
67 mexErrMsgIdAndTxt(
"mexopencv:error",
68 "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");
84 else if (method ==
"save") {
86 obj->save(rhs[2].toString());
88 else if (method ==
"empty") {
90 plhs[0] =
MxArray(obj->empty());
92 else if (method ==
"getDefaultName") {
94 plhs[0] =
MxArray(obj->getDefaultName());
96 else if (method ==
"process") {
97 nargchk((nrhs==4 || nrhs==5) && nlhs<=1);
100 vector<MxArray> arr(rhs[2].toVector<MxArray>());
101 src.reserve(arr.size());
102 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
103 src.push_back(it->toMat(CV_8U));
105 Mat times(rhs[3].toMat(CV_32F)), dst;
107 Mat response(rhs[4].toMat(CV_32F));
108 obj->process(src, dst, times, response);
111 obj->process(src, dst, times);
115 mexErrMsgIdAndTxt(
"mexopencv:error",
116 "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.