summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/lagrcv/calcOpticalFlowPyrLK.cc
diff options
context:
space:
mode:
authorLeo Chan <leochanj@live.unc.edu>2020-10-22 01:53:21 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-22 01:56:35 -0400
commitd17b33131c14864bd1eae275f49a3f148e21cf29 (patch)
tree0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/lagrcv/calcOpticalFlowPyrLK.cc
parent601ed25a4c5b66cb75315832c15613a727db2c26 (diff)
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to: - Use libextra to loop as realtime jobs - Preallocate memory before starting their main computation - Accept input via stdin instead of via argc Does not include the SD-VBS matlab code. Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/lagrcv/calcOpticalFlowPyrLK.cc')
-rwxr-xr-xSD-VBS/common/toolbox/lagrcv/calcOpticalFlowPyrLK.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/lagrcv/calcOpticalFlowPyrLK.cc b/SD-VBS/common/toolbox/lagrcv/calcOpticalFlowPyrLK.cc
new file mode 100755
index 0000000..d4be5ff
--- /dev/null
+++ b/SD-VBS/common/toolbox/lagrcv/calcOpticalFlowPyrLK.cc
@@ -0,0 +1,77 @@
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 8
13#define PYR_LEVELS 3
14
15void 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 IplImage *pyr1 = 0, *pyr2 = 0;
25 int flags = 0;
26 bool clearPyr1 = false;
27 int max_iter;
28
29 max_iter=30;
30
31 /* images */
32 IplImage *im1 =
33 cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_8U, 1);
34 IplImage *im2 =
35 cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_8U, 1);
36 im1->imageData = im1_ptr;
37 im2->imageData = im2_ptr;
38
39 /* allocate pyramids */
40 pyr1 = cvCreateImageHeader(cvSize(imdims[0],imdims[1]), IPL_DEPTH_8U, 1);
41 pyr2 = cvCreateImageHeader(cvSize(imdims[0],imdims[1]), IPL_DEPTH_8U, 1);
42 // reuse pyramid if given
43 if (nrhs > 3) {
44 pyr1->imageData = (char*)mxGetPr(prhs[3]);
45 flags |= CV_LKFLOW_PYR_A_READY;
46 } else {
47 clearPyr1 = true;
48 cvCreateData(pyr1);
49 }
50
51 // pyr2 will be reused, so allocate in return value
52 plhs[2] = mxCreateNumericMatrix(imdims[0], imdims[1], mxUINT8_CLASS, mxREAL);
53 pyr2->imageData = (char*)mxGetPr(plhs[2]);
54
55 /* coordinate arrays */
56 CvPoint2D32f *oldpoints = (CvPoint2D32f*)mxGetPr(prhs[2]);
57 const int *pointsdim = mxGetDimensions(prhs[2]);
58 int npoints = pointsdim[1];
59 plhs[0] = mxCreateNumericMatrix(2, npoints, mxSINGLE_CLASS, mxREAL);
60 CvPoint2D32f *newpoints = (CvPoint2D32f*)mxGetPr(plhs[0]);
61
62 /* status array */
63 plhs[1] = mxCreateNumericMatrix(1, npoints, mxUINT8_CLASS, mxREAL);
64 char *status = (char*)mxGetPr(plhs[1]);
65
66 cvCalcOpticalFlowPyrLK(im1, im2,
67 pyr1, pyr2,
68 oldpoints, newpoints, npoints,
69 cvSize(WIN_SIZE, WIN_SIZE), PYR_LEVELS,
70 status,
71 NULL,
72 cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,max_iter,0.03),
73 flags
74 );
75 if (clearPyr1)
76 cvReleaseImage(&pyr1);
77}