1. 程式人生 > >COCO API 顯示圖片的分割效果

COCO API 顯示圖片的分割效果

 

from pycocotools.coco import COCO
import numpy as np
import skimage.io as io
import matplotlib.pyplot as plt
import pylab

pylab.rcParams['figure.figsize'] = (8.0, 10.0)

dataDir = '資料夾路徑'
dataType = 'val2017'
annFile = '{}/annotations/instances_{}.json'.format(dataDir, dataType)

# I為圖片具體位置
I = io.imread(dataDir + '/annotations/val2017/' + '000000324158.jpg')

coco = COCO(annFile)

plt.imshow(I)
plt.axis('off')
annIds = coco.getAnnIds(imgIds=324158, iscrowd=None)
# print(annIds)
anns = coco.loadAnns(annIds)
# print(anns)
coco.showAnns(anns)
plt.show()