diff options
Diffstat (limited to 'SD-VBS/common/toolbox/lagrcv/calcOpticalFlowLK.cc')
| -rwxr-xr-x | SD-VBS/common/toolbox/lagrcv/calcOpticalFlowLK.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/lagrcv/calcOpticalFlowLK.cc b/SD-VBS/common/toolbox/lagrcv/calcOpticalFlowLK.cc new file mode 100755 index 0000000..150bae3 --- /dev/null +++ b/SD-VBS/common/toolbox/lagrcv/calcOpticalFlowLK.cc | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | |||
| 2 | /* compile with | ||
| 3 | mex calcOpticalFlowPyrLK.cc -I/usr/local/opencv/include -L/usr/local/opencv/lib -lcxcore -lcv | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include "mex.h" | ||
| 7 | #include "opencv/cv.h" | ||
| 8 | #include "opencv/highgui.h" | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <math.h> | ||
| 11 | |||
| 12 | #define WIN_SIZE 10 | ||
| 13 | #define PYR_LEVELS 3 | ||
| 14 | |||
| 15 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { | ||
| 16 | // usage: [ newpoints status pyr1 ] = | ||
| 17 | // calcOpticalFlowPyrLK(im1,im2,oldpoints,pyr1) | ||
| 18 | // images must be single-channel, 8-bit | ||
| 19 | // DO NOT PASS SAME IMAGE IN TWICE! | ||
| 20 | |||
| 21 | char *im1_ptr = (char*)mxGetPr(prhs[0]); | ||
| 22 | char *im2_ptr = (char*)mxGetPr(prhs[1]); | ||
| 23 | const int *imdims = mxGetDimensions(prhs[0]); | ||
| 24 | int flags = 0; | ||
| 25 | int max_iter; | ||
| 26 | |||
| 27 | if(nrhs>3){ | ||
| 28 | max_iter=(int)mxGetScalar(prhs[3]); | ||
| 29 | }else{ | ||
| 30 | max_iter=20; | ||
| 31 | } | ||
| 32 | |||
| 33 | /* images */ | ||
| 34 | IplImage *im1 = | ||
| 35 | cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_8U, 1); | ||
| 36 | IplImage *im2 = | ||
| 37 | cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_8U, 1); | ||
| 38 | im1->imageData = im1_ptr; | ||
| 39 | im2->imageData = im2_ptr; | ||
| 40 | |||
| 41 | /* coordinate arrays */ | ||
| 42 | CvPoint2D32f *oldpoints = (CvPoint2D32f*)mxGetPr(prhs[2]); | ||
| 43 | const int *pointsdim = mxGetDimensions(prhs[2]); | ||
| 44 | int npoints = pointsdim[1]; | ||
| 45 | plhs[0] = mxCreateNumericMatrix(2, npoints, mxSINGLE_CLASS, mxREAL); | ||
| 46 | CvPoint2D32f *newpoints = (CvPoint2D32f*)mxGetPr(plhs[0]); | ||
| 47 | |||
| 48 | /* status array */ | ||
| 49 | plhs[1] = mxCreateNumericMatrix(1, npoints, mxUINT8_CLASS, mxREAL); | ||
| 50 | char *status = (char*)mxGetPr(plhs[1]); | ||
| 51 | |||
| 52 | cvCalcOpticalFlowLK(im1, im2, | ||
| 53 | cvSize(WIN_SIZE, WIN_SIZE), velx, vely | ||
| 54 | status, | ||
| 55 | NULL, | ||
| 56 | cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,max_iter,0.03), | ||
| 57 | flags | ||
| 58 | ); | ||
| 59 | } | ||
