我有一个场景需要检测一个人的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
包含检测到的person的rect。我们将其传递给函数detect_head
,该函数返回保存在head矩形中的head边界框
head_rects
如下所示:
startX = 0
startY = 4
endX = 384
endY = 61
现在,如果我使用上述坐标绘制一个矩形:
cv2.rectangle(frame, (startX, startY), (endX, endY), (0, 0, 255), 2)
画得不正确:
在上图中,您可以看到红色矩形绘制在框架的左上方,而它应该是女士站在框架中的位置。原因是,检测到的头部坐标是相对于人的,而不是相对于帧的,因此在显示时绘制错误。有人能告诉我怎么改正吗。请帮忙。谢谢
目前没有回答
相关问题 更多 >
编程相关推荐