Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import numpy as np
- import picamera
- import picamera.array
- class DetectMotion(picamera.array.PiMotionAnalysis):
- def analyze(self, a):
- a = np.sqrt(
- np.square(a['x'].astype(np.float)) +
- np.square(a['y'].astype(np.float))
- ).clip(0, 255).astype(np.uint8)
- # If there're more than 10 vectors with a magnitude greater
- # than 60, then say we've detected motion
- if (a > 60).sum() > 10:
- print('Motion detected!')
- print('a = ',a)
- print('x = ','?')
- print('y = ','?')
- with picamera.PiCamera() as camera:
- with DetectMotion(camera) as output:
- camera.resolution = (640, 480)
- camera.start_recording(
- '/dev/null', format='h264', motion_output=output)
- camera.wait_recording(30)
- camera.stop_recording()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement