mexopencv  0.1
mex interface for opencv library
calcOpticalFlowSF.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 layers = 3;
31  int averaging_block_size = 2;
32  int max_flow = 4;
33  double sigma_dist = 4.1;
34  double sigma_color = 25.5;
35  int postprocess_window = 18;
36  double sigma_dist_fix = 55.0;
37  double sigma_color_fix = 25.5;
38  double occ_thr = 0.35;
39  int upscale_averaging_radius = 18;
40  double upscale_sigma_dist = 55.0;
41  double upscale_sigma_color = 25.5;
42  double speed_up_thr = 10;
43  for (int i=2; i<nrhs; i+=2) {
44  string key(rhs[i].toString());
45  if (key == "Layers")
46  layers = rhs[i+1].toInt();
47  else if (key == "AveragingBlockSize")
48  averaging_block_size = rhs[i+1].toInt();
49  else if (key == "MaxFlow")
50  max_flow = rhs[i+1].toInt();
51  else if (key == "SigmaDist")
52  sigma_dist = rhs[i+1].toDouble();
53  else if (key == "SigmaColor")
54  sigma_color = rhs[i+1].toDouble();
55  else if (key == "PostprocessWindow")
56  postprocess_window = rhs[i+1].toInt();
57  else if (key == "SigmaDistFix")
58  sigma_dist_fix = rhs[i+1].toDouble();
59  else if (key == "SigmaColorFix")
60  sigma_color_fix = rhs[i+1].toDouble();
61  else if (key == "OccThr")
62  occ_thr = rhs[i+1].toDouble();
63  else if (key == "UpscaleAveragingRadius")
64  upscale_averaging_radius = rhs[i+1].toInt();
65  else if (key == "UpscaleSigmaDist")
66  upscale_sigma_dist = rhs[i+1].toDouble();
67  else if (key == "UpscaleSigmaColor")
68  upscale_sigma_color = rhs[i+1].toDouble();
69  else if (key == "SpeedUpThr")
70  speed_up_thr = rhs[i+1].toDouble();
71  else
72  mexErrMsgIdAndTxt("mexopencv:error",
73  "Unrecognized option %s", key.c_str());
74  }
75 
76  // Process
77  Mat from(rhs[0].toMat(CV_8U)),
78  to(rhs[1].toMat(CV_8U)),
79  flow;
80  if (from.channels()!=3 || to.channels()!=3)
81  mexErrMsgIdAndTxt("mexopencv:error", "3-channel images expected");
82  calcOpticalFlowSF(from, to, flow,
83  layers, averaging_block_size, max_flow,
84  sigma_dist, sigma_color, postprocess_window, sigma_dist_fix,
85  sigma_color_fix, occ_thr, upscale_averaging_radius,
86  upscale_sigma_dist, upscale_sigma_color, speed_up_thr);
87  plhs[0] = MxArray(flow);
88 }
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.