Skip to content

Instantly share code, notes, and snippets.

@goodhamgupta
Created April 2, 2018 13:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save goodhamgupta/eb5b4cdd22fa95341502e1187ec71849 to your computer and use it in GitHub Desktop.
Save goodhamgupta/eb5b4cdd22fa95341502e1187ec71849 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