Skip to content

Instantly share code, notes, and snippets.

@webtk
Created September 29, 2022 08:13
Show Gist options
  • Save webtk/e553b718ed13a6b05039d81c786493c3 to your computer and use it in GitHub Desktop.
Save webtk/e553b718ed13a6b05039d81c786493c3 to your computer and use it in GitHub Desktop.
extraction RBox from Rendered.ai Annotation data
from PIL import ImageDraw as D
from PIL import Image
from PIL import ImagePath
import json
import cv2
import numpy as np
with open('syn_sample/annotations/0000000000-1-Image-ana.json','r') as f:
annotation = json.load(f)
i = Image.open("syn_sample/images/0000000000-1-Image.png")
draw = D.Draw(i)
objects = annotation['annotations']
for obj in objects:
for seg in obj['segmentation']:
pts=np.array(seg)
pts=np.reshape(pts, (-1,2))
#((x,y),(w,h),a) = cv2.minAreaRect(pts)
rect = cv2.minAreaRect(pts)
box = cv2.boxPoints(rect)
draw.polygon(box)
#break
i.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment