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!')
else:
print('No motion')
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(5)
camera.stop_recording()
这是使用运动检测矢量的树莓派相机的。
如果此代码检测到运动,它将录制5秒钟的视频。我的问题是,如果它仍在检测运动,我想再次使此代码camera.wait_recording(5)
。这意味着如果它检测到运动,则camera.wait_recording
的值仍为5秒,如果未检测到运动,则camera.wait_recording
的值将开始衰减。