-
Notifications
You must be signed in to change notification settings - Fork 2
/
berryCam-raspistill.py
100 lines (78 loc) · 4.17 KB
/
berryCam-raspistill.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
#
# BerryCam.py
# BerryCam - Raspberry Pi Camera Controller for use with iOS devices
#
# Created by James Moore on 17/08/2020
# Copyright (c) 2013-2020 Fotosyn. All rights reserved.
#
# Raspberry Pi is a trademark of the Raspberry Pi Foundation.
# iOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used by Apple Inc. under license.
#
import http.server
import socketserver
import os
from urllib import parse
port = 8000
handler = http.server.SimpleHTTPRequestHandler
class BerryCamHandler (http.server.SimpleHTTPRequestHandler):
print("B E R R Y C A M -- Listening on port ", port, flush=True)
print("Please ensure your BerryCam App is installed and running on your iOS Device", flush=True)
def do_GET(self):
parsed_url = parse.urlsplit(self.path)
parsed_query = parse.parse_qs(parsed_url.query)
parsed_dictionary = dict(parse.parse_qsl(parsed_url.query))
if parsed_url.path == "/berrycam":
directory = 'berrycam/' + parsed_dictionary['ffolder']
if not os.path.exists(directory):
os.makedirs(directory)
# Build up a raspistill command line string
command = "raspistill -v" # Initiate command for Raspistill
command += " -awb " + parsed_dictionary['awb'] # Define WB
command += " -mm " + parsed_dictionary['mm'] # Define Metering Mode
command += " -ev " + parsed_dictionary['ev'] # Define the Exposure Adjustment
command += " -ex " + parsed_dictionary['ex'] # Define Exposure Mode
command += " -sh " + parsed_dictionary['sh'] # Define Image Sharpness
command += " -br " + parsed_dictionary['br'] # Define Image Brightness
command += " -co " + parsed_dictionary['co'] # Define Image Contrast
command += " -sa " + parsed_dictionary['sa'] # Define Image Saturation
command += " -ISO " + parsed_dictionary['iso'] # Define Image ISO
command += " -drc " + parsed_dictionary['drc'] # Define Image dynamic range compres$
if parsed_dictionary['ss'] != "1":
command += " -ss " + parsed_dictionary['ss'] # Define shutter speed STILL TO BE IMPLEMENTED
command += " -ifx " + parsed_dictionary['ifx'] # Define Image Effect
command += " -q " + parsed_dictionary['fquality'] # Define Image Quality
command += " -w " + parsed_dictionary['fwidth'] # Define output image width
command += " -h " + parsed_dictionary['fheight'] # Define output image height
command += " -o berrycam/" + parsed_dictionary['ffolder'] + "/IMG-" + parsed_dictionary['fseq'] +".jpg"
if parsed_dictionary['hf'] == "1":
command += " -hf "
else:
command += ""
if parsed_dictionary['vf'] == "1":
command += " -vf "
else:
command += ""
if 'gpsLat' in parsed_dictionary:
#command += " -gps" Not needed
command += " -x GPS.GPSLatitude=" + parsed_dictionary['gpsLat']
command += " -x GPS.GPSLongitude=" + parsed_dictionary['gpsLon']
command += " -x GPS.GPSAltitude=" + parsed_dictionary['gpsAlt']
command += " -x GPS.GPSLatitudeRef=" + parsed_dictionary['gpsLatRef']
command += " -x GPS.GPSLongitudeRef=" + parsed_dictionary['gpsLonRef']
command += " -x GPS.GPSImgDirection=1"
command += " -x GPS.GPSTimeStamp=1"
if parsed_dictionary['ao'] == "1":
command += " -a 1024"
command += " -a " + "\"" + parsed_dictionary['a'] + "\""
command += " -ae " + parsed_dictionary['ae']
os.system(command)
self.send_response(200)
self.end_headers()
return
else:
http.server.SimpleHTTPRequestHandler.do_GET(self)
self.end_headers()
return
with socketserver.TCPServer(("", port), BerryCamHandler) as httpd:
httpd.serve_forever()