diff options
Diffstat (limited to 'SD-VBS/common/toolbox/lagrcv/calcOptFlowLKPyrMex.cc')
-rwxr-xr-x | SD-VBS/common/toolbox/lagrcv/calcOptFlowLKPyrMex.cc | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/lagrcv/calcOptFlowLKPyrMex.cc b/SD-VBS/common/toolbox/lagrcv/calcOptFlowLKPyrMex.cc new file mode 100755 index 0000000..56ab3d0 --- /dev/null +++ b/SD-VBS/common/toolbox/lagrcv/calcOptFlowLKPyrMex.cc | |||
@@ -0,0 +1,99 @@ | |||
1 | |||
2 | /* compile with | ||
3 | rm liblagrcv.a | ||
4 | gcc -c lagrcv.cpp | ||
5 | ar rc liblagrcv.a lagrcv.o | ||
6 | ranlib liblagrcv.a | ||
7 | mex7 calcTextureMex.cc -L/home/ikkjin/LagrMatlab/opencv/matlab -llagrcv -I/home/ikkjin/LagrMatlab/opencv/matlab/ | ||
8 | */ | ||
9 | |||
10 | #include "mex.h" | ||
11 | #include "lagrcv.h" | ||
12 | #include <stdio.h> | ||
13 | #include <math.h> | ||
14 | |||
15 | #ifndef MAX_LEVEL | ||
16 | # define MAX_LEVEL 5 | ||
17 | #endif | ||
18 | // TODO: add number of corners parameter | ||
19 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { | ||
20 | // usage: [newFeaturePnt validFlag ] = | ||
21 | // calcOptFlowPyrLKMex(Ipyr, IdxPyr, IdyPyr, Jpyr, featurePnt, winSize, accuracy_th, max_iter) | ||
22 | // Ipyr, IdxPyr, IdyPyr, Jpyr: levelx1 size cell. | ||
23 | // featurePnt 2xn int | ||
24 | // winSize c_level int | ||
25 | // c_xx c_xy c_yy: image size double* | ||
26 | // image must be double | ||
27 | |||
28 | |||
29 | const mxArray* imgArray; | ||
30 | int* imdims; | ||
31 | const int *curImgDims; | ||
32 | const int *nFeatures; | ||
33 | //double **iP, **iDxP, **iDyP, **jP; | ||
34 | double *iP[MAX_LEVEL], *iDxP[MAX_LEVEL], *iDyP[MAX_LEVEL], *jP[MAX_LEVEL]; | ||
35 | double *fPnt, *newFPnt; | ||
36 | char* valid; | ||
37 | double accuracy_th; | ||
38 | int winSize, max_iter; | ||
39 | const int *cellDims = mxGetDimensions(prhs[0]); | ||
40 | |||
41 | if (nrhs > 6) { | ||
42 | accuracy_th=(double)mxGetScalar(prhs[6]); | ||
43 | max_iter=(int)mxGetScalar(prhs[7]); | ||
44 | } | ||
45 | |||
46 | winSize = (int)mxGetScalar(prhs[5]); | ||
47 | fPnt=(double*)mxGetPr(prhs[4]); | ||
48 | nFeatures=mxGetDimensions(prhs[4]); | ||
49 | |||
50 | imdims=(int*)malloc(sizeof(int)*cellDims[0]*2); | ||
51 | //iP=(double**)malloc(sizeof(double*)*cellDims[0]); | ||
52 | //iDxP=(double**)malloc(sizeof(double*)*cellDims[0]); | ||
53 | //iDyP=(double**)malloc(sizeof(double*)*cellDims[0]); | ||
54 | //jP=(double**)malloc(sizeof(double*)*cellDims[0]); | ||
55 | |||
56 | for(int i=0; i<cellDims[0]; i++){ | ||
57 | //imgArray=mxGetCell(prhs[0],i); | ||
58 | //curImgDims = mxGetDimensions(imgArray); | ||
59 | curImgDims = mxGetDimensions(mxGetCell(prhs[0],i)); | ||
60 | imdims[i*2+0]= curImgDims[0]; | ||
61 | imdims[i*2+1]= curImgDims[1]; | ||
62 | //imdims[i][1] = curImgDims[1]; | ||
63 | |||
64 | iP[i]= (double*)mxGetPr(mxGetCell(prhs[0],i)); | ||
65 | iDxP[i]= (double*)mxGetPr(mxGetCell(prhs[1],i)); | ||
66 | iDyP[i]= (double*)mxGetPr(mxGetCell(prhs[2],i)); | ||
67 | jP[i]= (double*)mxGetPr(mxGetCell(prhs[3],i)); | ||
68 | } | ||
69 | |||
70 | plhs[0] = mxCreateNumericMatrix(nFeatures[0], nFeatures[1], mxDOUBLE_CLASS, mxREAL); | ||
71 | plhs[1] = mxCreateNumericMatrix(1, nFeatures[1], mxUINT8_CLASS, mxREAL); | ||
72 | |||
73 | newFPnt = (double*)mxGetPr(plhs[0]); | ||
74 | valid = (char*)mxGetPr(plhs[1]); | ||
75 | |||
76 | //idx convert from matlab to c | ||
77 | for(int i=0; i<nFeatures[1]; i++){ | ||
78 | fPnt[i*2]=fPnt[i*2]-1; | ||
79 | fPnt[i*2+1]=fPnt[i*2+1]-1; | ||
80 | valid[i]=1; | ||
81 | } | ||
82 | if(nrhs>6){ | ||
83 | calcPyrLKTrack( iP, iDxP, iDyP, jP, imdims, cellDims[0], fPnt, nFeatures[1], winSize, | ||
84 | newFPnt, valid, accuracy_th, max_iter); | ||
85 | }else{ | ||
86 | calcPyrLKTrack( iP, iDxP, iDyP, jP, imdims, cellDims[0], fPnt, nFeatures[1], winSize, | ||
87 | newFPnt, valid); | ||
88 | } | ||
89 | //idx convert from matlab to c | ||
90 | for(int i=0; i<nFeatures[1]*2; i++){ | ||
91 | fPnt[i]=fPnt[i]+1; | ||
92 | newFPnt[i]=newFPnt[i]+1; | ||
93 | } | ||
94 | free(imdims); | ||
95 | //free(iP); | ||
96 | //free(iDxP); | ||
97 | //free(iDyP); | ||
98 | //free(jP); | ||
99 | } | ||