in meshrcnn/utils/vis.py [0:0]
def draw_pix3d_dict(dataset_dict, class_names=None):
"""
Draw the instance annotations for an image.
Args:
dataset_dict (dict): a dict in Detectron2 Dataset format. See DATASETS.md
class_names (list[str] or None): `class_names[cateogory_id]` is the
name for this category. If not provided, the visualization will
not contain class names.
"""
img = dataset_dict.get("image", None)
if img is None:
img = cv2.imread(dataset_dict["file_name"])
annos = dataset_dict["annotations"]
if not len(annos):
return img
boxes = np.asarray(
[BoxMode.convert(k["bbox"], k["bbox_mode"], BoxMode.XYXY_ABS) for k in annos]
)
# Display in largest to smallest order to reduce occlusion
areas = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1])
sorted_inds = np.argsort(-areas)
sorted_boxes = copy.deepcopy(boxes[sorted_inds])
img = draw_boxes(img, sorted_boxes)
cmap = colormap()
for num, i in enumerate(sorted_inds):
anno = annos[i]
bbox = anno["bbox"]
assert anno["bbox_mode"] in [
BoxMode.XYXY_ABS,
BoxMode.XYWH_ABS,
], "Relative coordinates not yet supported in visualization."
iscrowd = anno.get("iscrowd", 0)
clsid = anno["category_id"]
text = class_names[clsid] if class_names is not None else str(clsid)
if iscrowd:
text = text + "_crowd"
img = draw_text(img, (bbox[0], bbox[1] - 2), text)
segs = anno.get("segmentation", None)
if segs is not None and not iscrowd:
segs_color = cmap[num % len(cmap)]
mask = cv2.imread(segs)
img = draw_mask(img, mask, segs_color, draw_contours=False)
kpts = anno.get("keypoints", None)
if kpts is not None and not iscrowd:
kpts = np.asarray(kpts).reshape(-1, 3)[:, :2]
img = draw_keypoints(img, kpts)
return img