[go: up one dir, main page]

Menu

[r219]: / calise / captured.py  Maximize  Restore  History

Download this file

76 lines (69 with data), 2.5 kB

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright (C) 2011 Nicolo' Barbon
#
# This file is part of Calise.
#
# Calise is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# Calise is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Calise. If not, see <http://www.gnu.org/licenses/>.
import time
from calise.capture import imaging
caliseCapture = imaging()
def takeScreenshot():
caliseCapture.scr_get()
return caliseCapture.scr
""" Picture taker (depends on gureatoCheck)
Takes n frames, one every i secs and returns a list object.
number: number of captures to be done each time a "capture" is asked
interval: time interval between captures in a single "capture" session
"""
def takeSomePic(number=7.0,interval=0.5):
camValues = []
for x in range(int(number)):
caliseCapture.cam_get()
camValues.append(caliseCapture.amb)
if x < number-1:
time.sleep(interval)
caliseCapture.stop_cam()
while True:
newVals = gureatoCheck(camValues)
if len(camValues) == len(newVals):
break
else:
camValues = newVals
return camValues
""" GURRRREATO CHECKER ONIZUKA
Searches given values for discordant ones, then return a "cleared" list
"""
def gureatoCheck(lista):
devList = []
for idx in range(len(lista)):
newList = lista[:idx]+lista[idx+1:]
avg = sum(newList)/float(len(newList))
dev = sDev(newList,avg)
devList.append(dev)
devListAvg = sum(devList)/len(devList)
devListDev = sDev(devList,devListAvg)
toBeErased = []
for idx in range(len(lista)):
try:
if devListDev > 0.75 and \
((devList[idx]-devListAvg)**2)**.5 > devListDev :
del lista[idx]
except IndexError:
break
return lista
# siple standard deviation function
def sDev(lista,average=None):
if not average:
average = sum(lista)/float(len(lista))
dev = (sum([(x-average)**(2) for x in lista])/float(len(lista)))**(.5)
return dev