diff --git a/photobooth/camera/CameraPicamera.py b/photobooth/camera/CameraPicamera.py new file mode 100644 index 0000000..79b8cf7 --- /dev/null +++ b/photobooth/camera/CameraPicamera.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Photobooth - a flexible photo booth software +# Copyright (C) 2018 Balthasar Reuter +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import io +import logging + +from PIL import Image + +from picamera import PiCamera + +from . import Camera + + +class CameraPicamera(Camera): + + def __init__(self): + + super().__init__() + + self.hasPreview = True + self.hasIdle = True + + logging.info('Using PiCamera') + + self._cap = PiCamera() + + def setActive(self): + + if self._cap.closed: + self._cap = PiCamera() + + def setIdle(self): + + if not self._cap.closed: + self._cap.close() + + def getPreview(self): + + return self.getPicture() + + def getPicture(self): + + self.setActive() + + stream = io.BytesIO() + self._cap.capture(stream, format='rgb') + stream.seek(0) + return Image.fromarray(stream) diff --git a/photobooth/camera/__init__.py b/photobooth/camera/__init__.py index e3d87bc..98083f6 100644 --- a/photobooth/camera/__init__.py +++ b/photobooth/camera/__init__.py @@ -24,6 +24,7 @@ modules = ( ('gphoto2-commandline', 'CameraGphoto2CommandLine', 'CameraGphoto2CommandLine'), ('opencv', 'CameraOpenCV', 'CameraOpenCV'), + ('picamera', 'CameraPicamera', 'CameraPicamera'), ('dummy', 'CameraDummy', 'CameraDummy')) diff --git a/photobooth/defaults.cfg b/photobooth/defaults.cfg index d581446..e33f27d 100644 --- a/photobooth/defaults.cfg +++ b/photobooth/defaults.cfg @@ -13,7 +13,8 @@ hide_cursor = False style = default [Camera] -# Camera module to use (python-gphoto2, gphoto2-cffi, gphoto2-commandline, opencv) +# Camera module to use (python-gphoto2, gphoto2-cffi, gphoto2-commandline, +# opencv, picamera, dummy) module = python-gphoto2 [Gpio]