2-3-3. 監視カメラ Python PGM List

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/env /usr/bin/python
# -*- coding: utf-8 -*-
 
import picamera
import time
import RPi.GPIO as GPIO
 
PICTURE_WIDTH = 640
PICTURE_HEIGHT = 480
SAVEDIR = "/usr/share/nginx/www/camera/pictures/"
 
INTAVAL = 600
SLEEPTIME = 5
 
SENSOR_PIN = 9
 
GPIO.cleanup()
 
GPIO.setmode( GPIO.BCM )
GPIO.setup( SENSOR_PIN, GPIO.IN )
 
cam = picamera.PiCamera()
cam.resolution = ( PICTURE_WIDTH, PICTURE_HEIGHT )
 
st = time.time() - INTAVAL
 
while True:
    if ( GPIO.input(SENSOR_PIN) == GPIO.HIGH ) and (st + INTAVAL < time.time() ):
        st = time.time()
        filename = time.strftime( "%Y%m%d%H%M%S" ) + ".jpg"
        save_file = SAVEDIR + filename
        cam.capture( save_file )
     
    time.sleep( SLEEPTIME )






プログラムほか