-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpikamera.py
44 lines (38 loc) · 1.58 KB
/
pikamera.py
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
"""pikamera is an encapsulation of picamera
It only does three things:
Starts a preview
Stops a preview
Take a snapshot
If it is not running on a Pi, it just pretends to work
#"""
try:
from picamera import PiCamera
CAMERA = 'pi'
except:
CAMERA = 'pseudo'
from time import sleep
import shutil
if CAMERA == 'pi':
camera = PiCamera()
def Snapshot(config,path):
if CAMERA == 'pi':
camera.resolution = (int(config['app']['resolution_width']),int(config['app']['resolution_height']))
camera.start_preview(fullscreen=False,window=(int(config['app']['pvw_left_margin']),
int(config['app']['pvw_top_margin']),
int(config['app']['preview_width']),
int(config['app']['preview_height'])))
sleep(2)
camera.capture(path)
camera.stop_preview()
else:
shutil.copyfile('sample.jpg',path)
def Preview(config):
if CAMERA == 'pi':
camera.resolution = (int(config['app']['resolution_width']),int(config['app']['resolution_height']))
camera.start_preview(fullscreen=False,window=(int(config['app']['pvw_left_margin']),
int(config['app']['pvw_top_margin']),
int(config['app']['preview_width']),
int(config['app']['preview_height'])))
def Stop():
if CAMERA == 'pi':
camera.stop_preview()