-
Notifications
You must be signed in to change notification settings - Fork 20
/
draw.h~
89 lines (71 loc) · 2.14 KB
/
draw.h~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "preproc_yolov2.h"
#include "regionLayer.h"
#include "bboxParser.h"
void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b)
{
int i;
if(x1 < 0) x1 = 0;
if(x1 >= a.w) x1 = a.w-1;
if(x2 < 0) x2 = 0;
if(x2 >= a.w) x2 = a.w-1;
if(y1 < 0) y1 = 0;
if(y1 >= a.h) y1 = a.h-1;
if(y2 < 0) y2 = 0;
if(y2 >= a.h) y2 = a.h-1;
for(i = x1; i <= x2; ++i){
a.data[i + y1*a.w + 0*a.w*a.h] = r;
a.data[i + y2*a.w + 0*a.w*a.h] = r;
a.data[i + y1*a.w + 1*a.w*a.h] = g;
a.data[i + y2*a.w + 1*a.w*a.h] = g;
a.data[i + y1*a.w + 2*a.w*a.h] = b;
a.data[i + y2*a.w + 2*a.w*a.h] = b;
}
for(i = y1; i <= y2; ++i){
a.data[x1 + i*a.w + 0*a.w*a.h] = r;
a.data[x2 + i*a.w + 0*a.w*a.h] = r;
a.data[x1 + i*a.w + 1*a.w*a.h] = g;
a.data[x2 + i*a.w + 1*a.w*a.h] = g;
a.data[x1 + i*a.w + 2*a.w*a.h] = b;
a.data[x2 + i*a.w + 2*a.w*a.h] = b;
}
}
void draw_box_width(image a, int x1, int y1, int x2, int y2, int w)
{
int i;
for(i = 0; i < w; ++i){
draw_box(a, x1+i, y1+i, x2-i, y2-i, 255, 0, 0);
}
}
void draw_detections(image im,
int batchIdx,
float thresh,
box *boxes,
float *probs,
int * indexes,
int sizeOfClass,
int sizeOfBatch)
{
int n = batchIdx;
// int sizeOfClass = l.n * l.h * l.w;
// int sizeOfBatch = l.classes * sizeOfClass;
int count = 0;
for(int i = 0; i < sizeOfBatch; ++i){
int id = n * sizeOfBatch + i;
int indexes_idx = indexes[id];
if (probs[id] > thresh){
int category = (indexes_idx % sizeOfBatch) / sizeOfClass;
int boxId = indexes_idx % sizeOfClass;
int width = im.h * .006;
box b = boxes[boxId];
int left = (b.x-b.w/2.)*im.w;
int right = (b.x+b.w/2.)*im.w;
int top = (b.y-b.h/2.)*im.h;
int bot = (b.y+b.h/2.)*im.h;
if(left < 0) left = 0;
if(right > im.w-1) right = im.w-1;
if(top < 0) top = 0;
if(bot > im.h-1) bot = im.h-1;
draw_box_width(im, left, top, right, bot, width);
}
}
}