-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCameraMockup.py
65 lines (53 loc) · 1.65 KB
/
CameraMockup.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
"""Class for cameras connected to framegrabbers run by Taco Device Servers
"""
from HardwareRepository import BaseHardwareObjects
import logging
import os
import gevent
import time
import numpy
from PIL import Image
import cStringIO
class CameraMockup(BaseHardwareObjects.Device):
def __init__(self,name):
BaseHardwareObjects.Device.__init__(self,name)
self.liveState = False
def _init(self):
self.setIsReady(True)
def init(self):
self.imagegen = None
def imageGenerator(self, delay):
while True:
newImage = self.getOneImage()
self.emit("imageReceived", newImage, 650, 485)
time.sleep(delay)
def getOneImage(self):
a = numpy.random.rand(485,650) * 255
im_out = Image.fromarray(a.astype('uint8')).convert('RGBA')
buf = cStringIO.StringIO()
im_out.save(buf,"JPEG")
return buf
def contrastExists(self):
return False
def brightnessExists(self):
return False
def gainExists(self):
return False
def setLive(self, live):
print "Setting camera live ", live
if live and self.liveState == live:
return
if live:
self.imagegen = gevent.spawn(self.imageGenerator, (self.getProperty("interval") or 500)/1000.0 )
self.liveState = live
else:
self.imagegen.kill()
self.liveState = live
return True
def imageType(self):
return None
def takeSnapshot(self, *args):
jpeg_data=self.getOneImage()
f = open(*(args + ("w",)))
f.write("".join(map(chr, jpeg_data)))
f.close()