Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2105 - 1
import numpy as np
2
#np.set_printoptions(threshold=np.nan)
3
import picamera
4
import picamera.array
5
import sys
6
import os
7
import time
8
import mmap
9
 
10
##>> Gain access to MMAP
11
##------------------------------------------------------------------------------------------------------
12
INDATAFILENAME = '/home/pi/ExPlat/input.dat'
13
LENGTHDATAMAP = 1024
14
inDataFile = open(INDATAFILENAME, 'r+')
15
inDataNo = inDataFile.fileno()
16
inDataMap = mmap.mmap(inDataNo, LENGTHDATAMAP, access=mmap.ACCESS_WRITE)
17
s = 0;
18
 
19
##>> Analyze Numpy Array and Print Motion Vector Data
20
##------------------------------------------------------------------------------------------------------
21
class AnalyzeArray(picamera.array.PiMotionAnalysis):
22
    def analyse(self, a):
23
            global s
24
            global inDataMap
25
            s += a[20,15][0]
26
            #print s
27
            inDataMap.seek(0)
28
            inDataMap.write('%d' %s + '\n')
29
 
30
##>> Start Capture and call AnalyzeArray after every frame
31
##------------------------------------------------------------------------------------------------------
32
def get_values():
33
    with picamera.PiCamera() as camera:
34
        with AnalyzeArray(camera) as output:
35
            camera.resolution = (640, 480)
36
            camera.framerate = (20, 1)
37
            camera.start_recording(
38
                '/dev/null', format='h264', motion_output=output)
39
            camera.wait_recording(0)
40
            camera.stop_recording()