Skip to content

Instantly share code, notes, and snippets.

@AbhimanyuAryan
Forked from goodhamgupta/voc_to_yolo.py
Created August 22, 2019 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhimanyuAryan/b8ab8cee6d2551eef7a9ab8c754eb474 to your computer and use it in GitHub Desktop.
Save AbhimanyuAryan/b8ab8cee6d2551eef7a9ab8c754eb474 to your computer and use it in GitHub Desktop.
def generate(label):
(
bbox_xmin,
bbox_ymin,
bbox_xmax,
bbox_ymax,
img_width,
img_height
) = (
label.get('xmin'),
label.get('ymin'),
label.get('xmax'),
label.get('ymax'),
label.get('img_width'),
label.get('img_height')
)
dw = 1. / img_width
dh = 1. / img_height
x = (bbox_xmin + bbox_xmax) / 2.0
y = (bbox_ymin + bbox_ymax) / 2.0
w = bbox_xmax - bbox_xmin
h = bbox_ymax - bbox_ymin
x = x * dw
w = w * dw
y = y * dh
h = h * dh
return (x, y, w, h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment