Added rotation of camera, closes #45
This commit is contained in:
@@ -52,6 +52,10 @@ class Camera:
|
||||
self._is_preview = self._cfg.getBool('Photobooth', 'show_preview')
|
||||
self._is_keep_pictures = self._cfg.getBool('Storage', 'keep_pictures')
|
||||
|
||||
rot_vals = {0: None, 90: Image.ROTATE_90, 180: Image.ROTATE_180,
|
||||
270: Image.ROTATE_270}
|
||||
self._rotation = rot_vals[self._cfg.getInt('Camera', 'rotation')]
|
||||
|
||||
def startup(self):
|
||||
|
||||
self._cap = self._cam()
|
||||
@@ -59,8 +63,11 @@ class Camera:
|
||||
logging.info('Using camera {} preview functionality'.format(
|
||||
'with' if self._is_preview else 'without'))
|
||||
|
||||
self._pic_dims = PictureDimensions(self._cfg,
|
||||
self._cap.getPicture().size)
|
||||
test_picture = self._cap.getPicture()
|
||||
if self._rotation is not None:
|
||||
test_picture = test_picture.transpose(self._rotation)
|
||||
|
||||
self._pic_dims = PictureDimensions(self._cfg, test_picture.size)
|
||||
self._is_preview = self._is_preview and self._cap.hasPreview
|
||||
|
||||
background = self._cfg.get('Picture', 'background')
|
||||
@@ -120,8 +127,11 @@ class Camera:
|
||||
|
||||
if self._is_preview:
|
||||
while self._comm.empty(Workers.CAMERA):
|
||||
picture = ImageOps.mirror(self._cap.getPreview())
|
||||
picture = self._cap.getPreview()
|
||||
if self._rotation is not None:
|
||||
picture = picture.transpose(self._rotation)
|
||||
picture = picture.resize(self._pic_dims.previewSize)
|
||||
picture = ImageOps.mirror(picture)
|
||||
self._comm.send(Workers.GUI,
|
||||
StateMachine.CameraEvent('preview', picture))
|
||||
|
||||
@@ -129,6 +139,8 @@ class Camera:
|
||||
|
||||
self.setIdle()
|
||||
picture = self._cap.getPicture()
|
||||
if self._rotation is not None:
|
||||
picture = picture.transpose(self._rotation)
|
||||
self._pictures.append(picture)
|
||||
self.setActive()
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ style = default
|
||||
# Camera module to use (python-gphoto2, gphoto2-cffi, gphoto2-commandline,
|
||||
# opencv, picamera, dummy)
|
||||
module = python-gphoto2
|
||||
# Specify rotation of camera in degree (possible values: 0, 90, 180, 270)
|
||||
rotation = 0
|
||||
|
||||
[Gpio]
|
||||
# Enable use of GPIO (True/False)
|
||||
|
||||
@@ -613,8 +613,25 @@ class Settings(QtWidgets.QFrame):
|
||||
self._cfg.get('Camera', 'module'))
|
||||
self.add('Camera', 'module', module)
|
||||
|
||||
self.rot_vals_ = (0, 90, 180, 270)
|
||||
cur_rot = self._cfg.getInt('Camera', 'rotation')
|
||||
|
||||
rotation = QtWidgets.QComboBox()
|
||||
for r in self.rot_vals_:
|
||||
rotation.addItem(str(r))
|
||||
|
||||
idx = [x for x, r in enumerate(self.rot_vals_) if r == cur_rot]
|
||||
rotation.setCurrentIndex(idx[0] if len(idx) > 0 else -1)
|
||||
|
||||
# Fix bug in Qt to allow changing the items in a stylesheet
|
||||
delegate = QtWidgets.QStyledItemDelegate()
|
||||
rotation.setItemDelegate(delegate)
|
||||
|
||||
self.add('Camera', 'rotation', rotation)
|
||||
|
||||
layout = QtWidgets.QFormLayout()
|
||||
layout.addRow(_('Camera module:'), module)
|
||||
layout.addRow(_('Camera rotation:'), rotation)
|
||||
|
||||
widget = QtWidgets.QWidget()
|
||||
widget.setLayout(layout)
|
||||
@@ -862,6 +879,8 @@ class Settings(QtWidgets.QFrame):
|
||||
self._cfg.set('Camera', 'module',
|
||||
camera.modules[self.get('Camera',
|
||||
'module').currentIndex()][0])
|
||||
self._cfg.set('Camera', 'rotation', str(
|
||||
self.rot_vals_[self.get('Camera', 'rotation').currentIndex()]))
|
||||
|
||||
self._cfg.set('Picture', 'num_x', self.get('Picture', 'num_x').text())
|
||||
self._cfg.set('Picture', 'num_y', self.get('Picture', 'num_y').text())
|
||||
|
||||
Reference in New Issue
Block a user