[YOLOv7 adjusts detect.py] 1. Adjust the thickness of the detection frame, 2. Set the label color, 3. Only display the detection results with the same number of labels

1. Adjust the thickness of the detection frame

detect.pyPress and hold the Ctrl+Fsearch button in line_thicknessthe past 129, line_thicknessand change the size of the left and right rows, for example, change toline_thickness=3

2. Set label color

detect.pyPress and hold Ctrl+Fthe 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):

insert image description here

3. Only display the detection results with the same number of tags

detect.pysource参数The setting in is test数据集the location, the change in this section is to implement对test数据集进行检测时,只保留检测出来的标签数量=真实标签数量的检测图片效果

  1. Import packages at detect.pythe topimport xml.etree.ElementTree as ET
  2. Ctrl+FRetrieve and locate # Process detectionsthe past, and then # Process detectionsadd 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---------------- #

insert image description here

  1. Ctrl+FSearch and # Save resultslocate the past, and then # Save resultsmake the following changes below

insert image description here

            if save_img and pred_names_num == xml_names_num:    # lwd edit

Guess you like

Origin blog.csdn.net/LWD19981223/article/details/131610634