diff options
Diffstat (limited to 'SD-VBS/benchmarks/tracking/src')
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c | 81 | ||||
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/calcGoodFeature.c | 78 | ||||
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/calcPyrLKTrack.c | 179 | ||||
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/fillFeatures.c | 67 | ||||
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/getANMS.c | 156 | ||||
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/getInterpolatePatch.c | 43 | ||||
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/script_tracking.c | 263 | ||||
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/tracking.h | 20 |
8 files changed, 887 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c b/SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c new file mode 100644 index 0000000..40f03dc --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "tracking.h" | ||
6 | |||
7 | /** Compute the sum of pixels over pixel neighborhood. | ||
8 | Neighborhood = winSize*winSize | ||
9 | This will be useful when we compute the displacement | ||
10 | of the neighborhood across frames instead of tracking each pixel. | ||
11 | |||
12 | Input: src Image | ||
13 | # rows, cols, size of window | ||
14 | Output: windowed-sum image, ret. | ||
15 | |||
16 | Example: | ||
17 | |||
18 | winSize = 4, cols = 8, rows = 16 | ||
19 | nave_half = 2, nave = 4 | ||
20 | Say, the first row of the image is: | ||
21 | 3 8 6 2 4 8 9 5 | ||
22 | a1 = 0 0 3 8 6 2 4 8 9 5 0 0 (append nave_half zeros to left and right border) | ||
23 | asum = (sum the first nave # pixels - 0 0 3 8 ) = 11 | ||
24 | ret(0,0) = 11 | ||
25 | For ret(0,1), we need to move the window to the right by one pixel and subtract | ||
26 | from a1sum the leftmost pixel. So, we add value 6 and subtract value at a1(0,0), = 0 here. | ||
27 | ret(0,1) = 17 = a1sum | ||
28 | For ret(0,2), a1sum - a1(0,1) + a1(2+nave) = 17 - 0 + 2 = 19 = a1sum | ||
29 | For ret(0,3), a1sum - a1(0,2) + a1(3+nave) = 19 - 3 + 4 = 20 = a1sum | ||
30 | |||
31 | We proceed this way for all the rows and then perform summantion across all cols. | ||
32 | **/ | ||
33 | F2D* calcAreaSum(F2D* src, int cols, int rows, int winSize) | ||
34 | { | ||
35 | int nave, nave_half, i, j, k; | ||
36 | F2D *ret, *a1; | ||
37 | float a1sum; | ||
38 | |||
39 | nave = winSize; | ||
40 | nave_half = floor((nave+1)/2); | ||
41 | |||
42 | ret = fMallocHandle(rows, cols); | ||
43 | a1 = fSetArray(1, cols+nave,0); | ||
44 | |||
45 | for(i=0; i<rows; i++) | ||
46 | { | ||
47 | for(j=0; j<cols; j++) { | ||
48 | asubsref(a1,j+nave_half) = subsref(src,i,j); | ||
49 | } | ||
50 | a1sum = 0; | ||
51 | for(k=0; k<nave; k++) { | ||
52 | a1sum += asubsref(a1,k); | ||
53 | } | ||
54 | for(j=0; j<cols; j++) | ||
55 | { | ||
56 | subsref(ret,i,j) = a1sum; | ||
57 | a1sum += asubsref(a1,j+nave) - asubsref(a1,j); | ||
58 | } | ||
59 | } | ||
60 | fFreeHandle(a1); | ||
61 | |||
62 | a1 = fSetArray(1, rows+nave,0); | ||
63 | for(i=0; i<cols; i++) | ||
64 | { | ||
65 | for(j=0; j<rows; j++) { | ||
66 | asubsref(a1,j+nave_half) = subsref(ret,j,i); | ||
67 | } | ||
68 | a1sum = 0; | ||
69 | for(k=0; k<nave; k++) { | ||
70 | a1sum += asubsref(a1,k); | ||
71 | } | ||
72 | for(j=0; j<rows; j++) | ||
73 | { | ||
74 | subsref(ret,j,i) = a1sum; | ||
75 | a1sum += asubsref(a1,j+nave) - asubsref(a1,j); | ||
76 | } | ||
77 | } | ||
78 | fFreeHandle(a1); | ||
79 | |||
80 | return ret; | ||
81 | } | ||
diff --git a/SD-VBS/benchmarks/tracking/src/c/calcGoodFeature.c b/SD-VBS/benchmarks/tracking/src/c/calcGoodFeature.c new file mode 100644 index 0000000..0ef1862 --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/calcGoodFeature.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "tracking.h" | ||
6 | |||
7 | /** Computes lambda matrix, strength at each pixel | ||
8 | |||
9 | det = determinant( [ IverticalEdgeSq IhorzVertEdge; IhorzVertEdge IhorizontalEdgeSq] ) ; | ||
10 | tr = IverticalEdgeSq + IhorizontalEdgeSq; | ||
11 | lamdba = det/tr; | ||
12 | |||
13 | Lambda is the measure of the strength of pixel | ||
14 | neighborhood. By strength we mean the amount of | ||
15 | edge information it has, which translates to | ||
16 | sharp features in the image. | ||
17 | |||
18 | Input: Edge images - vertical and horizontal | ||
19 | Window size (neighborhood size) | ||
20 | Output: Lambda, strength of pixel neighborhood | ||
21 | |||
22 | Given the edge images, we compute strength based | ||
23 | on how strong the edges are within each neighborhood. | ||
24 | |||
25 | **/ | ||
26 | |||
27 | F2D* calcGoodFeature(F2D* verticalEdgeImage, F2D* horizontalEdgeImage, int cols, int rows, int winSize) | ||
28 | { | ||
29 | int i, j, k, ind; | ||
30 | F2D *verticalEdgeSq, *horizontalEdgeSq, *horzVertEdge; | ||
31 | F2D *tr, *det, *lambda; | ||
32 | F2D *cummulative_verticalEdgeSq, *cummulative_horzVertEdge, *cummulative_horizontalEdgeSq; | ||
33 | |||
34 | verticalEdgeSq = fMallocHandle(rows, cols); | ||
35 | horzVertEdge = fMallocHandle(rows, cols); | ||
36 | horizontalEdgeSq = fMallocHandle(rows, cols); | ||
37 | |||
38 | for( i=0; i<rows; i++) | ||
39 | { | ||
40 | for( j=0; j<cols; j++) | ||
41 | { | ||
42 | subsref(verticalEdgeSq,i,j) = subsref(verticalEdgeImage,i,j) * subsref(verticalEdgeImage,i,j); | ||
43 | subsref(horzVertEdge,i,j) = subsref(verticalEdgeImage,i,j) * subsref(horizontalEdgeImage,i,j); | ||
44 | subsref(horizontalEdgeSq,i,j) = subsref(horizontalEdgeImage,i,j) * subsref(horizontalEdgeImage,i,j); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | cummulative_verticalEdgeSq = calcAreaSum(verticalEdgeSq, cols, rows, winSize); | ||
49 | cummulative_horzVertEdge = calcAreaSum(horzVertEdge, cols, rows, winSize); | ||
50 | cummulative_horizontalEdgeSq = calcAreaSum(horizontalEdgeSq, cols, rows, winSize); | ||
51 | |||
52 | tr = fMallocHandle(rows, cols); | ||
53 | det = fMallocHandle(rows, cols); | ||
54 | lambda = fMallocHandle(rows, cols); | ||
55 | |||
56 | for( i=0; i<rows; i++) | ||
57 | { | ||
58 | for( j=0; j<cols; j++) | ||
59 | { | ||
60 | subsref(tr,i,j) = subsref(cummulative_verticalEdgeSq,i,j) + subsref(cummulative_horizontalEdgeSq,i,j); | ||
61 | subsref(det,i,j) = subsref(cummulative_verticalEdgeSq,i,j) * subsref(cummulative_horizontalEdgeSq,i,j) - subsref(cummulative_horzVertEdge,i,j) * subsref(cummulative_horzVertEdge,i,j); | ||
62 | subsref(lambda,i,j) = ( subsref(det,i,j) / (subsref(tr,i,j)+0.00001) ) ; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | fFreeHandle(verticalEdgeSq); | ||
67 | fFreeHandle(horzVertEdge); | ||
68 | fFreeHandle(horizontalEdgeSq); | ||
69 | |||
70 | fFreeHandle(cummulative_verticalEdgeSq); | ||
71 | fFreeHandle(cummulative_horzVertEdge); | ||
72 | fFreeHandle(cummulative_horizontalEdgeSq); | ||
73 | |||
74 | fFreeHandle(tr); | ||
75 | fFreeHandle(det); | ||
76 | |||
77 | return lambda; | ||
78 | } | ||
diff --git a/SD-VBS/benchmarks/tracking/src/c/calcPyrLKTrack.c b/SD-VBS/benchmarks/tracking/src/c/calcPyrLKTrack.c new file mode 100644 index 0000000..3718673 --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/calcPyrLKTrack.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "tracking.h" | ||
6 | |||
7 | /** calcPyrLKTrack tries to find the displacement (translation in x and y) of features computed in the previous frame. | ||
8 | To compute the displacement, we interpolate the existing feature position around the pixel neighborhood. | ||
9 | For better results, we perform interpolatations across all pyramid levels. | ||
10 | |||
11 | Input: Previous frame blurred images, vertical and horizontal | ||
12 | Current frame edge images, vertical and horizontal | ||
13 | Current frame blurred images, for level 0 and 1 | ||
14 | Number of features from previous frame | ||
15 | Window size | ||
16 | Accuracy | ||
17 | Number of iterations to compute motion vector | ||
18 | Features from the previous frame | ||
19 | currentFrameFeatures, Populate the current frame features' displacements | ||
20 | Output: Number of valid features | ||
21 | |||
22 | **/ | ||
23 | |||
24 | I2D* calcPyrLKTrack(F2D* previousImageBlur_level1, F2D* previousImageBlur_level2, F2D* vertEdge_level1, F2D* vertEdge_level2, F2D* horzEdge_level1, F2D* horzEdge_level2, F2D* currentImageBlur_level1, F2D* currentImageBlur_level2, F2D* previousFrameFeatures, int nFeatures, int winSize, float accuracy, int max_iter, F2D* currentFrameFeatures) | ||
25 | { | ||
26 | int idx, level, pLevel, i, j, k, winSizeSq; | ||
27 | I2D *valid; | ||
28 | F2D *rate, *iPatch, *jPatch, *iDxPatch; | ||
29 | F2D *iDyPatch; | ||
30 | float tr, x, y, dX, dY, c_xx, c_yy, c_xy; | ||
31 | int imgSize_1, imgSize_2; | ||
32 | float mX, mY, dIt, eX, eY, c_det; | ||
33 | I2D *imgDims; | ||
34 | |||
35 | imgDims = iMallocHandle(2, 2); | ||
36 | subsref(imgDims,0,0) = previousImageBlur_level1->height; | ||
37 | subsref(imgDims,0,1) = previousImageBlur_level1->width; | ||
38 | subsref(imgDims,1,0) = previousImageBlur_level2->height; | ||
39 | subsref(imgDims,1,1) = previousImageBlur_level2->width; | ||
40 | |||
41 | pLevel = 2; | ||
42 | rate = fMallocHandle(1, 6); | ||
43 | |||
44 | asubsref(rate,0) = 1; | ||
45 | asubsref(rate,1) = 0.5; | ||
46 | asubsref(rate,2) = 0.25; | ||
47 | asubsref(rate,3) = 0.125; | ||
48 | asubsref(rate,4) = 0.0625; | ||
49 | asubsref(rate,5) = 0.03125; | ||
50 | |||
51 | winSizeSq = 4*winSize*winSize; | ||
52 | valid = iSetArray(1,nFeatures, 1); | ||
53 | |||
54 | /** For each feature passed from previous frame, compute the dx and dy, the displacements **/ | ||
55 | for(i=0; i<nFeatures; i++) | ||
56 | { | ||
57 | dX = 0; | ||
58 | dY = 0; | ||
59 | |||
60 | /** Compute the x and y co-ordinate values at "pLevel" **/ | ||
61 | x = subsref(previousFrameFeatures,0,i) * asubsref(rate,pLevel); | ||
62 | y = subsref(previousFrameFeatures,1,i) * asubsref(rate,pLevel); | ||
63 | c_det = 0; | ||
64 | |||
65 | /** For each pyramid level, try to find correspondence. | ||
66 | We look for the correspondence in a given window size | ||
67 | , (winSize x winSize) neighborhood **/ | ||
68 | for(level = pLevel-1; level>=0; level--) | ||
69 | { | ||
70 | x = x+x; | ||
71 | y = y+y; | ||
72 | dX = dX + dX; | ||
73 | dY = dY + dY; | ||
74 | imgSize_1 = subsref(imgDims,level,0); | ||
75 | imgSize_2 = subsref(imgDims,level,1); | ||
76 | |||
77 | c_xx = 0; | ||
78 | c_xy = 0; | ||
79 | c_yy = 0; | ||
80 | |||
81 | if((x-winSize)<0 || (y-winSize)<0 || (y+winSize+1)>=imgSize_1 || (x+winSize+1)>=imgSize_2) | ||
82 | { | ||
83 | asubsref(valid,i) = 0; | ||
84 | break; | ||
85 | } | ||
86 | |||
87 | /** Perform interpolation. Use co-ord from previous | ||
88 | frame and use the images from current frame **/ | ||
89 | |||
90 | if(level ==0) | ||
91 | { | ||
92 | iPatch = getInterpolatePatch(previousImageBlur_level1, imgSize_2, x, y, winSize); | ||
93 | iDxPatch = getInterpolatePatch(vertEdge_level1, imgSize_2, x, y, winSize); | ||
94 | iDyPatch = getInterpolatePatch(horzEdge_level1, imgSize_2, x, y, winSize); | ||
95 | } | ||
96 | if(level ==1) | ||
97 | { | ||
98 | iPatch = getInterpolatePatch(previousImageBlur_level2, imgSize_2, x, y, winSize); | ||
99 | iDxPatch = getInterpolatePatch(vertEdge_level2, imgSize_2, x, y, winSize); | ||
100 | iDyPatch = getInterpolatePatch(horzEdge_level2, imgSize_2, x, y, winSize); | ||
101 | } | ||
102 | |||
103 | /** Compute feature strength in similar way as calcGoodFeature **/ | ||
104 | for(idx=0; idx<winSizeSq; idx++) | ||
105 | { | ||
106 | c_xx += asubsref(iDxPatch,idx) * asubsref(iDxPatch,idx); | ||
107 | c_xy += asubsref(iDxPatch,idx) * asubsref(iDyPatch,idx); | ||
108 | c_yy += asubsref(iDyPatch,idx) * asubsref(iDyPatch,idx); | ||
109 | } | ||
110 | |||
111 | c_det = (c_xx * c_yy -c_xy * c_xy); | ||
112 | tr = c_xx + c_yy; | ||
113 | |||
114 | if((c_det/(tr+0.00001)) < accuracy) | ||
115 | { | ||
116 | asubsref(valid,i) = 0; | ||
117 | fFreeHandle(iPatch); | ||
118 | fFreeHandle(iDxPatch); | ||
119 | fFreeHandle(iDyPatch); | ||
120 | break; | ||
121 | } | ||
122 | c_det = 1/c_det; | ||
123 | |||
124 | /** We compute dX and dY using previous frame and current | ||
125 | frame images. For this, the strength is computed at each | ||
126 | pixel in the new image. **/ | ||
127 | for(k=0; k<max_iter; k++) | ||
128 | { | ||
129 | if( (x+dX-winSize)<0 || (y+dY-winSize)<0 || (y+dY+winSize+1)>=imgSize_1 || (x+dX+winSize+1)>=imgSize_2) | ||
130 | { | ||
131 | asubsref(valid,i) = 0; | ||
132 | break; | ||
133 | } | ||
134 | |||
135 | if(level == 0) | ||
136 | jPatch = getInterpolatePatch(currentImageBlur_level1, imgSize_2, x+dX, y+dY, winSize); | ||
137 | if(level == 1) | ||
138 | jPatch = getInterpolatePatch(currentImageBlur_level2, imgSize_2, x+dX, y+dY, winSize); | ||
139 | |||
140 | eX = 0; | ||
141 | eY = 0; | ||
142 | for(idx=0; idx<winSizeSq; idx++) | ||
143 | { | ||
144 | dIt = asubsref(iPatch,idx) - asubsref(jPatch,idx); | ||
145 | eX += dIt * asubsref(iDxPatch,idx); | ||
146 | eY += dIt * asubsref(iDyPatch,idx); | ||
147 | } | ||
148 | |||
149 | mX = c_det * (eX * c_yy - eY * c_xy); | ||
150 | mY = c_det * (-eX * c_xy + eY * c_xx); | ||
151 | dX = dX + mX; | ||
152 | dY = dY + mY; | ||
153 | |||
154 | if( (mX*mX+mY*mY) < accuracy) | ||
155 | { | ||
156 | fFreeHandle(jPatch); | ||
157 | break; | ||
158 | } | ||
159 | |||
160 | fFreeHandle(jPatch); | ||
161 | } | ||
162 | |||
163 | fFreeHandle(iPatch); | ||
164 | fFreeHandle(iDxPatch); | ||
165 | fFreeHandle(iDyPatch); | ||
166 | } | ||
167 | |||
168 | subsref(currentFrameFeatures,0,i) = subsref(previousFrameFeatures,0,i) + dX; | ||
169 | subsref(currentFrameFeatures,1,i) = subsref(previousFrameFeatures,1,i) + dY; | ||
170 | |||
171 | } | ||
172 | |||
173 | fFreeHandle(rate); | ||
174 | iFreeHandle(imgDims); | ||
175 | return valid; | ||
176 | } | ||
177 | |||
178 | |||
179 | |||
diff --git a/SD-VBS/benchmarks/tracking/src/c/fillFeatures.c b/SD-VBS/benchmarks/tracking/src/c/fillFeatures.c new file mode 100644 index 0000000..42de169 --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/fillFeatures.c | |||
@@ -0,0 +1,67 @@ | |||
1 | /******************************** | ||
2 | |||
3 | Author: Sravanthi Kota Venkata | ||
4 | ********************************/ | ||
5 | |||
6 | #include "tracking.h" | ||
7 | |||
8 | /** Find the position and values of the top N_FEA features | ||
9 | from the lambda matrix **/ | ||
10 | |||
11 | F2D* fillFeatures(F2D* lambda, int N_FEA, int win) | ||
12 | { | ||
13 | int i, j, k, l; | ||
14 | int rows = lambda->height; | ||
15 | int cols = lambda->width; | ||
16 | F2D* features; | ||
17 | |||
18 | features = fSetArray(3, N_FEA, 0); | ||
19 | |||
20 | /** init array **/ | ||
21 | for(i=0; i<N_FEA; i++) | ||
22 | { | ||
23 | subsref(features, 0, i) = -1.0; | ||
24 | subsref(features, 1, i) = -1.0; | ||
25 | subsref(features, 2, i) = 0.0; | ||
26 | } | ||
27 | |||
28 | |||
29 | /** | ||
30 | Find top N_FEA values and store them in | ||
31 | features array along with row and col information | ||
32 | It should be possible to make this algorithm better | ||
33 | if we use a pointer-based data structure, | ||
34 | but have not implemented due to MATLAB compatibility | ||
35 | **/ | ||
36 | |||
37 | for (i=win; i<rows-win; i++) | ||
38 | { | ||
39 | for (j=win; j<cols-win; j++) | ||
40 | { | ||
41 | float currLambdaVal = subsref(lambda,i,j); | ||
42 | if (subsref(features, 2, N_FEA-1) > currLambdaVal) | ||
43 | continue; | ||
44 | |||
45 | for (k=0; k<N_FEA; k++) | ||
46 | { | ||
47 | if (subsref(features, 2, k) < currLambdaVal) | ||
48 | { | ||
49 | /** shift one slot **/ | ||
50 | for (l=N_FEA-1; l>k; l--) | ||
51 | { | ||
52 | subsref(features, 0, l) = subsref(features, 0, l-1); | ||
53 | subsref(features, 1, l) = subsref(features, 1, l-1); | ||
54 | subsref(features, 2, l) = subsref(features, 2, l-1); | ||
55 | } | ||
56 | |||
57 | subsref(features, 0, k) = j * 1.0; | ||
58 | subsref(features, 1, k) = i * 1.0; | ||
59 | subsref(features, 2, k) = currLambdaVal; | ||
60 | break; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | return features; | ||
67 | } | ||
diff --git a/SD-VBS/benchmarks/tracking/src/c/getANMS.c b/SD-VBS/benchmarks/tracking/src/c/getANMS.c new file mode 100644 index 0000000..7ecce8b --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/getANMS.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "tracking.h" | ||
6 | |||
7 | /** ANMS - Adaptive Non-Maximal Suppression | ||
8 | This function takes features as input and suppresses those which | ||
9 | are close to each other (within the SUPPRESSION_RADIUS) and have | ||
10 | similar feature strength | ||
11 | **/ | ||
12 | F2D *getANMS (F2D *points, float r) | ||
13 | { | ||
14 | float MAX_LIMIT = 100000; | ||
15 | F2D *suppressR; | ||
16 | float C_ROBUST = 1.0; | ||
17 | F2D *srtdPnts; | ||
18 | int n; | ||
19 | I2D *srtdVIdx, *supId; | ||
20 | float t, t1, r_sq; | ||
21 | F2D *tempF, *srtdV, *interestPnts; | ||
22 | int i, j, validCount, cnt, end, k; | ||
23 | int iter, rows, cols; | ||
24 | F2D *temp; | ||
25 | int supIdPtr = 0; | ||
26 | |||
27 | /** Concatenate x,y,v to form points matrix **/ | ||
28 | r_sq = r * r; | ||
29 | n = points->height; | ||
30 | |||
31 | srtdVIdx = iMallocHandle(points->height, 1); | ||
32 | for (i = 0; i < srtdVIdx->height; i++) { | ||
33 | asubsref(srtdVIdx,i) = i; | ||
34 | } | ||
35 | srtdPnts = fMallocHandle (srtdVIdx->height, points->width); | ||
36 | for (i = 0; i < srtdVIdx->height; i++) { | ||
37 | for(j=0; j<points->width; j++) { | ||
38 | subsref(srtdPnts,i,j) = subsref(points, asubsref(srtdVIdx,i), j); | ||
39 | } | ||
40 | } | ||
41 | temp = fSetArray (1, 3, 0); | ||
42 | suppressR = fSetArray(n, 1, MAX_LIMIT); | ||
43 | validCount = n; | ||
44 | iter = 0; | ||
45 | |||
46 | /** Allocate supId for #validCount and fill the values of | ||
47 | supId with the indices where suppressR>r_sq **/ | ||
48 | k = 0; | ||
49 | supId = iMallocHandle(validCount, 1); | ||
50 | for (i = 0; i < (suppressR->height*suppressR->width); i++) | ||
51 | { | ||
52 | if ( asubsref(suppressR,i) > r_sq) | ||
53 | { | ||
54 | asubsref(supId,k++) = i; | ||
55 | } | ||
56 | } | ||
57 | |||
58 | /** While number of features not-inspected is >0, **/ | ||
59 | while (validCount > 0) | ||
60 | { | ||
61 | F2D *tempp, *temps; | ||
62 | |||
63 | /** Inspect the strongest feature point in srtdPnts | ||
64 | The index of that feature is in supId and the | ||
65 | index values in supId are arranged in descending order **/ | ||
66 | asubsref(temp,0) = subsref(srtdPnts, asubsref(supId,0), 0); | ||
67 | asubsref(temp,1) = subsref(srtdPnts, asubsref(supId,0), 1); | ||
68 | asubsref(temp,2) = subsref(srtdPnts, asubsref(supId,0), 2); | ||
69 | |||
70 | /** Stacking up the interestPnts matrix with top features | ||
71 | post suppression **/ | ||
72 | if(iter == 0) | ||
73 | interestPnts = fDeepCopy(temp); | ||
74 | else | ||
75 | { | ||
76 | tempp = fDeepCopy(interestPnts); | ||
77 | fFreeHandle(interestPnts); | ||
78 | interestPnts = ffVertcat(tempp, temp); | ||
79 | fFreeHandle(tempp); | ||
80 | } | ||
81 | iter++; | ||
82 | |||
83 | tempp = fDeepCopy(srtdPnts); | ||
84 | temps = fDeepCopy(suppressR); | ||
85 | |||
86 | fFreeHandle(srtdPnts); | ||
87 | fFreeHandle(suppressR); | ||
88 | |||
89 | /** Remove the feature that has been added to interestPnts **/ | ||
90 | srtdPnts = fMallocHandle(supId->height-1, 3); | ||
91 | suppressR = fMallocHandle(supId->height-1, 1); | ||
92 | k=0; | ||
93 | |||
94 | for(i=1; i<(supId->height); i++) /** Filling srtdPnts after removing the feature that was added to interestPnts**/ | ||
95 | { | ||
96 | subsref(srtdPnts,(i-1),0) = subsref(tempp, asubsref(supId,i) ,0); | ||
97 | subsref(srtdPnts,(i-1),1) = subsref(tempp, asubsref(supId,i) ,1); | ||
98 | subsref(srtdPnts,(i-1),2) = subsref(tempp, asubsref(supId,i) ,2); | ||
99 | subsref(suppressR,(i-1),0) = subsref(temps, asubsref(supId,i) ,0); | ||
100 | } | ||
101 | |||
102 | fFreeHandle(tempp); | ||
103 | fFreeHandle(temps); | ||
104 | rows = interestPnts->height-1; | ||
105 | cols = interestPnts->width; | ||
106 | |||
107 | /** For each feature, find how robust it is compared to the one in interestPnts **/ | ||
108 | for (i = 0; i < srtdPnts->height; i++) | ||
109 | { | ||
110 | t = 0; | ||
111 | t1 = 0; | ||
112 | |||
113 | if ((C_ROBUST * subsref(interestPnts,rows,2)) >= subsref(srtdPnts, i,2)) | ||
114 | { | ||
115 | t = subsref(srtdPnts, i,0) - subsref(interestPnts,rows,0); | ||
116 | t1 = subsref(srtdPnts, i,1) - subsref(interestPnts,rows,1); | ||
117 | t = t * t + t1 * t1; | ||
118 | t1 = 0; | ||
119 | } | ||
120 | |||
121 | if ((C_ROBUST * subsref(interestPnts,rows,2)) < subsref(srtdPnts, i,2)) | ||
122 | t1 = 1 * MAX_LIMIT; | ||
123 | |||
124 | if ( asubsref(suppressR, i) > (t + t1)) | ||
125 | { | ||
126 | asubsref(suppressR, i) = t + t1; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | /** Inspect the new suppressR to find how many valid features left **/ | ||
131 | validCount=0; | ||
132 | for (i = 0; i < suppressR->height; i++) { | ||
133 | if ( asubsref(suppressR,i) > r_sq) { | ||
134 | validCount++; | ||
135 | } | ||
136 | } | ||
137 | k = 0; | ||
138 | iFreeHandle(supId); | ||
139 | /** Allocate supId for #validCount and fill the values of | ||
140 | supId with the indices where suppressR>r_sq **/ | ||
141 | supId = iMallocHandle(validCount, 1); | ||
142 | for (i = 0; i < suppressR->height*suppressR->width; i++) { | ||
143 | if ( asubsref(suppressR,i) > r_sq) | ||
144 | asubsref(supId,k++) = i; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | iFreeHandle(supId); | ||
149 | iFreeHandle(srtdVIdx); | ||
150 | fFreeHandle(srtdPnts); | ||
151 | fFreeHandle(temp); | ||
152 | fFreeHandle(suppressR); | ||
153 | |||
154 | return interestPnts; | ||
155 | } | ||
156 | |||
diff --git a/SD-VBS/benchmarks/tracking/src/c/getInterpolatePatch.c b/SD-VBS/benchmarks/tracking/src/c/getInterpolatePatch.c new file mode 100644 index 0000000..99e95f9 --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/getInterpolatePatch.c | |||
@@ -0,0 +1,43 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "tracking.h" | ||
6 | |||
7 | /** Perform simple interpolation around 2*winSize*2*winSize neighbourhood **/ | ||
8 | F2D* getInterpolatePatch(F2D* src, int cols, float centerX, float centerY, int winSize) | ||
9 | { | ||
10 | F2D *dst; | ||
11 | float a, b, a11, a12, a21, a22; | ||
12 | int i, j, k, srcIdx, dstIdx; | ||
13 | int srcIdxx, dstIdxx; | ||
14 | |||
15 | a = centerX - floor(centerX); | ||
16 | b = centerY - floor(centerY); | ||
17 | |||
18 | a11 = (1-a)*(1-b); | ||
19 | a12 = a*(1-b); | ||
20 | a21 = (1-a)*b; | ||
21 | a22 = a*b; | ||
22 | |||
23 | dst = fSetArray(1,2*winSize*2*winSize, 0); | ||
24 | |||
25 | |||
26 | for(i=-winSize; i<winSize; i++) | ||
27 | { | ||
28 | srcIdxx = floor(centerY) + i; | ||
29 | dstIdxx = i+winSize; | ||
30 | |||
31 | for(j=-winSize; j<(winSize); j++) | ||
32 | { | ||
33 | srcIdx = srcIdxx * cols + floor(centerX) + j; | ||
34 | dstIdx = dstIdxx * 2 * winSize + j + winSize; | ||
35 | asubsref(dst,dstIdx) = asubsref(src,srcIdx)*a11 + asubsref(src,srcIdx+1)*a12 + asubsref(src,srcIdx+cols)*a21 + asubsref(src,srcIdx+1+cols)*a22; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | return dst; | ||
40 | } | ||
41 | |||
42 | |||
43 | |||
diff --git a/SD-VBS/benchmarks/tracking/src/c/script_tracking.c b/SD-VBS/benchmarks/tracking/src/c/script_tracking.c new file mode 100644 index 0000000..bb48ace --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/script_tracking.c | |||
@@ -0,0 +1,263 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "tracking.h" | ||
6 | #include <malloc.h> | ||
7 | #include "extra.h" | ||
8 | #define TRACKING_MEM 1<<29 | ||
9 | |||
10 | int main(int argc, char* argv[]) | ||
11 | { | ||
12 | SET_UP | ||
13 | mallopt(M_TOP_PAD, TRACKING_MEM); | ||
14 | mallopt(M_MMAP_MAX, 0); | ||
15 | int i, j, k, N_FEA, WINSZ, LK_ITER, rows, cols; | ||
16 | int endR, endC; | ||
17 | F2D *blurredImage, *previousFrameBlurred_level1, *previousFrameBlurred_level2, *blurred_level1, *blurred_level2; | ||
18 | F2D *verticalEdgeImage, *horizontalEdgeImage, *verticalEdge_level1, *verticalEdge_level2, *horizontalEdge_level1, *horizontalEdge_level2, *interestPnt; | ||
19 | F2D *lambda, *lambdaTemp, *features; | ||
20 | I2D *Ic, *status; | ||
21 | float SUPPRESION_RADIUS; | ||
22 | F2D *newpoints; | ||
23 | |||
24 | int numFind, m, n; | ||
25 | F2D *np_temp; | ||
26 | |||
27 | char im1[100]; | ||
28 | int counter=2; | ||
29 | float accuracy = 0.03; | ||
30 | int count; | ||
31 | |||
32 | |||
33 | N_FEA = 1600; | ||
34 | WINSZ = 4; | ||
35 | SUPPRESION_RADIUS = 10.0; | ||
36 | LK_ITER = 20; | ||
37 | |||
38 | #ifdef test | ||
39 | WINSZ = 2; | ||
40 | N_FEA = 100; | ||
41 | LK_ITER = 2; | ||
42 | counter = 2; | ||
43 | accuracy = 0.1; | ||
44 | #endif | ||
45 | #ifdef sim_fast | ||
46 | WINSZ = 2; | ||
47 | N_FEA = 100; | ||
48 | LK_ITER = 2; | ||
49 | counter = 4; | ||
50 | #endif | ||
51 | #ifdef sim | ||
52 | WINSZ = 2; | ||
53 | N_FEA = 200; | ||
54 | LK_ITER = 2; | ||
55 | counter = 4; | ||
56 | #endif | ||
57 | #ifdef sqcif | ||
58 | WINSZ = 8; | ||
59 | N_FEA = 500; | ||
60 | LK_ITER = 15; | ||
61 | counter = 2; | ||
62 | #endif | ||
63 | #ifdef qcif | ||
64 | WINSZ = 12; | ||
65 | N_FEA = 400; | ||
66 | LK_ITER = 15; | ||
67 | counter = 4; | ||
68 | #endif | ||
69 | #ifdef cif | ||
70 | WINSZ = 20; | ||
71 | N_FEA = 500; | ||
72 | LK_ITER = 20; | ||
73 | counter = 4; | ||
74 | #endif | ||
75 | #ifdef vga | ||
76 | WINSZ = 32; | ||
77 | N_FEA = 400; | ||
78 | LK_ITER = 20; | ||
79 | counter = 4; | ||
80 | #endif | ||
81 | #ifdef wuxga | ||
82 | WINSZ = 64; | ||
83 | N_FEA = 500; | ||
84 | LK_ITER = 20; | ||
85 | counter = 4; | ||
86 | #endif | ||
87 | #ifdef fullhd | ||
88 | WINSZ = 48; | ||
89 | N_FEA = 500; | ||
90 | LK_ITER = 20; | ||
91 | counter = 4; | ||
92 | #endif | ||
93 | |||
94 | I2D* images[counter]; | ||
95 | /** Read input image **/ | ||
96 | for(count=1; count<=counter; count++) | ||
97 | { | ||
98 | /** Read image **/ | ||
99 | printf("Input image %d: ", count); | ||
100 | scanf("%s", im1); | ||
101 | images[count - 1] = readImage(im1); | ||
102 | if(count == 1) Ic = readImage(im1); | ||
103 | } | ||
104 | |||
105 | |||
106 | rows = Ic->height; | ||
107 | cols = Ic->width; | ||
108 | |||
109 | printf("start\n"); | ||
110 | for_each_job{ | ||
111 | |||
112 | /** IMAGE PRE-PROCESSING **/ | ||
113 | |||
114 | /** Blur the image to remove noise - weighted avergae filter **/ | ||
115 | blurredImage = imageBlur(Ic); | ||
116 | |||
117 | /** Scale down the image to build Image Pyramid. We find features across all scales of the image **/ | ||
118 | blurred_level1 = blurredImage; /** Scale 0 **/ | ||
119 | blurred_level2 = imageResize(blurredImage); /** Scale 1 **/ | ||
120 | |||
121 | |||
122 | /** Edge Images - From pre-processed images, build gradient images, both horizontal and vertical **/ | ||
123 | verticalEdgeImage = calcSobel_dX(blurredImage); | ||
124 | horizontalEdgeImage = calcSobel_dY(blurredImage); | ||
125 | |||
126 | /** Edge images are used for feature detection. So, using the verticalEdgeImage and horizontalEdgeImage images, we compute feature strength | ||
127 | across all pixels. Lambda matrix is the feature strength matrix returned by calcGoodFeature **/ | ||
128 | |||
129 | lambda = calcGoodFeature(verticalEdgeImage, horizontalEdgeImage, verticalEdgeImage->width, verticalEdgeImage->height, WINSZ); | ||
130 | endR = lambda->height; | ||
131 | endC = lambda->width; | ||
132 | lambdaTemp = fReshape(lambda, endR*endC, 1); | ||
133 | |||
134 | /** We sort the lambda matrix based on the strengths **/ | ||
135 | /** Fill features matrix with top N_FEA features **/ | ||
136 | fFreeHandle(lambdaTemp); | ||
137 | lambdaTemp = fillFeatures(lambda, N_FEA, WINSZ); | ||
138 | features = fTranspose(lambdaTemp); | ||
139 | |||
140 | /** Suppress features that have approximately similar strength and belong to close neighborhood **/ | ||
141 | interestPnt = getANMS(features, SUPPRESION_RADIUS); | ||
142 | |||
143 | /** Refill interestPnt in features matrix **/ | ||
144 | fFreeHandle(features); | ||
145 | features = fSetArray(2, interestPnt->height, 0); | ||
146 | for(i=0; i<2; i++) { | ||
147 | for(j=0; j<interestPnt->height; j++) { | ||
148 | subsref(features,i,j) = subsref(interestPnt,j,i); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | |||
153 | fFreeHandle(verticalEdgeImage); | ||
154 | fFreeHandle(horizontalEdgeImage); | ||
155 | fFreeHandle(interestPnt); | ||
156 | fFreeHandle(lambda); | ||
157 | fFreeHandle(lambdaTemp); | ||
158 | /** Until now, we processed base frame. The following for loop processes other frames **/ | ||
159 | for(count=1; count<=counter; count++) | ||
160 | { | ||
161 | /** Read image **/ | ||
162 | //sprintf(im1, "%s/%d.bmp", argv[1], count); | ||
163 | //Ic = readImage(im1); | ||
164 | I2D* Icc = images[count-1]; | ||
165 | rows = Icc->height; | ||
166 | cols = Icc->width; | ||
167 | |||
168 | |||
169 | /** Blur image to remove noise **/ | ||
170 | blurredImage = imageBlur(Icc); | ||
171 | previousFrameBlurred_level1 = fDeepCopy(blurred_level1); | ||
172 | previousFrameBlurred_level2 = fDeepCopy(blurred_level2); | ||
173 | |||
174 | fFreeHandle(blurred_level1); | ||
175 | fFreeHandle(blurred_level2); | ||
176 | |||
177 | /** Image pyramid **/ | ||
178 | blurred_level1 = blurredImage; | ||
179 | blurred_level2 = imageResize(blurredImage); | ||
180 | |||
181 | /** Gradient image computation, for all scales **/ | ||
182 | verticalEdge_level1 = calcSobel_dX(blurred_level1); | ||
183 | horizontalEdge_level1 = calcSobel_dY(blurred_level1); | ||
184 | |||
185 | verticalEdge_level2 = calcSobel_dX(blurred_level2); | ||
186 | horizontalEdge_level2 = calcSobel_dY(blurred_level2); | ||
187 | |||
188 | newpoints = fSetArray(2, features->width, 0); | ||
189 | |||
190 | /** Based on features computed in the previous frame, find correspondence in the current frame. "status" returns the index of corresponding features **/ | ||
191 | status = calcPyrLKTrack(previousFrameBlurred_level1, previousFrameBlurred_level2, verticalEdge_level1, verticalEdge_level2, horizontalEdge_level1, horizontalEdge_level2, blurred_level1, blurred_level2, features, features->width, WINSZ, accuracy, LK_ITER, newpoints); | ||
192 | fFreeHandle(verticalEdge_level1); | ||
193 | fFreeHandle(verticalEdge_level2); | ||
194 | fFreeHandle(horizontalEdge_level1); | ||
195 | fFreeHandle(horizontalEdge_level2); | ||
196 | fFreeHandle(previousFrameBlurred_level1); | ||
197 | fFreeHandle(previousFrameBlurred_level2); | ||
198 | //printf("height = %d, width = %d, numFind = %d\n", newpoints->height, newpoints->width); | ||
199 | |||
200 | /** Populate newpoints with features that had correspondence with previous frame features **/ | ||
201 | np_temp = fDeepCopy(newpoints); | ||
202 | if(status->width > 0 ) | ||
203 | { | ||
204 | k = 0; | ||
205 | numFind=0; | ||
206 | for(i=0; i<status->width; i++) | ||
207 | { | ||
208 | if( asubsref(status,i) == 1) | ||
209 | numFind++; | ||
210 | } | ||
211 | fFreeHandle(newpoints); | ||
212 | newpoints = fSetArray(2, numFind, 0); | ||
213 | |||
214 | for(i=0; i<status->width; i++) | ||
215 | { | ||
216 | if( asubsref(status,i) == 1) | ||
217 | { | ||
218 | subsref(newpoints,0,k) = subsref(np_temp,0,i); | ||
219 | subsref(newpoints,1,k++) = subsref(np_temp,1,i); | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | |||
224 | iFreeHandle(status); | ||
225 | fFreeHandle(np_temp); | ||
226 | fFreeHandle(features); | ||
227 | |||
228 | /** Populate newpoints into features **/ | ||
229 | features = fDeepCopy(newpoints); | ||
230 | fFreeHandle(newpoints); | ||
231 | } | ||
232 | } | ||
233 | printf("end..\n"); | ||
234 | #ifdef CHECK | ||
235 | /* Self checking */ | ||
236 | { | ||
237 | int ret=0; | ||
238 | float tol = 2.0; | ||
239 | #ifdef GENERATE_OUTPUT | ||
240 | fWriteMatrix(features, argv[1]); | ||
241 | #endif | ||
242 | ret = fSelfCheck(features, "expected_C.txt", tol); | ||
243 | if (ret == -1) | ||
244 | printf("Error in Tracking Map\n"); | ||
245 | } | ||
246 | #endif | ||
247 | |||
248 | fFreeHandle(blurred_level1); | ||
249 | fFreeHandle(blurred_level2); | ||
250 | fFreeHandle(features); | ||
251 | |||
252 | for(count=1; count<=counter; count++) | ||
253 | { | ||
254 | free(images[count - 1] ); | ||
255 | } | ||
256 | iFreeHandle(Ic); | ||
257 | WRITE_TO_FILE | ||
258 | return 0; | ||
259 | |||
260 | } | ||
261 | |||
262 | |||
263 | |||
diff --git a/SD-VBS/benchmarks/tracking/src/c/tracking.h b/SD-VBS/benchmarks/tracking/src/c/tracking.h new file mode 100644 index 0000000..24b8b2d --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/tracking.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #ifndef _SCRIPT_TRACK_ | ||
6 | #define _SCRIPT_TRACK_ | ||
7 | |||
8 | #include "sdvbs_common.h" | ||
9 | |||
10 | F2D* calcAreaSum(F2D* src, int cols, int rows, int winSize); | ||
11 | F2D* calcGoodFeature(F2D* dX, F2D* dY, int cols, int rows, int winSize); | ||
12 | I2D* calcPyrLKTrack(F2D* ip1, F2D* ip2, F2D* idxp1, F2D* idxp2, F2D* idyp1, F2D* idyp2, F2D* jp1, F2D* jp2, F2D* fPnt, int nFeatures, int winSize, float accuracy, int maxIter, F2D* newPnt); | ||
13 | F2D *getANMS (F2D *points, float r); | ||
14 | F2D* getInterpolatePatch(F2D* src, int cols, float centerX, float centerY, int winSize); | ||
15 | float polynomial(int d, F2D* a, F2D* b, int dim); | ||
16 | I2D* sortInd(F2D* input, int dim); | ||
17 | F2D* fillFeatures(F2D* lambda, int N_FEA, int win); | ||
18 | |||
19 | #endif | ||
20 | |||