17 map<int,Ptr<KalmanFilter> > obj_;
27 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
33 vector<MxArray> rhs(prhs, prhs+nrhs);
34 int id = rhs[0].toInt();
35 string method(rhs[1].toString());
38 if (method ==
"new") {
40 obj_[++last_id] = makePtr<KalmanFilter>();
46 Ptr<KalmanFilter> obj = obj_[id];
47 if (method ==
"delete") {
51 else if (method ==
"init") {
52 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs==0);
53 int dynamParams = rhs[2].toInt();
54 int measureParams = rhs[3].toInt();
55 int controlParams = 0;
57 for (
int i=4; i<nrhs; i+=2) {
58 string key(rhs[i].toString());
59 if (key==
"ControlParams")
60 controlParams = rhs[i+1].toInt();
62 type = (rhs[i+1].isChar()) ?
65 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
67 obj->init(dynamParams, measureParams, controlParams, type);
69 else if (method ==
"predict") {
70 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
72 for (
int i=2; i<nrhs; i+=2) {
73 string key(rhs[i].toString());
75 control = rhs[i+1].toMat();
77 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
79 plhs[0] =
MxArray(obj->predict(control));
81 else if (method ==
"correct") {
83 Mat measurement(rhs[2].toMat());
84 plhs[0] =
MxArray(obj->correct(measurement));
86 else if (method ==
"get") {
88 string prop(rhs[2].toString());
89 if (prop ==
"statePre")
90 plhs[0] =
MxArray(obj->statePre);
91 else if (prop ==
"statePost")
92 plhs[0] =
MxArray(obj->statePost);
93 else if (prop ==
"transitionMatrix")
94 plhs[0] =
MxArray(obj->transitionMatrix);
95 else if (prop ==
"controlMatrix")
96 plhs[0] =
MxArray(obj->controlMatrix);
97 else if (prop ==
"measurementMatrix")
98 plhs[0] =
MxArray(obj->measurementMatrix);
99 else if (prop ==
"measurementNoiseCov")
100 plhs[0] =
MxArray(obj->measurementNoiseCov);
101 else if (prop ==
"processNoiseCov")
102 plhs[0] =
MxArray(obj->processNoiseCov);
103 else if (prop ==
"errorCovPre")
104 plhs[0] =
MxArray(obj->errorCovPre);
105 else if (prop ==
"errorCovPost")
106 plhs[0] =
MxArray(obj->errorCovPost);
107 else if (prop ==
"gain")
110 mexErrMsgIdAndTxt(
"mexopencv:error",
111 "Unrecognized property %s", prop.c_str());
113 else if (method ==
"set") {
115 string prop(rhs[2].toString());
116 if (prop ==
"statePre")
117 obj->statePre = rhs[3].toMat();
118 else if (prop ==
"statePost")
119 obj->statePost = rhs[3].toMat();
120 else if (prop ==
"transitionMatrix")
121 obj->transitionMatrix = rhs[3].toMat();
122 else if (prop ==
"controlMatrix")
123 obj->controlMatrix = rhs[3].toMat();
124 else if (prop ==
"measurementMatrix")
125 obj->measurementMatrix = rhs[3].toMat();
126 else if (prop ==
"measurementNoiseCov")
127 obj->measurementNoiseCov = rhs[3].toMat();
128 else if (prop ==
"processNoiseCov")
129 obj->processNoiseCov = rhs[3].toMat();
130 else if (prop ==
"errorCovPre")
131 obj->errorCovPre = rhs[3].toMat();
132 else if (prop ==
"errorCovPost")
133 obj->errorCovPost = rhs[3].toMat();
134 else if (prop ==
"gain")
135 obj->gain = rhs[3].toMat();
137 mexErrMsgIdAndTxt(
"mexopencv:error",
138 "Unrecognized property %s", prop.c_str());
141 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized operation");
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
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.