Files
@ f4d822fe8861
Branch filter:
Location: light9/bin/captureDevice - annotation
f4d822fe8861
5.3 KiB
text/plain
subserver old code
Ignore-this: 105bd538f0096f4d0d5c1ced35b04f25
Ignore-this: 105bd538f0096f4d0d5c1ced35b04f25
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | fc5675f5b756 fc5675f5b756 0aad247a1168 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 17da56a3c8df fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 17da56a3c8df fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 17da56a3c8df 17da56a3c8df fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 2239d5648932 2239d5648932 2239d5648932 2239d5648932 2239d5648932 0aad247a1168 2239d5648932 0aad247a1168 2239d5648932 0aad247a1168 17da56a3c8df 0aad247a1168 0aad247a1168 0aad247a1168 fc5675f5b756 0aad247a1168 0aad247a1168 0aad247a1168 fc5675f5b756 0aad247a1168 2239d5648932 2239d5648932 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 2239d5648932 2239d5648932 2239d5648932 0aad247a1168 fc5675f5b756 17da56a3c8df 17da56a3c8df 17da56a3c8df 17da56a3c8df 17da56a3c8df 17da56a3c8df 17da56a3c8df 17da56a3c8df 17da56a3c8df 0aad247a1168 0aad247a1168 0aad247a1168 2239d5648932 2239d5648932 2239d5648932 2239d5648932 0aad247a1168 fc5675f5b756 0aad247a1168 0aad247a1168 2239d5648932 2239d5648932 fc5675f5b756 fc5675f5b756 0aad247a1168 fc5675f5b756 2239d5648932 2239d5648932 2239d5648932 fc5675f5b756 2239d5648932 2239d5648932 0aad247a1168 0aad247a1168 17da56a3c8df 17da56a3c8df 17da56a3c8df fc5675f5b756 2239d5648932 0aad247a1168 fc5675f5b756 17da56a3c8df 17da56a3c8df 17da56a3c8df 0aad247a1168 0aad247a1168 0aad247a1168 fc5675f5b756 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 0aad247a1168 2239d5648932 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 fc5675f5b756 | #!bin/python
from __future__ import division
from rdflib import URIRef
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, Deferred
import logging
import optparse
import os
import time
import treq
import cyclone.web, cyclone.websocket, cyclone.httpclient
from greplin import scales
from run_local import log
from lib.cycloneerr import PrettyErrorHandler
from light9.namespaces import L9, RDF
from light9 import networking, showconfig
from light9.rdfdb.syncedgraph import SyncedGraph
from light9.paint.capture import writeCaptureDescription
from light9.greplin_cyclone import StatsForCyclone
from light9.effect.settings import DeviceSettings
from light9.effect.sequencer import sendToCollector
from light9.rdfdb.patch import Patch
stats = scales.collection('/webServer', scales.PmfStat('setAttr'))
class Camera(object):
def __init__(self, imageUrl):
self.imageUrl = imageUrl
def takePic(self, uri, writePath):
log.info('takePic %s', uri)
return treq.get(self.imageUrl).addCallbacks(
lambda r: self._done(writePath, r), log.error)
@inlineCallbacks
def _done(self, writePath, response):
jpg = yield response.content()
try:
os.makedirs(os.path.dirname(writePath))
except OSError:
pass
with open(writePath, 'w') as out:
out.write(jpg)
log.info('wrote %s', writePath)
def deferSleep(sec):
d = Deferred()
reactor.callLater(sec, d.callback, None)
return d
class Capture(object):
firstMoveTime = 3
settleTime = .5
def __init__(self, graph, dev):
self.graph = graph
self.dev = dev
def steps(a, b, n):
return [round(a + (b - a) * i / n, 5) for i in range(n)]
startTime = time.time()
self.captureId = 'cap%s' % (int(startTime) - 1495170000)
self.toGather = []
row = 0
for ry in steps(0.82, .92, 6):
xSteps = steps(.23, .42, 12)
if row % 2:
xSteps.reverse()
row += 1
for rx in xSteps:
self.toGather.append(DeviceSettings(graph, [
(dev, L9['rx'], rx),
(dev, L9['ry'], ry),
(dev, L9['color'], '#ffffff'),
]))
self.devTail = dev.rsplit('/')[-1]
self.session = URIRef('/'.join([showconfig.showUri(),
'capture', self.devTail, self.captureId]))
self.ctx = URIRef(self.session + '/index')
self.graph.patch(Patch(addQuads=[
(self.session, RDF.type, L9['CaptureSession'], self.ctx),
]))
self.numPics = 0
self.settingsCache = set()
self.step().addErrback(log.error)
def off(self):
return sendToCollector(client='captureDevice', session='main',
settings=DeviceSettings(self.graph, []))
@inlineCallbacks
def step(self):
if not self.toGather:
yield self.off()
yield deferSleep(1)
reactor.stop()
return
settings = self.toGather.pop()
log.info('[%s left] move to %r', len(self.toGather), settings)
yield sendToCollector(client='captureDevice', session='main',
settings=settings)
yield deferSleep(self.firstMoveTime if self.numPics == 0 else
self.settleTime)
picId = 'pic%s' % self.numPics
path = '/'.join([
'capture', self.devTail, self.captureId, picId]) + '.jpg'
uri = URIRef(self.session + '/' + picId)
yield camera.takePic(uri, os.path.join(showconfig.root(), path))
self.numPics += 1
writeCaptureDescription(self.graph, self.ctx, self.session, uri,
self.dev,
path, self.settingsCache, settings)
reactor.callLater(0, self.step)
camera = Camera('http://dash:8200/picamserve/pic?res=480&resize=480&rotation=180&iso=800&redgain=1.6&bluegain=2&shutter=60000')
class Attrs(PrettyErrorHandler, cyclone.web.RequestHandler):
def put(self):
with stats.setAttr.time():
client, clientSession, settings, sendTime = parseJsonMessage(self.request.body)
self.set_status(202)
def launch(graph):
cap = Capture(graph, dev=L9['device/moving1'])
reactor.listenTCP(networking.captureDevice.port,
cyclone.web.Application(handlers=[
(r'/()', cyclone.web.StaticFileHandler,
{"path" : "light9/web", "default_filename" : "captureDevice.html"}),
(r'/stats', StatsForCyclone),
]),
interface='::')
log.info('serving http on %s', networking.captureDevice.port)
def main():
parser = optparse.OptionParser()
parser.add_option("-v", "--verbose", action="store_true",
help="logging.DEBUG")
(options, args) = parser.parse_args()
log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
graph = SyncedGraph(networking.rdfdb.url, "captureDevice")
graph.initiallySynced.addCallback(lambda _: launch(graph)).addErrback(log.error)
reactor.run()
if __name__ == '__main__':
main()
|