Created
October 7, 2021 12:47
-
-
Save seanbenhur/b4ca8cae53d0adc5f9e0ab1bc04b46bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_annot_to_yolov5(x_min, y_min, x_max, y_max, img): | |
""" | |
Convert annotations into required yolov5 formamt | |
x_center, y_center, width, height | |
""" | |
w = x_max - x_min | |
h = y_max - y_min | |
imgheight,imgwidth = img.shape[0], img.shape[1] | |
#x,y,w,h = a['hbox'] //for each tag in gtboxes object | |
""" | |
x_min = x | |
x_max = (x+w) | |
y_min = y | |
y_max = (y+h) | |
""" | |
x_center = (x_min+x_max)/2. | |
y_center = (y_min+y_max)/2. | |
yolo_x = x_center/imgheight | |
yolo_w = w/imgwidth | |
yolo_y = y_center/imgwidth | |
yolo_h = h/imgheight | |
return yolo_x, yolo_w, yolo_y, yolo_h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment