import cv2
import numpy as np
import json
P = []
with open('test.json') as f:
datas = f.readlines()
for data in datas:
data = data.strip()
annotations = json.loads(data)['annotation']
annotation = annotations[0]
points = annotation['points']
imageWidth = annotation['imageWidth']
imageHeight = annotation['imageHeight']
for point in points:
point[0] *= imageWidth
point[1] *= imageHeight
P.append([int(point[0]),int(point[1])])
originalimg = cv2.imread('/home/lixuan/data/466yuanshi/f/t1.jpg')
img = np.zeros((imageHeight, imageWidth, 3), np.uint8)
area1 = np.array(P)
cv2.fillPoly(img, [area1], (255, 255, 255))
maskindex = np.where(img > 0)
img[maskindex] = originalimg[maskindex]
cv2.imshow('',img)
cv2.waitKey(0)