Re: Zugriff auf Variablen einer anderen Funktion
Verfasst: Freitag 20. Juli 2018, 15:28
Das mit dem Überschreiben von self.camera ist natürlich falsch
Was meinst du wie wird Kamera benutzt
Hier noch mal etwas mehr Code.
Hoffe damit könnt ihr mir weiter helfen
Was meinst du wie wird Kamera benutzt
Hier noch mal etwas mehr Code.
Hoffe damit könnt ihr mir weiter helfen
Code: Alles auswählen
from tkinter import messagebox
import tkinter as tk
import picamera
import time
import numpy as np
from PIL import Image
APP_TITLE = "Kamera"
APP_XPOS = 10
APP_YPOS = 10
APP_WIDTH = 1280
APP_HEIGHT = 800
Hintergrundbild = "Hintergrund.gif"
camera = picamera.PiCamera(resolution=(1280,720))
cam_bri = 45
cam_con = 100
cam_shu = 20000
cam_iso = 100
camera.brightness = cam_bri
camera.contrast = cam_con
camera.shutter_speed = cam_shu
camera.iso = cam_iso
camera.vflip=False
camera.hflip=False
camera.saturation = -100
#camera.framerate = 60
camera.awb_mode='auto'
camera.exposure_mode='auto'
camera.video_stabilization=True
camera.preview_fullscreen=False
camera.preview_window=(200, 50, 1050, 800)
class Kamera:
def __init__(self):
self.camera=camera
self.fx = 0
self.fy = 0
def startpreview(self):
print("Starte_ Preview")
self.camera.start_preview()
def stoppreview(self):
print("Stop_Preview")
self.camera.stop_preview()
def overlay(self):
print("Start_Overlay")
img = Image.open('test.png')
pad = Image.new('RGBA',(
((img.size[0] + 31) // 32) * 32,
((img.size[1] + 15) // 16) * 16,
))
pad.paste(img, (self.fx, self.fy),)
self.overlay = self.camera.add_overlay(pad.tostring(), size=img.size)
self.overlay.alpha = 25
self.overlay.layer = 4
def stopoverlay(self):
print("Stop_Oberlay")
camera.remove_overlay(self.overlay)
class MainFrame(tk.Frame):
def __init__(self, haupt_fenster):
super().__init__(haupt_fenster)
self.haupt_fenster = haupt_fenster
self.haupt_fenster.protocol("WM_DELETE_WINDOW", self.close)
self.build()
def build(self):
button_frame = tk.Button(self)
button_frame.pack(pady=6)
button_frame.configure(bg='steelblue1')
def capture(self):
print("Capture")
Kamera().startpreview()
Kamera().overlay()
def stop(self):
print("Stop")
Kamera().stoppreview()
Kamera().stopoverlay()
def main():
haupt_fenster = tk.Tk()
haupt_fenster.title(APP_TITLE)
haupt_fenster.attributes('-fullscreen',True)
haupt_fenster.option_add("*highlightThickness", 0)
haupt_fenster.configure(bg='steelblue1')
background_image = tk.PhotoImage(file=Hintergrundbild)
tk.Label(haupt_fenster, image=background_image).place(x=0, y=0)
main_frame = MainFrame(haupt_fenster)
main_frame.pack(fill='both', expand=False, padx=0, pady=0,)
main_frame.configure(bg='steelblue1')
haupt_fenster.mainloop()
if __name__ == '__main__':
main()