Table of contents
1. Adjust the thickness of the detection frame
detect.py
Press and hold the Ctrl+F
search button in line_thickness
the past 129
, line_thickness
and change the size of the left and right rows, for example, change toline_thickness=3
2. Set label color
detect.py
Press and hold Ctrl+F
the search button in colors = [[random.randint(0, 255) for _ in range(3)] for _ in names]
the past, comment it out, and then directly write the color matrix, for example as follows:
- Note: Because cv2 saves the image later, the order of cv2 saves the image is BGR, so the color card needs to manually change the RGB order to BGR first
colors = [[97, 57, 234], [80, 176, 0], [240, 176, 0], [201, 33, 113]] # 因为后面是cv2保存图像,cv2保存图像的顺序是BGR,所以颜色卡需要把RGB顺序变为BGR
The corresponding color of RGB is (after changing the order of the above code, the same color can be displayed as follows):
3. Only display the detection results with the same number of tags
detect.py
source参数
The setting in is test数据集
the location, the change in this section is to implement对test数据集进行检测时,只保留检测出来的标签数量=真实标签数量的检测图片效果
- Import packages at
detect.py
the topimport xml.etree.ElementTree as ET
Ctrl+F
Retrieve and locate# Process detections
the past, and then# Process detections
add the following code above
# ---------------lwd edit---------------- #
xml_path = path.replace('images', 'annotations').replace('jpg', 'xml')
xml_names_num = [0 for _ in range(len(names))]
# 检查类别个数是否对得上
tree = ET.parse(xml_path)
root = tree.getroot()
objects = root.findall('object')
for obj in objects:
cls = obj.find('name').text
xml_names_num[names.index(cls)] += 1
pred_names_num = [0 for _ in range(len(names))]
# ---------------lwd edit---------------- #
Ctrl+F
Search and# Save results
locate the past, and then# Save results
make the following changes below
if save_img and pred_names_num == xml_names_num: # lwd edit