19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=3);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
28 vector<Point2f> nextPts;
31 TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01);
33 double minEigThreshold = 1e-4;
34 for (
int i=3; i<nrhs; i+=2) {
35 string key(rhs[i].toString());
36 if (key==
"InitialFlow") {
37 nextPts = rhs[i+1].toVector<Point2f>();
38 flags |= cv::OPTFLOW_USE_INITIAL_FLOW;
40 else if (key==
"WinSize")
41 winSize = rhs[i+1].toSize();
42 else if (key==
"MaxLevel")
43 maxLevel = rhs[i+1].toInt();
44 else if (key==
"Criteria")
45 criteria = rhs[i+1].toTermCriteria();
46 else if (key==
"GetMinEigenvals")
47 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::OPTFLOW_LK_GET_MIN_EIGENVALS);
48 else if (key==
"MinEigThreshold")
49 minEigThreshold = rhs[i+1].toDouble();
51 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
55 vector<Point2f> prevPts(rhs[2].toVector<Point2f>());
57 if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
59 Mat prevImg(rhs[0].toMat(CV_8U)),
60 nextImg(rhs[1].toMat(CV_8U));
61 calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status,
62 (nlhs>2 ? err : noArray()), winSize, maxLevel, criteria, flags,
65 else if (rhs[0].isCell() && rhs[1].isCell()) {
67 vector<Mat> prevImg(rhs[0].toVector<Mat>()),
68 nextImg(rhs[1].toVector<Mat>());
69 calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status,
70 (nlhs>2 ? err : noArray()), winSize, maxLevel, criteria, flags,
74 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid argument");
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.