9 #include "opencv2/photo.hpp" 18 map<int,Ptr<CalibrateRobertson> > obj_;
25 Ptr<CalibrateRobertson> create_CalibrateRobertson(
26 vector<MxArray>::const_iterator first,
27 vector<MxArray>::const_iterator last)
29 ptrdiff_t len = std::distance(first, last);
32 float threshold = 0.01f;
33 for (; first != last; first += 2) {
34 string key(first->toString());
35 const MxArray& val = *(first + 1);
37 max_iter = val.
toInt();
38 else if (key ==
"Threshold")
39 threshold = val.toFloat();
41 mexErrMsgIdAndTxt(
"mexopencv:error",
42 "Unrecognized option %s", key.c_str());
44 return createCalibrateRobertson(max_iter, threshold);
55 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
61 vector<MxArray> rhs(prhs, prhs+nrhs);
62 int id = rhs[0].toInt();
63 string method(rhs[1].toString());
66 if (method ==
"new") {
68 obj_[++last_id] = create_CalibrateRobertson(
69 rhs.begin() + 2, rhs.end());
75 Ptr<CalibrateRobertson> obj = obj_[id];
76 if (method ==
"delete") {
80 else if (method ==
"clear") {
84 else if (method ==
"load") {
85 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
87 bool loadFromString =
false;
88 for (
int i=3; i<nrhs; i+=2) {
89 string key(rhs[i].toString());
91 objname = rhs[i+1].toString();
92 else if (key ==
"FromString")
93 loadFromString = rhs[i+1].toBool();
95 mexErrMsgIdAndTxt(
"mexopencv:error",
96 "Unrecognized option %s", key.c_str());
105 FileStorage fs(rhs[2].toString(), FileStorage::READ +
106 (loadFromString ? FileStorage::MEMORY : 0));
107 obj->read(objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]);
109 mexErrMsgIdAndTxt(
"mexopencv:error",
"Failed to load algorithm");
112 else if (method ==
"save") {
114 obj->save(rhs[2].toString());
116 else if (method ==
"empty") {
118 plhs[0] =
MxArray(obj->empty());
120 else if (method ==
"getDefaultName") {
122 plhs[0] =
MxArray(obj->getDefaultName());
124 else if (method ==
"process") {
128 vector<MxArray> arr(rhs[2].toVector<MxArray>());
129 src.reserve(arr.size());
130 for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
131 src.push_back(it->toMat(CV_8U));
133 Mat times(rhs[3].toMat(CV_32F)), dst;
134 obj->process(src, dst, times);
137 else if (method ==
"getRadiance") {
139 plhs[0] =
MxArray(obj->getRadiance());
141 else if (method ==
"get") {
143 string prop(rhs[2].toString());
144 if (prop ==
"MaxIter")
145 plhs[0] =
MxArray(obj->getMaxIter());
146 else if (prop ==
"Threshold")
147 plhs[0] =
MxArray(obj->getThreshold());
149 mexErrMsgIdAndTxt(
"mexopencv:error",
150 "Unrecognized property %s", prop.c_str());
152 else if (method ==
"set") {
154 string prop(rhs[2].toString());
155 if (prop ==
"MaxIter")
156 obj->setMaxIter(rhs[3].toInt());
157 else if (prop ==
"Threshold")
158 obj->setThreshold(rhs[3].toFloat());
160 mexErrMsgIdAndTxt(
"mexopencv:error",
161 "Unrecognized property %s", prop.c_str());
164 mexErrMsgIdAndTxt(
"mexopencv:error",
165 "Unrecognized operation %s", method.c_str());
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
int toInt() const
Convert MxArray to int.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.