mexopencv  0.1
mex interface for opencv library
calcOpticalFlowFarneback.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  Mat flow;
29  double pyrScale = 0.5;
30  int levels = 5;
31  int winsize = 13;
32  int iterations = 10;
33  int polyN = 5;
34  double polySigma = 1.1;
35  int flags = 0;
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;
41  }
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);
56  else
57  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
58  }
59 
60  // Process
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);
65  plhs[0] = MxArray(flow);
66 }
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
Definition: mexopencv.hpp:159
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
Global constant definitions.