Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

person-detection.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # import the necessary packages
  2. from __future__ import print_function
  3. from imutils.object_detection import non_max_suppression
  4. from imutils import paths
  5. import numpy as np
  6. import argparse
  7. import imutils
  8. import cv2
  9. # construct the argument parse and parse the arguments
  10. ap = argparse.ArgumentParser()
  11. ap.add_argument("-i", "--images", required=True, help="path to images directory")
  12. args = vars(ap.parse_args())
  13. # initialize the HOG descriptor/person detector
  14. hog = cv2.HOGDescriptor()
  15. hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
  16. # loop over the image paths
  17. for imagePath in paths.list_images(args["images"]):
  18. # load the image and resize it to (1) reduce detection time
  19. # and (2) improve detection accuracy
  20. image = cv2.imread(imagePath)
  21. image = imutils.resize(image, width=min(400, image.shape[1]))
  22. orig = image.copy()
  23. # detect people in the image
  24. (rects, weights) = hog.detectMultiScale(image, winStride=(4, 4),
  25. padding=(8, 8), scale=1.05)
  26. # draw the original bounding boxes
  27. for (x, y, w, h) in rects:
  28. cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255), 2)
  29. # apply non-maxima suppression to the bounding boxes using a
  30. # fairly large overlap threshold to try to maintain overlapping
  31. # boxes that are still people
  32. rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
  33. pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)
  34. # draw the final bounding boxes
  35. for (xA, yA, xB, yB) in pick:
  36. cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)
  37. # show some information on the number of bounding boxes
  38. filename = imagePath[imagePath.rfind("/") + 1:]
  39. print("[INFO] {}: {} original boxes, {} after suppression".format(filename, len(rects), len(pick)))
  40. # show the output images
  41. #cv2.imshow("Before NMS", orig)
  42. #cv2.imshow("After NMS", image)
  43. #cv2.waitKey(0)