56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
from picamera2 import Picamera2, Preview
|
|
import PIL.Image, PIL.ImageTk
|
|
|
|
|
|
class Camera():
|
|
def __init__(self, still_image_processing):
|
|
#Auflösung des Vorschaubildes
|
|
self.preview_width = 800
|
|
self.preview_height = 480
|
|
#Auflösung des finalen Bildes
|
|
self.still_width = 4056
|
|
self.still_height = 3040
|
|
|
|
self.camera = Picamera2()
|
|
#Low-Resolution-Config, für flüssigeres Vorschaubild
|
|
self.lowres_preview_config = self.camera.create_preview_configuration(main={"size": (self.preview_width, self.preview_height)})
|
|
#Einstellung für Vorschaubild in höherer AUflsung (für Zoom)
|
|
self.highres_preview_config = self.camera.create_preview_configuration(main={"size": (2028, 1080)})
|
|
#Einstellung für finales Bild, maximale Auflösung
|
|
self.capture_config = self.camera.create_still_configuration(main={"size": (self.still_width, self.still_height)})
|
|
|
|
|
|
self.preview_config = self.lowres_preview_config
|
|
self.still_image_processing = still_image_processing
|
|
self.set_highres_preview_config = False
|
|
|
|
def start_camera(self):
|
|
self.camera.configure(self.preview_config)
|
|
self.camera.start()
|
|
|
|
def get_preview_image(self):
|
|
image = self.camera.capture_array()
|
|
return image
|
|
|
|
#Kameravorschau auf höhere Auflösung umstellen
|
|
def get_highres_preview(self):
|
|
self.camera.stop()
|
|
if self.set_highres_preview_config == False:
|
|
self.preview_config = self.highres_preview_config
|
|
self.set_highres_preview_config = True
|
|
else:
|
|
self.preview_config = self.lowres_preview_config
|
|
self.set_highres_preview_config = False
|
|
|
|
self.camera.configure(self.preview_config)
|
|
self.camera.start()
|
|
|
|
def get_still_image(self):
|
|
image = self.camera.switch_mode_and_capture_array(self.capture_config)
|
|
self.still_image_processing.process_image(image)
|
|
|
|
def get_aspect_ratio(self):
|
|
preview_ratio = self.preview_width / self.preview_height
|
|
return preview_ratio
|
|
|