Created
July 16, 2019 15:08
-
-
Save mrmemmo/c6a91f0f7bc084b197b550f4feafe3f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import picamera | |
| import picamera.array | |
| import time | |
| baseImage = [] | |
| nextImage = [] | |
| def examineImage(): | |
| with picamera.PiCamera() as camera: | |
| camera.resolution = (64, 64) | |
| with picamera.array.PiRGBArray(camera) as output: | |
| camera.capture(output, 'rgb') | |
| image = output.array | |
| return image | |
| def compareArrays(image1, image2): | |
| diff = 0 | |
| for i in range(1, 60): | |
| #print(image1[i][0][0]) | |
| # print(image2[i][0][0]) | |
| if (image1[i][0][0] != image2[i][0][0]): | |
| diff += 1 | |
| return diff | |
| baseImage = examineImage() | |
| while True: | |
| time.sleep(5) | |
| nextImage = examineImage() | |
| if compareArrays(baseImage, nextImage)>40: | |
| #motion | |
| print("motion detected") | |
| baseImage = examineImage() | |
| else: | |
| print("no motion detected") | |
| print("Press Control-C to exit") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment