9 #include "opencv2/photo.hpp" 18 map<int,Ptr<TonemapDrago> > obj_;
25 Ptr<TonemapDrago> create_TonemapDrago(
26 vector<MxArray>::const_iterator first,
27 vector<MxArray>::const_iterator last)
29 ptrdiff_t len = std::distance(first, last);
32 float saturation = 1.0f;
34 for (; first != last; first += 2) {
35 string key(first->toString());
36 const MxArray& val = *(first + 1);
39 else if (key ==
"Saturation")
40 saturation = val.toFloat();
41 else if (key ==
"Bias")
44 mexErrMsgIdAndTxt(
"mexopencv:error",
45 "Unrecognized option %s", key.c_str());
47 return createTonemapDrago(gamma, saturation, bias);
58 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
64 vector<MxArray> rhs(prhs, prhs+nrhs);
65 int id = rhs[0].toInt();
66 string method(rhs[1].toString());
69 if (method ==
"new") {
71 obj_[++last_id] = create_TonemapDrago(
72 rhs.begin() + 2, rhs.end());
78 Ptr<TonemapDrago> obj = obj_[id];
79 if (method ==
"delete") {
83 else if (method ==
"clear") {
87 else if (method ==
"load") {
88 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
90 bool loadFromString =
false;
91 for (
int i=3; i<nrhs; i+=2) {
92 string key(rhs[i].toString());
94 objname = rhs[i+1].toString();
95 else if (key ==
"FromString")
96 loadFromString = rhs[i+1].toBool();
98 mexErrMsgIdAndTxt(
"mexopencv:error",
99 "Unrecognized option %s", key.c_str());
108 FileStorage fs(rhs[2].toString(), FileStorage::READ +
109 (loadFromString ? FileStorage::MEMORY : 0));
110 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
112 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
115 else if (method ==
"save") {
117 obj->save(rhs[2].toString());
119 else if (method ==
"empty") {
121 plhs[0] =
MxArray(obj->empty());
123 else if (method ==
"getDefaultName") {
125 plhs[0] =
MxArray(obj->getDefaultName());
127 else if (method ==
"process") {
129 Mat src(rhs[2].toMat(CV_32F)), dst;
130 obj->process(src, dst);
133 else if (method ==
"get") {
135 string prop(rhs[2].toString());
137 plhs[0] =
MxArray(obj->getGamma());
138 else if (prop ==
"Saturation")
139 plhs[0] =
MxArray(obj->getSaturation());
140 else if (prop ==
"Bias")
141 plhs[0] =
MxArray(obj->getBias());
143 mexErrMsgIdAndTxt(
"mexopencv:error",
144 "Unrecognized property %s", prop.c_str());
146 else if (method ==
"set") {
148 string prop(rhs[2].toString());
150 obj->setGamma(rhs[3].toFloat());
151 else if (prop ==
"Saturation")
152 obj->setSaturation(rhs[3].toFloat());
153 else if (prop ==
"Bias")
154 obj->setBias(rhs[3].toFloat());
156 mexErrMsgIdAndTxt(
"mexopencv:error",
157 "Unrecognized property %s", prop.c_str());
160 mexErrMsgIdAndTxt(
"mexopencv:error",
161 "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.