YOLO对象检测opencv绘制很多矩形

时间:2020-05-14 09:29:18

标签: opencv yolo

我收集了S9手机的图像,并在labellmg中添加了标签,并在google colab中接受了几个小时的培训。我的损失很小,所以我认为足够了。我只选择了显示电话的矩形,而没有其他选择。我不明白的是,它在电话上绘制了许多矩形。我只想在手机上绘制1或2个矩形。我做错什么了吗?

def detect_img(self, img):
    blob = cv2.dnn.blobFromImage(img, 0.00392 ,(416,416), (0,0,0), True, crop=False)
    input_img = self.net.setInput(blob)
    output = self.net.forward(self.output)

    height, width, channel = img.shape
    boxes = []
    trusts = []
    class_ids = []

    for out in output:
        for detect in out:
            total_scores = detect[5:]
            class_id = np.argmax(total_scores)
            trust_factor = total_scores[class_id]
            if trust_factor > 0.5:
                x_center = int(detect[0] * width)
                y_center = int(detect[1] * height)
                w = int(detect[2] * width)
                h = int(detect[3] * height)
                x = int(x_center - w / 2)
                y = int(x_center - h / 2)
                boxes.append([x,y,w,h])
                trusts.append(float(trust_factor))
                class_ids.append(class_id)
                cv2.rectangle(img, (x_center,y_center), (x + w, y + h), (0,255,0), 2)


当我将trust_factor设置为0.8时,许多矩形消失了,但电话外部仍然有矩形,而我只在labellmg中选择了电话本身,而不是背景。

Result

0 个答案:

没有答案