'full': {'type': 'array', 'items': {'type': 'integer'},
'minItems': 2, 'maxItems': 2},
'web': {'type': 'array', 'items': {'type': 'integer'},
- 'minItems': 2, 'maxItems': 2},
- 'thumb': {'type': 'array', 'items': {'type': 'integer'},
- 'minItems': 2, 'maxItems': 2}},
+ 'minItems': 2, 'maxItems': 2}},
'required': ['pause', 'keep', 'path']}
async def _receive(self, message: Message) -> None:
if message['command'] == 'get image':
if len(self._images) > 0:
await self.bus.send(Message(self.name,
- {'image': self._images[0][0],
- 'date': self._images[0][1]}))
+ {'image': self._images[-1][0],
+ 'date': self._images[-1][1]}))
elif message['command'] == 'start capture':
self._capture = True
elif message['command'] == 'stop capture':
self._web = (640, 480)
if 'web' in self.conf:
self._web = self.conf['web']
- self._thumb = (160, 120)
- if 'thumb' in self.conf:
- self._thumb = self.conf['thumb']
sends = [MessageTemplate({'event': {'const': 'new image'},
'image': {'type': 'string'},
'date': {'type': 'string'}}),
camera = picamera.PiCamera()
camera.iso = self._iso
camera.resolution = self._full
- web_path = os.path.join(self.conf['path'], 'web.jpg')
- thumb_path = os.path.join(self.conf['path'], 'thumb.jpg')
try:
while True:
if self._capture:
camera.awb_gains = gains
while self._capture:
while len(self._images) >= self.conf['keep']:
- file_name = self._images.popleft()[0]
- file_path = os.path.join(self.conf['path'],
- file_name)
- await aiofiles.os.remove(file_path)
+ full_name = self._images.popleft()[0]
+ full_path = os.path.join(self.conf['path'],
+ full_name)
+ if os.path.isfile(full_path):
+ await aiofiles.os.remove(full_path)
+ web_name = 'web-'+full_name
+ web_path = os.path.join(self.conf['path'],
+ web_name)
+ if os.path.isfile(web_path):
+ await aiofiles.os.remove(web_path)
timestamp = datetime.datetime.now()
iso_time = timestamp.strftime('%Y-%m-%d %H:%M:%S')
full_name = timestamp.strftime('%Y%m%d%H%M%S%f')+'.jpg'
+ web_name = 'web-'+full_name
full_path = os.path.join(self.conf['path'], full_name)
+ web_path = os.path.join(self.conf['path'], web_name)
stream = io.BytesIO()
await loop.run_in_executor(
executor,
executor,
functools.partial(
web_image.save, web_path))
- thumb_image = await loop.run_in_executor(
- executor,
- functools.partial(
- full_image.resize,
- self._thumb,
- PIL.Image.ANTIALIAS))
- await loop.run_in_executor(
- executor,
- functools.partial(
- thumb_image.save, thumb_path))
stream.close()
self._images.append((full_name, iso_time))
await self.bus.send(Message(self.name,
camera.stop_preview()
camera.close()
while len(self._images) > 0:
- file_name = self._images.popleft()[0]
- file_path = os.path.join(self.conf['path'],
- file_name)
- os.remove(file_path)
- if os.path.isfile(web_path):
- os.remove(web_path)
- if os.path.isfile(thumb_path):
- os.remove(thumb_path)
+ full_name = self._images.popleft()[0]
+ full_path = os.path.join(self.conf['path'], full_name)
+ if os.path.isfile(full_path):
+ os.remove(full_path)
+ web_name = 'web_'+full_name
+ web_path = os.path.join(self.conf['path'], web_name)
+ if os.path.isfile(web_path):
+ os.remove(web_path)
executor.shutdown(True)
raise