def find_people(self, img):
'''
Detect people in image
:param img: numpy.ndarray
:return: count of rectangles after non-maxima suppression, corresponding to number of people detected in picture
'''
t = time.time()
# HOG descriptor/person detector
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
# Chooses whichever size is less
image = imutils.resize(img, width=min(self.MIN_IMAGE_WIDTH, img.shape[1]))
# detect people in the image
(rects, wghts) = hog.detectMultiScale(image, winStride=self.WIN_STRIDE,
padding=self.PADDING, scale=self.SCALE)
# apply non-maxima suppression to the bounding boxes but use a fairly large overlap threshold,
# to try to maintain overlapping boxes that are separate people
rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
pick = non_max_suppression(rects, probs=None, overlapThresh=self.OVERLAP_THRESHOLD)
print("Elapsed time: {} seconds".format(int((time.time() - t) * 100) / 100.0))
if self.SHOW_IMAGES:
# draw the final bounding boxes
for (xA, yA, xB, yB) in pick:
# Tighten the rectangle around each person by a small margin
shrinkW, shrinkH = int(0.05 * xB), int(0.15*yB)
cv2.rectangle(image, (xA+shrinkW, yA+shrinkH), (xB-shrinkW, yB-shrinkH), self.BOX_COLOR, 2)
cv2.imshow("People detection", image)
cv2.waitKey(self.IMAGE_WAIT_TIME)
cv2.destroyAllWindows()
return len(pick)
detect_from_camera.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录