为什么中心点与对象不匹配?

2024-06-02 14:03:28 发布

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

我想跟踪一个目标的基础上,中心点和检测,我用级联算法。我使用的是本页的质心跟踪算法https://www.pyimagesearch.com/2018/07/23/simple-object-tracking-with-opencv/

在这篇文章中-https://www.pyimagesearch.com/2018/07/23/simple-object-tracking-with-opencv/。作者采用了一种深度神经网络算法进行检测,我想用级联。但是当我将边界框作为rec传递给detect centers时,它只在每个对象的帧上显示一个ID点,但它并不完全位于每个对象的中心。在下面,我添加了一张我的结果照片。 非常感谢

```
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
body = fullbody_cascade.detectMultiScale(gray, 1.3, 5)
rects = []
for (i, (startX, startY, endX, endY)) in enumerate(body):
    if endY < 85:
    rects.append(body[i].astype('int'))
    pad_w, pad_h = int(0.15 * endX), int(0.05 * endY)
    cv2.rectangle(frame, (startX + pad_w, startY - pad_h), (startX + endX - 
                  pad_w, startY + endY - pad_h), (0, 255, 0), 2)

# here pass the rects to find centers
objects = ct.update(rects)
for (objectID, centeroid) in objects.items():
     text = "Id {}".format(objectID)
     cv2.putText(frame, text, (centeroid[0] - 10, centeroid[1] - 10), 
                 cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
     cv2.circle(frame, (centeroid[0], centeroid[1]), 3, (0, 255, 0), -1)
```

enter image description here


Tags: https算法wwwbodycv2frame级联int