使用 matplotlib 按类别着色
这是我用 coco json 和图像创建带注释的图像的代码。
I = io.imread('%s/images/%s'%(dataDir,img['file_name']))
axes = plt.gca()
axes.set_frame_on(False)
axes.set_xticks([]); axes.set_yticks([])
annpath = os.path.join(dataDir, 'AnnImages/')
if not os.path.exists(annpath):
os.makedirs(annpath)
path=annpath+str(img['file_name'])[:-4]+'.jpg'
annotation_ids = coco.getAnnIds(imgIds=img['id'], catIds=catIds, iscrowd=None)
annotations = coco.loadAnns(annotation_ids)
fig = plt.figure(figsize=(16, 9), dpi=155.9)
plt.imshow(I, interpolation='nearest')
plt.axis('off')
coco.showAnns(annotations)
plt.savefig(path, bbox_inches='tight', pad_inches=0)
但它为每个对象以不同的颜色输出。
我想为每个类别着色。
你能帮助我吗?
我的注释类别: test , test2
This is my code to create an annotated image with coco json and image.
I = io.imread('%s/images/%s'%(dataDir,img['file_name']))
axes = plt.gca()
axes.set_frame_on(False)
axes.set_xticks([]); axes.set_yticks([])
annpath = os.path.join(dataDir, 'AnnImages/')
if not os.path.exists(annpath):
os.makedirs(annpath)
path=annpath+str(img['file_name'])[:-4]+'.jpg'
annotation_ids = coco.getAnnIds(imgIds=img['id'], catIds=catIds, iscrowd=None)
annotations = coco.loadAnns(annotation_ids)
fig = plt.figure(figsize=(16, 9), dpi=155.9)
plt.imshow(I, interpolation='nearest')
plt.axis('off')
coco.showAnns(annotations)
plt.savefig(path, bbox_inches='tight', pad_inches=0)
But it is output in different colors for each object..
I want to color each category.
Can you help me?
My annotate category : test , test2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论