不同类别对象的多个颜色边界框

2024-10-01 13:25:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在实现“面向BBAVectors的对象检测”https://github.com/yijingru/BBAVectors-Oriented-Object-Detection模型。对模型进行测试后,所有检测到的对象都显示为相同颜色的边框

下面是指向test.py代码https://github.com/yijingru/BBAVectors-Oriented-Object-Detection/blob/master/test.py的链接。我发现下面这行代码改变了边界框的颜色

ori_image = cv2.drawContours(ori_image, [np.int0(box)], -1, (255,0,255),1,1)

然而,它一次只需要一种颜色

此外,在“面向对象检测的BBAVectors”的另一个文件“dataset_dota.py”https://github.com/yijingru/BBAVectors-Oriented-Object-Detection/blob/master/datasets/dataset_dota.py中,我找到了分配给每个对象类别的颜色

class DOTA(BaseDataset):
    def __init__(self, data_dir, phase, input_h=None, input_w=None, down_ratio=None):
        super(DOTA, self).__init__(data_dir, phase, input_h, input_w, down_ratio)
        self.category = ['plane',
                         'baseball-diamond',
                         'bridge',
                         'ground-track-field',
                         'small-vehicle',
                         'large-vehicle',
                         'ship',
                         'tennis-court',
                         'basketball-court',
                         'storage-tank',
                         'soccer-ball-field',
                         'roundabout',
                         'harbor',
                         'swimming-pool',
                         'helicopter'
                         ]
        self.color_pans = [(204,78,210),
                           (0,192,255),
                           (0,131,0),
                           (240,176,0),
                           (254,100,38),
                           (0,0,255),
                           (182,117,46),
                           (185,60,129),
                           (204,153,255),
                           (80,208,146),
                           (0,0,204),
                           (17,90,197),
                           (0,255,255),
                           (102,255,102),
                           (255,255,0)]
        self.num_classes = len(self.category)
        self.cat_ids = {cat:i for i,cat in enumerate(self.category)}
        self.img_ids = self.load_img_ids()
        self.image_path = os.path.join(data_dir, 'images')
        self.label_path = os.path.join(data_dir, 'labelTxt')

我对Python和Opencv比较熟悉。如果有人能帮助我链接这些文件,并在不同的颜色边界框中显示检测到的对象,或者用另一种方法在不同的颜色边界框中显示不同的对象类别,我将不胜感激。多谢各位

在当前版本中,检测到的对象如下所示:

detected samples


Tags: path对象pyhttpsselfgithubcominput
1条回答
网友
1楼 · 发布于 2024-10-01 13:25:48

以下是一个片段:

# Initialize the DOTA Class 
dota_object = DOTA(data_dir, phase)

# Get color 
object = 'plane'
id = dota_object.category.index(object)
color = dota_object.color_pans[id]

# Display the image
ori_image = cv2.drawContours(ori_image, [np.int0(box)], -1, color,1,1)

将变量替换为代码中的变量(ori_imagedota_objectdata_dirphase

相关问题 更多 >