opencv python中的绘图头检测边界框

问题描述 投票:0回答:1

我有需要检测一个人的head的情况。为此,我正在使用人员检测模型,然后使用人员边界框提取人员的头部。

person_detector.setInput(blob)
person_detections = person_detector.forward()
boundingboxes = np.array([])
for i in np.arange(0, person_detections.shape[2]):
    person_det_confidence = person_detections[0, 0, i, 2]

    if person_det_confidence > 0.40:
        # extract the index of the class label from the
        # detections list
        idx = int(person_detections[0, 0, i, 1])

        # if the class label is not a person, ignore it
        if CLASSES[idx] != "person":
            continue

        # compute the (x, y)-coordinates of the bounding box
        # for the object
        person_box = person_detections[0, 0, i, 3:7] * np.array([W, H, W, H])
        (startX, startY, endX, endY) = person_box.astype("int")

        # Only append the person which are inside ROI
        if roix1 < startX < roix2:
            rects.append(person_box)

boundingboxes = np.array(rects)
boundingboxes = boundingboxes.astype(int)
person_rects = helper.non_max_suppression_fast(boundingboxes, 0.3)

head_rects = []

for (startX, startY, endX, endY) in person_rects:
    img = frame[startY: startY + endY, startX: startX + endX]
    (startX, startY, endX, endY) = detect_head(img)
    p = (startX, startY, endX, endY)
    head_rects.append(p)

在以上代码中,person_rects包含检测到的人的名字。我们将其传递给函数detect_head,该函数返回保存在head_rects中的头部边界框。

head_rects看起来如下:

startX = 0
startY = 4
endX = 384
endY = 61

现在,如果我使用上述坐标绘制矩形:

cv2.rectangle(frame, (startX, startY), (endX, endY), (0, 0, 255), 2)

绘制不正确:

enter image description here

在上图中,您可以看到在框架的左上方绘制了红色矩形,而矩形应该是女士站在框架中的位置。原因是,检测到的头部的坐标是相对于人的,而不是相对于框架的,因此在显示时会被错误地绘制。任何人都可以给我一些有关如何纠正它的想法。请帮忙。谢谢

python opencv frame bounding-box
1个回答
0
投票

遇到相同的确切问题,您是如何解决的?

© www.soinside.com 2019 - 2024. All rights reserved.