Пример #1
0
    def show_result(self,
                    img,
                    result,
                    colors='green',
                    top_k=300,
                    thickness=1,
                    win_name='',
                    wait_time=0,
                    show=False,
                    out_file=None,
                    score_thr=None):
        img = mmcv.imread(img)
        bboxes, scores = result[:, :-1], result[:, -1]
        idx = scores.argsort()[::-1]
        bboxes = bboxes[idx]

        top_k = min(top_k, len(bboxes))
        bboxes = bboxes[:top_k, :]

        if out_file is not None:
            show = False
        img = bt.imshow_bboxes(
            img,
            bboxes,
            colors=colors,
            thickness=thickness,
            with_text=False,
            show=show,
            win_name=win_name,
            wait_time=wait_time,
            out_file=out_file)
        return img
Пример #2
0
def single_vis(task, btype, class_names, colors, thickness, text_off,
               font_size, show_off, wait_time, lock, prog, total):
    imgpath, out_file, bboxes, labels, scores = task
    bboxes = bt.bbox2type(bboxes, btype) if btype else bboxes
    bt.imshow_bboxes(imgpath,
                     bboxes,
                     labels,
                     scores,
                     class_names=class_names,
                     colors=colors,
                     thickness=thickness,
                     with_text=(not text_off),
                     font_size=font_size,
                     show=(not show_off),
                     wait_time=wait_time,
                     out_file=out_file)

    lock.acquire()
    prog.value += 1
    msg = f'({prog.value/total:3.1%} {prog.value}:{total})'
    msg += ' - ' + f"Filename: {osp.split(imgpath)[-1]}"
    print(msg)
    lock.release()
Пример #3
0
    def show_result(self,
                    img,
                    result,
                    score_thr=0.3,
                    colors='green',
                    thickness=1.,
                    font_size=10,
                    win_name='',
                    show=False,
                    wait_time=0,
                    out_file=None):

        img = mmcv.imread(img)
        img = img.copy()
        if isinstance(result, tuple):
            bbox_result, segm_result = result
            if isinstance(segm_result, tuple):
                segm_result = segm_result[0]  # ms rcnn
        else:
            bbox_result, segm_result = result, None
        bboxes = np.vstack(bbox_result)
        labels = [
            np.full(bbox.shape[0], i, dtype=np.int32)
            for i, bbox in enumerate(bbox_result)
        ]
        labels = np.concatenate(labels)
        # draw segmentation masks
        if segm_result is not None and len(labels) > 0:  # non empty
            segms = mmcv.concat_list(segm_result)
            inds = np.where(bboxes[:, -1] > score_thr)[0]
            np.random.seed(42)
            color_masks = [
                np.random.randint(0, 256, (1, 3), dtype=np.uint8)
                for _ in range(max(labels) + 1)
            ]
            for i in inds:
                i = int(i)
                color_mask = color_masks[labels[i]]
                mask = segms[i]
                img[mask] = img[mask] * 0.5 + color_mask * 0.5
        # if out_file specified, do not show image in window
        if out_file is not None:
            show = False
        # draw bounding boxes
        bboxes, scores = bboxes[:, :-1], bboxes[:, -1]
        bboxes = bboxes[scores > score_thr]
        labels = labels[scores > score_thr]
        scores = scores[scores > score_thr]
        img = bt.imshow_bboxes(
            img, bboxes, labels, scores,
            class_names=self.CLASSES,
            colors=colors,
            thickness=thickness,
            font_size=font_size,
            win_name=win_name,
            show=show,
            wait_time=wait_time,
            out_file=out_file)

        if not (show or out_file):
            warnings.warn('show==False and out_file is not specified, only '
                          'result image will be returned')
            return img