Initial support for picamera added
This commit is contained in:
64
photobooth/camera/CameraPicamera.py
Normal file
64
photobooth/camera/CameraPicamera.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Photobooth - a flexible photo booth software
|
||||||
|
# Copyright (C) 2018 Balthasar Reuter <photobooth at re - web dot eu>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
||||||
@@ -24,6 +24,7 @@ modules = (
|
|||||||
('gphoto2-commandline', 'CameraGphoto2CommandLine',
|
('gphoto2-commandline', 'CameraGphoto2CommandLine',
|
||||||
'CameraGphoto2CommandLine'),
|
'CameraGphoto2CommandLine'),
|
||||||
('opencv', 'CameraOpenCV', 'CameraOpenCV'),
|
('opencv', 'CameraOpenCV', 'CameraOpenCV'),
|
||||||
|
('picamera', 'CameraPicamera', 'CameraPicamera'),
|
||||||
('dummy', 'CameraDummy', 'CameraDummy'))
|
('dummy', 'CameraDummy', 'CameraDummy'))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ hide_cursor = False
|
|||||||
style = default
|
style = default
|
||||||
|
|
||||||
[Camera]
|
[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
|
module = python-gphoto2
|
||||||
|
|
||||||
[Gpio]
|
[Gpio]
|
||||||
|
|||||||
Reference in New Issue
Block a user