当前位置:网站首页>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
边栏推荐
- Face detection, training and recognition based on OpenCV
- StepN分析
- (2) v-cloak指令
- Golang --- comparison operation of various types of variables
- 1264_FreeRTOS任务的初始化以及堆栈初始化处理分析
- Test website construction + penetration + audit Part II penetration test
- Attention OCR Chinese version mas # ter Code Running Logic
- golang---并发runtime包
- (6)事件
- 微信小程序:(异常)Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ 解决方案和分析流程(这里一定有你要的答案)
猜你喜欢

golang---並發runtime包

golang---并发Goroutine

170亿参数,28项公开测试集SOTA,行业最大的视觉多任务统一大模型来了

Pdf merge based on pyqt5

Rigidbody2d rotate around a fixed point rotate

Golang--- redis operation

MMdet修改检测框字体大小、位置、颜色、填充框

Software testing (II)

golang---并发runtime包
![[software tools] [tutorials] a useful tool for exporting CSDN blog articles to word](/img/40/556cd8c4868a93d4cc06a4a945475d.png)
[software tools] [tutorials] a useful tool for exporting CSDN blog articles to word
随机推荐
Binary processing of opcv image
JVM面试
Graph to document function based on pyqt5
5、快速(分组)排序
变量提升和函数提升
基于PyQt5完成的pdf转word
Principle analysis of the bottom plate of Ruixin micro rk3399 development board
Openinfra Foundation launched the "targeted fund" program to promote successful open source governance experience
测试网站搭建+渗透+审计之第二篇渗透测试
Attention OCR Chinese version mas # ter Code Running Logic
微信小程序开发的页面组件
基于PyQt5完成的抠图功能-程序实现
《Attention-ocr-Chinese-Version-mas # ter》代码运行逻辑
User controlled keyboard and mouse custom script
golang---并发runtime包
(5) 双向数据绑定
Rigidbody2d SweepTest Rigidbody2D. Cast but for rotation rotation
Lua string
5. Quick (Group) sort
P5321 [BJOI2019]送别(LCT)
https://blog.csdn.net/qq_40502460/article/details/117319923