-
Notifications
You must be signed in to change notification settings - Fork 12
/
helpers.py
27 lines (21 loc) · 917 Bytes
/
helpers.py
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
#convert from Yolo_mark to opencv format
def yoloFormattocv(x1, y1, x2, y2, H, W):
bbox_width = x2 * W
bbox_height = y2 * H
center_x = x1 * W
center_y = y1 * H
voc = []
voc.append(center_x - (bbox_width / 2))
voc.append(center_y - (bbox_height / 2))
voc.append(center_x + (bbox_width / 2))
voc.append(center_y + (bbox_height / 2))
return [int(v) for v in voc]
# convert from opencv format to yolo format
# H,W is the image height and width
def cvFormattoYolo(corner, H, W):
bbox_W = corner[3] - corner[1]
bbox_H = corner[4] - corner[2]
center_bbox_x = (corner[1] + corner[3]) / 2
center_bbox_y = (corner[2] + corner[4]) / 2
return corner[0], round(center_bbox_x / W, 6), round(center_bbox_y / H, 6), round(bbox_W / W, 6), round(bbox_H / H,
6)