Created
September 29, 2022 08:13
-
-
Save webtk/e553b718ed13a6b05039d81c786493c3 to your computer and use it in GitHub Desktop.
extraction RBox from Rendered.ai Annotation data
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
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