print(self.categories)
self.label.append(label[1])
self.label.append(label)
points = shapes[‘points’]
self.annotations.append(self.annotation(points, label, num))
self.annID += 1
def image(self, data, num):
image = {}
img = utils.img_b64_to_arr(data[‘imageData’])
height, width = img.shape[:2]
img = None
image[‘height’] = height
image[‘width’] = width
image[‘id’] = num + 1
image[‘file_name’] = data[‘imagePath’].split(‘/’)[-1]
self.height = height
self.width = width
return image
def categorie(self, label):
categorie = {}
categorie[‘supercategory’] = label
categorie[‘supercategory’] = label
categorie[‘id’] = labels[label] # 0 默认为背景
categorie[‘name’] = label
return categorie
def annotation(self, points, label, num):
annotation = {}
print(points)
x1 = points[0][0]
y1 = points[0][1]
x2 = points[1][0]
y2 = points[1][1]
contour = np.array([[x1, y1], [x2, y1], [x2, y2], [x1, y2]]) # points = [[x1, y1], [x2, y2]] for rectangle
contour = contour.astype(int)
area = cv2.contourArea(contour)
print("contour is ", contour, " area = ", area)</