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.

image_presence.py 1.9KB

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