mexopencv  3.4.1
MEX interface for OpenCV library
buildOpticalFlowPyramid.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/video.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=1 && (nrhs%2)!=0 && nlhs<=2);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  Size winSize(21,21);
30  int maxLevel = 3;
31  bool withDerivatives = true;
32  int pyrBorder = cv::BORDER_REFLECT_101;
33  int derivBorder = cv::BORDER_CONSTANT;
34  bool tryReuseInputImage = true; // TODO: has no effect
35  for (int i=1; i<nrhs; i+=2) {
36  string key(rhs[i].toString());
37  if (key == "WinSize")
38  winSize = rhs[i+1].toSize();
39  else if (key == "MaxLevel")
40  maxLevel = rhs[i+1].toInt();
41  else if (key == "WithDerivatives")
42  withDerivatives = rhs[i+1].toBool();
43  else if (key == "PyrBorder")
44  pyrBorder = (rhs[i+1].isChar()) ?
45  BorderType[rhs[i+1].toString()] : rhs[i+1].toInt();
46  else if (key == "DerivBorder")
47  derivBorder = (rhs[i+1].isChar()) ?
48  BorderType[rhs[i+1].toString()] : rhs[i+1].toInt();
49  else if (key == "TryReuseInputImage")
50  tryReuseInputImage = rhs[i+1].toBool();
51  else
52  mexErrMsgIdAndTxt("mexopencv:error",
53  "Unrecognized option %s", key.c_str());
54  }
55 
56  // Process
57  Mat img(rhs[0].toMat(CV_8U));
58  vector<Mat> pyramid;
59  int maxLvl = buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel,
60  withDerivatives, pyrBorder, derivBorder, tryReuseInputImage);
61  plhs[0] = MxArray(pyramid);
62  if (nlhs > 1)
63  plhs[1] = MxArray(maxLvl);
64 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
BORDER_REFLECT_101
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:66
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
STL class.
Global constant definitions.
T c_str(T... args)
BORDER_CONSTANT
int buildOpticalFlowPyramid(InputArray img, OutputArrayOfArrays pyramid, Size winSize, int maxLevel, bool withDerivatives=true, int pyrBorder=BORDER_REFLECT_101, int derivBorder=BORDER_CONSTANT, bool tryReuseInputImage=true)
cv::Mat toMat() const