19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
29 double pyrScale = 0.5;
34 double polySigma = 1.1;
36 for (
int i=2; i<nrhs; i+=2) {
37 string key(rhs[i].toString());
38 if (key==
"InitialFlow") {
39 flow = rhs[i+1].toMat(CV_32F);
40 flags |= cv::OPTFLOW_USE_INITIAL_FLOW;
42 else if (key==
"PyrScale")
43 pyrScale = rhs[i+1].toDouble();
44 else if (key==
"Levels")
45 levels = rhs[i+1].toInt();
46 else if (key==
"WinSize")
47 winsize = rhs[i+1].toInt();
48 else if (key==
"Iterations")
49 iterations = rhs[i+1].toInt();
50 else if (key==
"PolyN")
51 polyN = rhs[i+1].toInt();
52 else if (key==
"PolySigma")
53 polySigma = rhs[i+1].toDouble();
54 else if (key==
"Gaussian")
55 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::OPTFLOW_FARNEBACK_GAUSSIAN);
57 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
61 Mat prevImg(rhs[0].toMat(CV_8U)),
62 nextImg(rhs[1].toMat(CV_8U));
63 calcOpticalFlowFarneback(prevImg, nextImg, flow, pyrScale, levels,
64 winsize, iterations, polyN, polySigma, flags);
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
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.