16 if(diff < 0)
return 1;
17 else if(diff > 0)
return -1;
25 for(i = 0; i <= k; ++i){
26 if(dets[i].objectness == 0){
36 for(i = 0; i < total; ++i){
41 for(i = 0; i < total; ++i){
42 if(dets[i].objectness == 0)
continue;
44 for(j = i+1; j < total; ++j){
45 if(dets[j].objectness == 0)
continue;
62 for(i = 0; i <= k; ++i){
63 if(dets[i].objectness == 0){
74 for(i = 0; i < total; ++i){
78 for(i = 0; i < total; ++i){
79 if(dets[i].prob[k] == 0)
continue;
81 for(j = i+1; j < total; ++j){
106 float l1 = a.
x - a.
w/2;
107 float l2 = b.
x - b.
w/2;
112 float r1 = a.
x + a.
w/2;
113 float r2 = b.
x + b.
w/2;
129 float t1 = a.
y - a.
h/2;
130 float t2 = b.
y - b.
h/2;
135 float b1 = a.
y + a.
h/2;
136 float b2 = b.
y + b.
h/2;
152 float overlap(
float x1,
float w1,
float x2,
float w2)
154 float l1 = x1 - w1/2;
155 float l2 = x2 - w2/2;
156 float left = l1 > l2 ? l1 : l2;
157 float r1 = x1 + w1/2;
158 float r2 = x2 + w2/2;
159 float right = r1 < r2 ? r1 : r2;
167 if(w < 0 || h < 0)
return 0;
175 float u = a.
w*a.
h + b.
w*b.
h - i;
186 return sqrt(pow(a.
x-b.
x, 2) +
223 box a = {0, 0, 1, 1};
224 box dxa= {0+.0001, 0, 1, 1};
225 box dya= {0, 0+.0001, 1, 1};
226 box dwa= {0, 0, 1+.0001, 1};
227 box dha= {0, 0, 1, 1+.0001};
229 box b = {.5, .5, .2, .2};
231 printf(
"Union: %f %f %f %f\n", di.
dx, di.
dy, di.
dw, di.
dh);
237 xinter = (xinter - inter)/(.0001);
238 yinter = (yinter - inter)/(.0001);
239 winter = (winter - inter)/(.0001);
240 hinter = (hinter - inter)/(.0001);
241 printf(
"Union Manual %f %f %f %f\n", xinter, yinter, winter, hinter);
245 box a = {0, 0, 1, 1};
246 box dxa= {0+.0001, 0, 1, 1};
247 box dya= {0, 0+.0001, 1, 1};
248 box dwa= {0, 0, 1+.0001, 1};
249 box dha= {0, 0, 1, 1+.0001};
251 box b = {.5, .5, .2, .2};
253 printf(
"Inter: %f %f %f %f\n", di.
dx, di.
dy, di.
dw, di.
dh);
259 xinter = (xinter - inter)/(.0001);
260 yinter = (yinter - inter)/(.0001);
261 winter = (winter - inter)/(.0001);
262 hinter = (hinter - inter)/(.0001);
263 printf(
"Inter Manual %f %f %f %f\n", xinter, yinter, winter, hinter);
270 box a = {0, 0, 1, 1};
271 box dxa= {0+.00001, 0, 1, 1};
272 box dya= {0, 0+.00001, 1, 1};
273 box dwa= {0, 0, 1+.00001, 1};
274 box dha= {0, 0, 1, 1+.00001};
276 box b = {.5, 0, .2, .2};
279 iou = (1-iou)*(1-iou);
282 printf(
"%f %f %f %f\n", d.
dx, d.
dy, d.
dw, d.
dh);
288 xiou = ((1-xiou)*(1-xiou) - iou)/(.00001);
289 yiou = ((1-yiou)*(1-yiou) - iou)/(.00001);
290 wiou = ((1-wiou)*(1-wiou) - iou)/(.00001);
291 hiou = ((1-hiou)*(1-hiou) - iou)/(.00001);
292 printf(
"manual %f %f %f %f\n", xiou, yiou, wiou, hiou);
311 dd.
dx = 2*pow((1-(i/u)),1)*(di.
dx*u - du.
dx*i)/(u*u);
312 dd.
dy = 2*pow((1-(i/u)),1)*(di.
dy*u - du.
dy*i)/(u*u);
313 dd.
dw = 2*pow((1-(i/u)),1)*(di.
dw*u - du.
dw*i)/(u*u);
314 dd.
dh = 2*pow((1-(i/u)),1)*(di.
dh*u - du.
dh*i)/(u*u);
322 for(i = 0; i < total; ++i){
324 for(k = 0; k < classes; ++k) any = any || (probs[i][k] > 0);
328 for(j = i+1; j < total; ++j){
329 if (
box_iou(boxes[i], boxes[j]) > thresh){
331 if (probs[i][k] < probs[j][k]) probs[i][k] = 0;
332 else probs[j][k] = 0;
342 encode.
x = (b.
x - anchor.
x) / anchor.
w;
343 encode.
y = (b.
y - anchor.
y) / anchor.
h;
344 encode.
w = log2(b.
w / anchor.
w);
345 encode.
h = log2(b.
h / anchor.
h);
352 decode.
x = b.
x * anchor.
w + anchor.
x;
353 decode.
y = b.
y * anchor.
h + anchor.
y;
354 decode.
w = pow(2., b.
w) * anchor.
w;
355 decode.
h = pow(2., b.
h) * anchor.
h;
box float_to_box(float *f, int stride)
box encode_box(box b, box anchor)
float overlap(float x1, float w1, float x2, float w2)
dbox derivative(box a, box b)
void do_nms_obj(detection *dets, int total, int classes, float thresh)
float box_rmse(box a, box b)
int nms_comparator(const void *pa, const void *pb)
box decode_box(box b, box anchor)
void do_nms(box *boxes, float **probs, int total, int classes, float thresh)
dbox dunion(box a, box b)
float box_iou(box a, box b)
float box_union(box a, box b)
dbox dintersect(box a, box b)
float box_intersection(box a, box b)
void do_nms_sort(detection *dets, int total, int classes, float thresh)