labelme转COCO数据集(物体检测)

本文介绍如何将labelme标注的物体检测数据转换为COCO格式,涉及Python代码解析,包括图像、类别、注解的处理,以及数据集划分和保存为JSON文件的过程。
摘要由CSDN通过智能技术生成

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)</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值