diff options
Diffstat (limited to 'SD-VBS/benchmarks/tracking/src/c/getANMS.c')
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/getANMS.c | 156 |
1 files changed, 156 insertions, 0 deletions
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 | |||