diff options
author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
---|---|---|
committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/common/toolbox/lagrcv/calcOptFlowLKMex.cc | |
parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/common/toolbox/lagrcv/calcOptFlowLKMex.cc')
-rwxr-xr-x | SD-VBS/common/toolbox/lagrcv/calcOptFlowLKMex.cc | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/lagrcv/calcOptFlowLKMex.cc b/SD-VBS/common/toolbox/lagrcv/calcOptFlowLKMex.cc new file mode 100755 index 0000000..e22af8b --- /dev/null +++ b/SD-VBS/common/toolbox/lagrcv/calcOptFlowLKMex.cc | |||
@@ -0,0 +1,85 @@ | |||
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 | // calcOptFlowLKMex(I, Idx, Idy, J, c_xx, c_xy, c_yy, featurePnt, initialPnt, winSize, accuracy_th, max_iter) | ||
22 | // featurePnt 2xn int | ||
23 | // winSize c_level int | ||
24 | // c_xx c_xy c_yy: image size double* | ||
25 | // image must be double | ||
26 | |||
27 | |||
28 | const int* imdims; | ||
29 | const int *nFeatures; | ||
30 | double *imgI, *iDx, *iDy, *imgJ, *c_xx, *c_xy, *c_yy; | ||
31 | double *fPnt, *initPnt, *newFPnt; | ||
32 | char* valid; | ||
33 | double accuracy_th; | ||
34 | int winSize, max_iter; | ||
35 | |||
36 | if (nrhs > 10) { | ||
37 | accuracy_th=(double)mxGetScalar(prhs[10]); | ||
38 | max_iter=(int)mxGetScalar(prhs[11]); | ||
39 | } | ||
40 | |||
41 | winSize = (int)mxGetScalar(prhs[9]); | ||
42 | initPnt=(double*)mxGetPr(prhs[8]); | ||
43 | fPnt=(double*)mxGetPr(prhs[7]); | ||
44 | c_xx=(double*)mxGetPr(prhs[6]); | ||
45 | c_xy=(double*)mxGetPr(prhs[5]); | ||
46 | c_yy=(double*)mxGetPr(prhs[4]); | ||
47 | imgJ=(double*)mxGetPr(prhs[3]); | ||
48 | iDy=(double*)mxGetPr(prhs[2]); | ||
49 | iDx=(double*)mxGetPr(prhs[1]); | ||
50 | imgI=(double*)mxGetPr(prhs[0]); | ||
51 | nFeatures=mxGetDimensions(prhs[7]); | ||
52 | imdims=mxGetDimensions(prhs[0]); | ||
53 | |||
54 | plhs[0] = mxCreateNumericMatrix(nFeatures[0], nFeatures[1], mxDOUBLE_CLASS, mxREAL); | ||
55 | plhs[1] = mxCreateNumericMatrix(1, nFeatures[1], mxUINT8_CLASS, mxREAL); | ||
56 | |||
57 | newFPnt = (double*)mxGetPr(plhs[0]); | ||
58 | valid = (char*)mxGetPr(plhs[1]); | ||
59 | |||
60 | //idx convert from matlab to c | ||
61 | for(int i=0; i<nFeatures[1]; i++){ | ||
62 | fPnt[i*2]=fPnt[i*2]-1; | ||
63 | fPnt[i*2+1]=fPnt[i*2+1]-1; | ||
64 | initPnt[i*2]=initPnt[i*2]-1; | ||
65 | initPnt[i*2+1]=initPnt[i*2+1]-1; | ||
66 | valid[i]=1; | ||
67 | } | ||
68 | if(nrhs>10){ | ||
69 | calcLKTrack( imgI, iDx, iDy, imgJ, imdims, | ||
70 | c_xx, c_xy, c_yy, | ||
71 | fPnt, initPnt, nFeatures[1], winSize, | ||
72 | newFPnt, valid, accuracy_th, max_iter); | ||
73 | }else{ | ||
74 | calcLKTrack( imgI, iDx, iDy, imgJ, imdims, | ||
75 | c_xx, c_xy, c_yy, | ||
76 | fPnt, initPnt, nFeatures[1], winSize, | ||
77 | newFPnt, valid); | ||
78 | } | ||
79 | //idx convert from matlab to c | ||
80 | for(int i=0; i<nFeatures[1]*2; i++){ | ||
81 | fPnt[i]=fPnt[i]+1; | ||
82 | initPnt[i]=initPnt[i]+1; | ||
83 | newFPnt[i]=newFPnt[i]+1; | ||
84 | } | ||
85 | } | ||