Skip to content

Instantly share code, notes, and snippets.

@pranjalAI
Created September 11, 2020 04:20
Show Gist options
  • Save pranjalAI/1361d46f16387207af52c62d060227fb to your computer and use it in GitHub Desktop.
Save pranjalAI/1361d46f16387207af52c62d060227fb to your computer and use it in GitHub Desktop.
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment