import os
import picamera # type: ignore
import PIL.Image # type: ignore
-import time
from controlpi import BasePlugin, Message, MessageTemplate
camera.awb_gains = gains
while self._capture:
while len(self._images) >= self.conf['keep']:
- 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)
+ file_name = self._images.popleft()[0]
+ file_path = os.path.join(self.conf['path'],
+ file_name)
+ if os.path.isfile(file_path):
+ await aiofiles.os.remove(file_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)
- start_direct = time.perf_counter()
- await loop.run_in_executor(
- executor,
- functools.partial(
- camera.capture,
- full_path,
- 'jpeg',
- use_video_port=True))
- end_direct = time.perf_counter()
- print(f"Direct: {end_direct - start_direct}")
- start_pil = time.perf_counter()
+ file_name = timestamp.strftime('%Y%m%d%H%M%S%f')+'.jpg'
+ file_path = os.path.join(self.conf['path'], file_name)
stream = io.BytesIO()
await loop.run_in_executor(
executor,
'jpeg',
use_video_port=True))
stream.seek(0)
- full_image = await loop.run_in_executor(
+ image = await loop.run_in_executor(
executor,
functools.partial(PIL.Image.open, stream))
await loop.run_in_executor(
executor,
- functools.partial(
- full_image.save, web_path))
+ functools.partial(image.save, file_path))
stream.close()
- end_pil = time.perf_counter()
- print(f"PIL: {end_pil - start_pil}")
- self._images.append((full_name, iso_time))
+ self._images.append((file_name, iso_time))
await self.bus.send(Message(self.name,
{'event': 'new image',
- 'image': full_name,
+ 'image': file_name,
'date': iso_time}))
await asyncio.sleep(self.conf['pause'])
camera.stop_preview()
camera.stop_preview()
camera.close()
while len(self._images) > 0:
- 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)
+ file_name = self._images.popleft()[0]
+ file_path = os.path.join(self.conf['path'], file_name)
+ if os.path.isfile(file_path):
+ os.remove(file_path)
executor.shutdown(True)
raise