diff options
author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/benchmarks/tracking/src/c/script_tracking.c | |
parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (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/benchmarks/tracking/src/c/script_tracking.c')
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/script_tracking.c | 263 |
1 files changed, 263 insertions, 0 deletions
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 | |||