9 #include "opencv2/optflow.hpp" 21 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
24 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
27 vector<MxArray> rhs(prhs, prhs+nrhs);
31 int averaging_block_size = 2;
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());
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();
72 mexErrMsgIdAndTxt(
"mexopencv:error",
73 "Unrecognized option %s", key.c_str());
77 Mat from(rhs[0].toMat(CV_8U)),
78 to(rhs[1].toMat(CV_8U)),
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);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.