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.

camera.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python3
  2. import time, subprocess
  3. import RPi.GPIO as GPIO
  4. from SCP import scp
  5. IR_PIN = 3
  6. GPIO.setmode(GPIO.BOARD)
  7. GPIO.setup(IR_PIN, GPIO.OUT)
  8. # set cameramode to normal; GPIO.LOW would enable infrared mode
  9. GPIO.output(IR_PIN, GPIO.HIGH)
  10. def person_detect():
  11. # initialize the HOG descriptor/person detector
  12. hog = cv2.HOGDescriptor()
  13. hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
  14. # loop over the image paths
  15. for imagePath in paths.list_images(args["images"]):
  16. # load the image and resize it to (1) reduce detection time
  17. # and (2) improve detection accuracy
  18. image = cv2.imread(imagePath)
  19. image = imutils.resize(image, width=min(400, image.shape[1]))
  20. orig = image.copy()
  21. # detect people in the image
  22. (rects, weights) = hog.detectMultiScale(image, winStride=(4, 4),
  23. padding=(8, 8), scale=1.05)
  24. # draw the original bounding boxes
  25. for (x, y, w, h) in rects:
  26. cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255), 2)
  27. # apply non-maxima suppression to the bounding boxes using a
  28. # fairly large overlap threshold to try to maintain overlapping
  29. # boxes that are still people
  30. rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
  31. pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)
  32. # draw the final bounding boxes
  33. for (xA, yA, xB, yB) in pick:
  34. cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)
  35. # show some information on the number of bounding boxes
  36. filename = imagePath[imagePath.rfind("/") + 1:]
  37. print("[INFO] {}: {} original boxes, {} after suppression".format(filename, len(rects), len(pick)))
  38. def main():
  39. i = 0
  40. try:
  41. while True:
  42. print("Gpio Low")
  43. time.sleep(2)
  44. # take image and scp it to the other pi
  45. print("take image...")
  46. subprocess.run(['raspistill', '-o', 'images/image' + str(i) + '.jpg'])
  47. #print("transfer image")
  48. #scp('images/image' + str(i) + '.jpg', '~/image' + str(i) + '.jpg', '192.168.252.1', 'pi', 'smarthome')
  49. i+=1
  50. if i>10:
  51. break
  52. #print("Gpio High")
  53. #GPIO.output(IR_PIN, GPIO.HIGH)
  54. #time.sleep(2)
  55. # take image and scp it to the other pi
  56. #print("take image...")
  57. #subprocess.run(['raspistill', '-o', 'image2.jpg'])
  58. #print("transfer image")
  59. #scp('image2.jpg', '~/image2.jpg', '192.168.252.1', 'pi', 'smarthome')
  60. #break
  61. except Exception as e:
  62. print(e)
  63. finally:
  64. GPIO.cleanup()
  65. #person_detect()
  66. if __name__ == '__main__':
  67. main()