티스토리 뷰

라즈베리파이+파이썬+tkinter+gpio+picamera+lcd 디스플레이 예제

 


예제 영상 :https://youtu.be/mUSGsu5AYjQ





라즈베리파이+파이썬+tkinter+gpio+picamera+lcd 디스플레이 예제 소스 코드 



#toytvstory.tistory.com


import tkinter as tk

import RPi.GPIO as GPIO

import picamera

from time import sleep

from gpiozero import LED, Button

from signal import pause


led = LED(17)




camera = picamera.PiCamera()

choices = ['off', 'auto', 'sunlight','cloudy','shade','tungsten','fluorescent','incandescent','flash','horizon']

effects = ['none','negative','solarize','sketch','denoise','emboss','oilpaint','hatch','gpen','pastel','watercolor','film','blur','saturation','colorswap','washedout','posterise','colorpoint','colorbalance','cartoon','deinterlace1','deinterlace2']

iso = ['100','200','400','800','1600']


# LED 온 오프

def Ledon():

    led.on()


def Ledoff():

    led.off()


# 카메라 온 오프

def CameraON():

    camera.preview_fullscreen=False

    camera.preview_window=(0,50,440,330) # 0, 0, 320, 240 (4:3 screen)

    camera.resolution=(1280,960) #640, 480

    camera.start_preview()

    

def CameraOFF():

    camera.stop_preview()


# 나가기

def EXIT():

    root.destroy

    camera.stop_preview()

    camera.close()

    quit()


# 사진 저장

def Photo():

    camera.capture('/home/pi/image1.jpg')


#동영상 촬영

def CameraRecordingStart():

    camera.start_recording('/home/pi/camerbutton.h264')


#동영상 촬영 스톱

def CameraRecordingStop():

    camera.stop_recording()

    


#밝기 조절

def UpdateBrightness(value):

    camera.brightness = int(value)


# 대조

def UpdateContrast(value):

    camera.contrast = int(value)


# 선명도

def UpdateSharpness(value):

    camera.sharpness = int(value)

    

def UpdateSaturation(value):

    camera.saturation = int(value)


def SetIso(var):

    camera.iso =int(var)


def SetAWB(var):

    camera.awb_mode = var


def SetEFFECTS(var):

    camera.image_effect = var


def Zoom(var):

    x = float("0."+var)

    camera.zoom = (0.05,0.05,x,x)



    

root = tk.Tk()

root.resizable(width=False, height=False)

root.geometry("320x300+450+50") #320(x size) x300(y size) +89(positon x)+50(position y)

root.title("Camera Button Test")


root.buttonframe = tk.Frame(root)

root.buttonframe.grid(row=7, column=3, columnspan=2) # row=5, column=3, columnspan=2


tk.Button(root.buttonframe, text='Start Camera', command=CameraON).grid(row=1, column = 1)

tk.Button(root.buttonframe, text='Kill Camera', command=CameraOFF).grid(row=1, column = 2)

tk.Button(root.buttonframe, text='Exit Program', command=EXIT).grid(row=1, column = 3)


tk.Scale(root.buttonframe, from_= 30, to=100, orient=tk.HORIZONTAL, label = "Brightness", command=UpdateBrightness).grid(row=2,column=1)

tk.Scale(root.buttonframe, from_=-100, to=100, orient=tk.HORIZONTAL, label = "Contrast", command=UpdateContrast).grid(row=2,column=2)

tk.Scale(root.buttonframe, from_=-100, to=100, orient=tk.HORIZONTAL, label = "Sharpness", command=UpdateSharpness).grid(row=2,column=3)

tk.Scale(root.buttonframe, from_=-100, to=100, orient=tk.HORIZONTAL, label = "Saturation", command=UpdateSaturation).grid(row=3,column=1)

tk.Scale(root.buttonframe, from_=10, to=99, orient=tk.HORIZONTAL, label = "Zoom", command=Zoom).grid(row=4,column=1)





tk.Button(root.buttonframe, text='Photo', command=Photo).grid(row=5,column=1)

tk.Button(root.buttonframe, text='Rec',command=CameraRecordingStart).grid(row=5,column=2)

tk.Button(root.buttonframe, text='Stop',command=CameraRecordingStop).grid(row=5,column=3)

tk.Button(root.buttonframe, text='LED ON',command=Ledon).grid(row=6,column=1)

tk.Button(root.buttonframe, text='LED OFF',command=Ledoff).grid(row=6,column=2)


AWB_Var = tk.StringVar(root)

AWB_Var.set(choices[0]) 

AWB_Option = tk.OptionMenu(root.buttonframe, AWB_Var, *choices, command=SetAWB).grid(row=3,column=2)


EFFECT_Var = tk.StringVar(root)

EFFECT_Var.set(effects[0]) 

EFFECT_Option = tk.OptionMenu(root.buttonframe, EFFECT_Var, *effects, command=SetEFFECTS).grid(row=3,column=3)


ISO_Var = tk.StringVar(root)

ISO_Var.set(iso[0])

ISO_Option = tk.OptionMenu(root.buttonframe, ISO_Var, *iso, command=SetIso).grid(row = 7,column=1)




root.mainloop()



댓글
최근에 달린 댓글
글 보관함
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글