当前位置:网站首页>Mmdet modify the font size, position, color and fill box of the detection box

Mmdet modify the font size, position, color and fill box of the detection box

2022-06-09 04:17:00 Hometown clouds and stars

1. Modify fill box

        stay mmdet/core/visulization/image.py below ,139 OK, let's start , Write code for text and fill boxes , Comment out the filling box

2. Modify the font size of the detection box 、 Color

        find mmdet/models/detectors/base.py file , modify class BaseDetector() Medium show_result() Function's input parameters

def show_result(self,
                    img,
                    result,
                    score_thr=0.3,
                    bbox_color='green',    # Check the color of the box
                    text_color='green',    # The color of the font
                    thickness=2, # Check the thickness of the box
                    font_size=1.5, # font size
                    win_name='',
                    show=False,
                    wait_time=0,
                    out_file=None):

3. Change the font thickness

        file found anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/visualization/image.py. stay mmcv.imshow_det_bboxes() Function call cv2.putText Function to label the category text on the graph , Add the parameter to change the font thickness .

       cv2.putText(img, 
            label_text, 
            (bbox_int[0], bbox_int[1] - 2),
             cv2.FONT_HERSHEY_COMPLEX, 
             font_scale, 
             text_color,
             3    # Add a parameter to change the font thickness )

4. Set the font size that is automatically set according to the picture resolution

        We can give... According to the size of the input picture thickness and font_scale assignment , Font size: np.floor(5e-4 * np.shape(img)[1] + 0.5). The thickness of the detection box is set to max((np.shape(img)[0] + np.shape(img)[1]) // 1080, 1).

def show_result(self,
                    img,
                    result,
                    score_thr=0.3,
                    bbox_color='green',
                    text_color='green',
                    #thickness=3,
                    #font_scale=0.8,
                    win_name='',
                    show=False,
                    wait_time=0,
                    out_file=None):
        img = mmcv.imread(img)
        font_scale=np.floor(5e-4 * np.shape(img)[1] + 0.5)
        thickness=thickness = max((np.shape(img)[0] + np.shape(img)[1]) // 1080, 1)
        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]]
                sg = segms[i]
                if isinstance(sg, torch.Tensor):
                    sg = sg.detach().cpu().numpy()
                mask = sg.astype(bool)
                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
        mmcv.imshow_det_bboxes(
            img,
            bboxes,
            labels,
            class_names=self.CLASSES,
            score_thr=score_thr,
            bbox_color=bbox_color,
            text_color=text_color,
            thickness=thickness,
            font_scale=font_scale,
            win_name=win_name,
            show=show,
            wait_time=wait_time,
            out_file=out_file)

        if not (show or out_file):
            return img

5. For a more detailed explanation, see the boss' blog

MMDetection V2.0 Visual parameter modification _ Awe inspiring little programmer's blog -CSDN Blog MMDetection V2.0 Visual parameter modification changes the color of the detection box 、 thickness 、 The effect of changing the text size to change the text thickness will MMDetection The test results of SAR When visualizing on a graph , Found font too small 、 Too thin , Can't see . modify MMDtection Some parameters in can change the color of the detection box 、 thickness 、 font size 、 The font size . Change the color of the detection box 、 thickness 、 Text size found mmdet/models/detectors/base.py file , modify class BaseDetector() Medium show_result() Function's input parameters def show_result(selfhttps://blog.csdn.net/i013140225/article/details/109819366?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-1-109819366.pc_agg_new_rank&utm_term=mmdetection%E4%B8%AD%E6%A0%87%E6%B3%A8%E5%AD%97%E4%BD%93%E7%9A%84%E5%A4%A7%E5%B0%8F%E6%80%8E%E4%B9%88%E8%B0%83%E6%95%B4&spm=1000.2123.3001.4430

Target detection modifies the size of the detection box 、 thickness _ Tianya Xiaocai's blog -CSDN Blog _ How to adjust the size of the target detection box https://blog.csdn.net/qq_40502460/article/details/117319923

原网站

版权声明
本文为[Hometown clouds and stars]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090414213978.html