Added a OpenCV-based Camera class

This commit is contained in:
Balthasar Reuter
2015-06-18 00:06:43 +02:00
parent dcc8f59a47
commit 400210b8c5
2 changed files with 25 additions and 1 deletions

View File

@@ -3,10 +3,33 @@
import subprocess
try:
import cv2 as cv
cv_enabled = True
except ImportError:
cv_enabled = False
class CameraException(Exception):
"""Custom exception class to handle camera class errors"""
pass
class Camera_cv:
def __init__(self):
if cv_enabled:
self.cap = cv.VideoCapture(0)
self.cap.set(3, 640)
self.cap.set(4, 480)
def take_picture(self, filename="/tmp/picture.jpg"):
if cv_enabled:
r, frame = self.cap.read()
cv.imwrite(filename, frame)
return filename
else:
return "/dev/null"
class Camera_gPhoto:
"""Camera class providing functionality to take pictures using gPhoto 2"""

View File

@@ -190,6 +190,7 @@ class Photobooth:
offset = (j * thumb_size[0], i * thumb_size[1])
output_image.paste(img, offset)
# Save resized image
output_image.save(output_filename, "JPEG")
def take_picture(self):