EfficientDet数据集可视化
import cv2
import random
import json, os
from pycocotools.coco import COCO
from matplotlib import pyplot as plt
train_json = './datasets/jam/annotations/instances_train.json'
train_path = './datasets/jam/train/'
def visualization_bbox2(num_image, json_path, img_path):
coco = COCO(json_path)
list_imgIds = coco.getImgIds(catIds=2)
print(list_imgIds)
img = coco.loadImgs(list_imgIds[num_image-1])[0]
image = cv2.imread(img_path + img['file_name'])
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_name = img['file_name']
image_id = img['id']
img_annIds = coco.getAnnIds(imgIds=image_id)
img_anns = coco.loadAnns(img_annIds)
print(len(img_annIds))
for i in range(len(img_annIds)):
x, y, w, h = img_anns[i]['bbox']
label = img_anns[i]['category_id']
label = coco.loadCats(label)[0]['name']
image = cv2.rectangle(image, (int(x), int(y)), (int(x + w), int(y + h)), (255, 255, 255), 2)
cv2.putText(image,str(label),(int(x), int(y)),cv2.FONT_HERSHEY_SIMPLEX,1.2, (255, 255, 255), 2)
plt.rcParams['figure.figsize'] = (20.0, 20.0)
plt.imshow(image)
plt.show()
visualization_bbox2(10, train_json, train_path)
![运行](https://i-blog.csdnimg.cn/blog_migrate/8ec6a248cec4b47a62d2ae883a8036dd.png)