mexopencv  3.4.1
MEX interface for OpenCV library
calcOpticalFlowSparseToDense.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/optflow.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::optflow;
13 
21 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
22 {
23  // Check the number of arguments
24  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
25 
26  // Argument vector
27  vector<MxArray> rhs(prhs, prhs+nrhs);
28 
29  // Option processing
30  int grid_step = 8;
31  int k = 128;
32  float sigma = 0.05f;
33  bool use_post_proc = true;
34  float fgs_lambda = 500.0f;
35  float fgs_sigma = 1.5f;
36  for (int i=2; i<nrhs; i+=2) {
37  string key(rhs[i].toString());
38  if (key == "GridStep")
39  grid_step = rhs[i+1].toInt();
40  else if (key == "K")
41  k = rhs[i+1].toInt();
42  else if (key == "Sigma")
43  sigma = rhs[i+1].toFloat();
44  else if (key == "UsePostProcessing")
45  use_post_proc = rhs[i+1].toBool();
46  else if (key == "FGSLambda")
47  fgs_lambda = rhs[i+1].toFloat();
48  else if (key == "FGSSigma")
49  fgs_sigma = rhs[i+1].toFloat();
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s", key.c_str());
53  }
54 
55  // Process
56  Mat from(rhs[0].toMat(CV_8U)), to(rhs[1].toMat(CV_8U)), flow;
57  calcOpticalFlowSparseToDense(from, to, flow,
58  grid_step, k, sigma, use_post_proc, fgs_lambda, fgs_sigma);
59  plhs[0] = MxArray(flow);
60 }
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
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...
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
STL class.
Global constant definitions.
void calcOpticalFlowSparseToDense(InputArray from, InputArray to, OutputArray flow, int grid_step=8, int k=128, float sigma=0.05f, bool use_post_proc=true, float fgs_lambda=500.0f, float fgs_sigma=1.5f)
T c_str(T... args)
cv::Mat toMat() const