Added a OpenCV-based Camera class
This commit is contained in:
25
camera.py
25
camera.py
@@ -3,14 +3,37 @@
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
try:
|
||||||
|
import cv2 as cv
|
||||||
|
cv_enabled = True
|
||||||
|
except ImportError:
|
||||||
|
cv_enabled = False
|
||||||
|
|
||||||
|
|
||||||
class CameraException(Exception):
|
class CameraException(Exception):
|
||||||
"""Custom exception class to handle camera class errors"""
|
"""Custom exception class to handle camera class errors"""
|
||||||
pass
|
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:
|
class Camera_gPhoto:
|
||||||
"""Camera class providing functionality to take pictures using gPhoto 2"""
|
"""Camera class providing functionality to take pictures using gPhoto 2"""
|
||||||
|
|
||||||
#def __init__(self):
|
# def __init__(self):
|
||||||
# Print the abilities of the connected camera
|
# Print the abilities of the connected camera
|
||||||
# print(self.call_gphoto("-a", "/dev/null"))
|
# print(self.call_gphoto("-a", "/dev/null"))
|
||||||
|
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ class Photobooth:
|
|||||||
offset = (j * thumb_size[0], i * thumb_size[1])
|
offset = (j * thumb_size[0], i * thumb_size[1])
|
||||||
output_image.paste(img, offset)
|
output_image.paste(img, offset)
|
||||||
|
|
||||||
|
# Save resized image
|
||||||
output_image.save(output_filename, "JPEG")
|
output_image.save(output_filename, "JPEG")
|
||||||
|
|
||||||
def take_picture(self):
|
def take_picture(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user