9 #include "opencv2/photo.hpp" 18 map<int,Ptr<Tonemap> > obj_;
25 Ptr<Tonemap> create_Tonemap(
26 vector<MxArray>::const_iterator first,
27 vector<MxArray>::const_iterator last)
29 ptrdiff_t len = std::distance(first, last);
32 for (; first != last; first += 2) {
33 string key(first->toString());
34 const MxArray& val = *(first + 1);
38 mexErrMsgIdAndTxt(
"mexopencv:error",
39 "Unrecognized option %s", key.c_str());
41 return createTonemap(gamma);
52 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
58 vector<MxArray> rhs(prhs, prhs+nrhs);
59 int id = rhs[0].toInt();
60 string method(rhs[1].toString());
63 if (method ==
"new") {
65 obj_[++last_id] = create_Tonemap(
66 rhs.begin() + 2, rhs.end());
72 Ptr<Tonemap> obj = obj_[id];
73 if (method ==
"delete") {
77 else if (method ==
"clear") {
81 else if (method ==
"load") {
82 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
84 bool loadFromString =
false;
85 for (
int i=3; i<nrhs; i+=2) {
86 string key(rhs[i].toString());
88 objname = rhs[i+1].toString();
89 else if (key ==
"FromString")
90 loadFromString = rhs[i+1].toBool();
92 mexErrMsgIdAndTxt(
"mexopencv:error",
93 "Unrecognized option %s", key.c_str());
102 FileStorage fs(rhs[2].toString(), FileStorage::READ +
103 (loadFromString ? FileStorage::MEMORY : 0));
104 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
106 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
109 else if (method ==
"save") {
111 obj->save(rhs[2].toString());
113 else if (method ==
"empty") {
115 plhs[0] =
MxArray(obj->empty());
117 else if (method ==
"getDefaultName") {
119 plhs[0] =
MxArray(obj->getDefaultName());
121 else if (method ==
"process") {
123 Mat src(rhs[2].toMat(CV_32F)), dst;
124 obj->process(src, dst);
127 else if (method ==
"get") {
129 string prop(rhs[2].toString());
131 plhs[0] =
MxArray(obj->getGamma());
133 mexErrMsgIdAndTxt(
"mexopencv:error",
134 "Unrecognized property %s", prop.c_str());
136 else if (method ==
"set") {
138 string prop(rhs[2].toString());
140 obj->setGamma(rhs[3].toFloat());
142 mexErrMsgIdAndTxt(
"mexopencv:error",
143 "Unrecognized property %s", prop.c_str());
146 mexErrMsgIdAndTxt(
"mexopencv:error",
147 "Unrecognized operation %s", method.c_str());
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
float toFloat() const
Convert MxArray to float.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.