mexopencv  0.1
mex interface for opencv library
buildOpticalFlowPyramid.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>=1 && (nrhs%2)!=0 && nlhs<=2);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  Size winSize(21,21);
29  int maxLevel = 3;
30  bool withDerivatives = true;
31  int pyrBorder = cv::BORDER_REFLECT_101;
32  int derivBorder = cv::BORDER_CONSTANT;
33  bool tryReuseInputImage = true; // TODO: has no effect
34  for (int i=1; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key == "WinSize")
37  winSize = rhs[i+1].toSize();
38  else if (key == "MaxLevel")
39  maxLevel = rhs[i+1].toInt();
40  else if (key == "WithDerivatives")
41  withDerivatives = rhs[i+1].toBool();
42  else if (key == "PyrBorder")
43  pyrBorder = (rhs[i+1].isChar()) ?
44  BorderType[rhs[i+1].toString()] : rhs[i+1].toInt();
45  else if (key == "DerivBorder")
46  derivBorder = (rhs[i+1].isChar()) ?
47  BorderType[rhs[i+1].toString()] : rhs[i+1].toInt();
48  else if (key == "TryReuseInputImage")
49  tryReuseInputImage = rhs[i+1].toBool();
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s", key.c_str());
53  }
54 
55  // Process
56  Mat img(rhs[0].toMat(CV_8U));
57  vector<Mat> pyramid;
58  int maxLvl = buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel,
59  withDerivatives, pyrBorder, derivBorder, tryReuseInputImage);
60  plhs[0] = MxArray(pyramid);
61  if (nlhs > 1)
62  plhs[1] = MxArray(maxLvl);
63 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:52
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.