我有一个场景需要检测
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矩形中的head边界框。
head_rects
如下所示:
startX = 0
startY = 4
endX = 384
endY = 61
cv2.rectangle(frame, (startX, startY), (endX, endY), (0, 0, 255), 2)
画得不正确: