Created
February 27, 2015 16:48
-
-
Save miaoski/7638175fd1ee0989d4d4 to your computer and use it in GitHub Desktop.
picamera + PIR
This file contains 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
# -*- coding: utf8 -*- | |
import RPi.GPIO as GPIO | |
import time | |
import picamera | |
import datetime | |
SENSOR = 4 | |
CAMDIR = '/cam' | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(SENSOR, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
cam = picamera.PiCamera(resolution = (640,480)) | |
def get_file_name(): | |
fn = datetime.datetime.now().strftime("%Y%m%d-%H%M%S.h264") | |
d = fn[0:8] | |
if not os.path.isdir(os.path.join(CAMDIR, d)): | |
os.mkdir(os.path.join(CAMDIR, d)) | |
return os.path.join(CAMDIR, d, fn) | |
def recording(channel): | |
if GPIO.input(SENSOR): | |
fileName = get_file_name() | |
print 'Start recording to ' + fileName | |
#cam.start_preview() | |
cam.start_recording(fileName) | |
#camera.capture('foo.jpg') | |
else: | |
print 'Stop recording.' | |
#cam.stop_preview() | |
cam.stop_recording() | |
try: | |
GPIO.add_event_detect(SENSOR, GPIO.BOTH, callback=recording) | |
while True: | |
time.sleep(100) | |
except: | |
print 'Cleanup and quit.' | |
GPIO.cleanup() | |
cam.close() | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
按 7. Camera Hardware 的說明,其實 1926x972 15-30fps 才是符合硬體規格的設定,不過就先不管了...