Tuesday, March 9, 2021

RPi/Python Code to control Camera Module with preview on local HDMI

It's a Python3 code run on Raspberry Pi to control Camera Module with various setting. The preview display on local HDMI. 


In my usage scenario: The Raspberry Pi 4B/8G is installed with HQ Camera Module (mount with manual focus lens) and a 4 inch HDMI IPS Touch Display. Remote control with Android with xrdp/Microsoft Remote Desktop. Such that I can control and change setting on remote Android device, adjust focus/aperture on the lens, and check the effect on local HDMI preview at real-time.

It's a long time ago, I make a similar code with preview stream video, both control and preview on remote desktop, Python to capture image from Pi Camera Module, with image effects. But I'm not satisfied by the delay of stream video, that's why I re-develop this code again.


The lens shown on the video is a Nikkor ais 28mm f2.8 manual focus lens, connected to HQ Camera Module via a Nikon F to C mount adapter.

rpiCam_20210309a.py
import sys
import picamera
from pkg_resources import require
import time

"""
ref: Picamera
https://picamera.readthedocs.io/en/release-1.13/
"""

#from tkinter import *
#tkinter for Python 3
import tkinter as tk
from tkinter import ttk

def close_window():
    #close tasks
    camera.close()
    print("Camera closed")
    
    print("close_window()")
    print("Window closed")
    root.destroy()

#event callback functions
def evStartPreviewBtnPressed():
    print("Start Preview")
    camera.start_preview()

def evStopPreviewBtnPressed():
    print("Stop Preview")
    camera.stop_preview()

def evCaptureBtnPressed():
    print("Capture")
    timeStamp = time.strftime("%Y%m%d-%H%M%S")
    targetPath="/home/pi/Desktop/img_"+timeStamp+".jpg"
    print(targetPath)
    camera.capture(targetPath)
    
def cmdScaleSharpness(new_value):
    camera.sharpness = scaleSharpness.get()
    print("sharpness: " + str(camera.sharpness))
    
def cmdScaleContrast(new_value):
    camera.contrast = scaleContrast.get()
    print("contrast: " + str(camera.contrast))
    
def cmdScaleBrightness(new_value):
    camera.brightness = scaleBrightness.get()
    print("brightness: " + str(camera.brightness))
    
def cmdScaleSaturation(new_value):
    camera.saturation = scaleSaturation.get()
    print("saturation: " + str(camera.saturation))
    
def cmdScaleExpCompensation(NEW_VALUE):
    camera.exposure_compensation = scaleExpCompensation.get()
    print("exposure_compensation: " + str(camera.exposure_compensation))
    
def cmdRB_Iso():
    camera.iso = varIso.get()
    print("iso: " + str(camera.iso))

print(sys.version)
print(require('picamera'))
strInfo = str(sys.version) + str(require('picamera'))
type(sys.version)
type(require('picamera'))

#Prepare camera
camera = picamera.PiCamera()
#set default
camera.sharpness = +5
camera.contrast = 0
camera.brightness = 50
camera.saturation = 0
camera.iso = 100
camera.video_stabilization = False
camera.exposure_compensation = 0
camera.exposure_mode = 'auto'
camera.meter_mode = 'average'
camera.awb_mode = 'auto'
camera.image_effect = 'none'
camera.color_effects = None
camera.rotation = 0
camera.hflip = False
camera.vflip = False
camera.crop = (0.0, 0.0, 1.0, 1.0)
  
# not work for HQ
#camera.resolution = (4056, 3040)  # HQ
#camera.resolution = (2592, 1944)  # V1
camera.resolution = (3280, 2464)  # V2
#end of set default

SCALE_WIDTH = 940;

#Prepare GUI
root = tk.Tk()
#root.geometry("650x550")
root.geometry("960x800")
root.wm_title("doCamII")
root.protocol("WM_DELETE_WINDOW", close_window)

labelInfo = tk.Label(root,
                  text=strInfo, fg="gray",
                  font=("Helvetica", 14))
labelInfo.pack()

#Main control
frameMain = tk.Frame(root, bg="lightgray")

btnStartPreview = tk.Button(frameMain, text="Start Preview",
                    command=evStartPreviewBtnPressed)
btnStopPreview = tk.Button(frameMain, text="Stop Preview",
                    command=evStopPreviewBtnPressed)
btnStartPreview.grid(row=2, column=0, sticky=tk.W+tk.E)
btnStopPreview.grid(row=2, column=1, sticky=tk.W+tk.E)

btnCapture = tk.Button(frameMain, text="Capture",
                    command=evCaptureBtnPressed)
btnCapture.grid(row=3, columnspan=2, sticky=tk.W+tk.E)
frameMain.pack(padx=10,pady=10)

#Setting
notebook = ttk.Notebook(root)
frame1 = ttk.Frame(notebook)
frame2 = ttk.Frame(notebook)
frame3 = ttk.Frame(notebook)
notebook.add(frame1, text='Setting 1')
notebook.add(frame2, text='Setting 2')
notebook.add(frame3, text='Setting 3')
notebook.pack()

lfSharpness = ttk.LabelFrame(frame1, text="sharpness")
lfSharpness.pack(fill="x", expand="no", anchor=tk.N)
scaleSharpness = tk.Scale(
    lfSharpness,
    from_=-100, to=100,
    length=SCALE_WIDTH,
    orient=tk.HORIZONTAL,
    command=cmdScaleSharpness)
scaleSharpness.set(camera.sharpness)
scaleSharpness.pack()

lfContrast = ttk.LabelFrame(frame1, text="contrast")
lfContrast.pack(fill="x", expand="no", anchor=tk.N)
scaleContrast = tk.Scale(
    lfContrast,
    from_=-100, to=100,
    length=SCALE_WIDTH,
    orient=tk.HORIZONTAL,
    command=cmdScaleContrast)
scaleContrast.set(camera.contrast)
scaleContrast.pack()

lfBrightness = ttk.LabelFrame(frame1, text="brightness")
lfBrightness.pack(fill="x", expand="no", anchor=tk.N)
scaleBrightness = tk.Scale(
    lfBrightness,
    from_=0, to=100,
    length=SCALE_WIDTH,
    orient=tk.HORIZONTAL,
    command=cmdScaleBrightness)
scaleBrightness.set(camera.brightness)
scaleBrightness.pack()

lfSaturation = ttk.LabelFrame(frame1, text="saturation")
lfSaturation.pack(fill="x", expand="no", anchor=tk.N)
scaleSaturation = tk.Scale(
    lfSaturation,
    from_=-100, to=100,
    length=SCALE_WIDTH,
    orient=tk.HORIZONTAL,
    command=cmdScaleSaturation)
scaleSaturation.set(camera.saturation)
scaleSaturation.pack()

lfExpCompensation = ttk.LabelFrame(frame1, text="exposure_compensation")
lfExpCompensation.pack(fill="x", expand="no", anchor=tk.N)
scaleExpCompensation = tk.Scale(
    lfExpCompensation,
    from_=-25, to=25,
    length=SCALE_WIDTH,
    orient=tk.HORIZONTAL,
    command=cmdScaleExpCompensation)
scaleExpCompensation.set(camera.exposure_compensation)
scaleExpCompensation.pack()

#==========================================================
varIso = tk.IntVar()
varIso.set(camera.iso)
lfIso = ttk.LabelFrame(frame2, text="iso")
lfIso.pack(fill="x", expand="no", anchor=tk.N)
tk.Radiobutton(lfIso, variable=varIso,
        text='0 (auto)',value=0,command=cmdRB_Iso).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfIso, variable=varIso,
        text='100',value=100,command=cmdRB_Iso).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfIso, variable=varIso,
        text='200',value=200,command=cmdRB_Iso).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfIso, variable=varIso,
        text='400',value=400,command=cmdRB_Iso).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfIso, variable=varIso,
        text='800',value=800,command=cmdRB_Iso).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfIso, variable=varIso,
        text='1600',value=1600,command=cmdRB_Iso).pack(
            anchor=tk.W, side=tk.LEFT)
#==========================================================
#-- meter_mode command
def cmdMeterMode():
    camera.meter_mode = varMeterMode.get()
    print("meter_mode: " + str(camera.meter_mode))
#-- exposure_mode
lfMeterMode = ttk.LabelFrame(frame2, text="meter_mode")
lfMeterMode.pack(fill="x", expand="no", anchor=tk.N)
varMeterMode = tk.StringVar()
varMeterMode.set(camera.meter_mode)

tk.Radiobutton(lfMeterMode, variable=varMeterMode,
        text='average',value='average',command=cmdMeterMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfMeterMode, variable=varMeterMode,
        text='spot',value='spot',command=cmdMeterMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfMeterMode, variable=varMeterMode,
        text='backlit',value='backlit',command=cmdMeterMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfMeterMode, variable=varMeterMode,
        text='matrix',value='matrix',command=cmdMeterMode).pack(
            anchor=tk.W, side=tk.LEFT)


#==========================================================
#-- exposure_mode command
def cmdEposureMode():
    camera.exposure_mode = varExposureMode.get()
    print("exposure_mode: " + str(camera.exposure_mode))
#-- exposure_mode
lfExpMode = ttk.LabelFrame(frame2, text="exposure_mode")
lfExpMode.pack(fill="x", expand="no", anchor=tk.N)
varExposureMode = tk.StringVar()
varExposureMode.set(camera.exposure_mode)
lfExposure_mode1 = ttk.Frame(lfExpMode)
lfExposure_mode1.pack(fill="x", expand="no", anchor=tk.N)
lfExposure_mode2 = ttk.Frame(lfExpMode)
lfExposure_mode2.pack(fill="x", expand="no", anchor=tk.N)

tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='off',value='off',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='auto',value='auto',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='night',value='night',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)

tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='nightpreview',value='nightpreview',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='backlight',value='backlight',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='spotlight',value='spotlight',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='sports',value='sports',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode1, variable=varExposureMode,
        text='snow',value='snow',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)

tk.Radiobutton(lfExposure_mode2, variable=varExposureMode,
        text='beach',value='beach',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode2, variable=varExposureMode,
        text='verylong',value='verylong',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode2, variable=varExposureMode,
        text='fixedfps',value='fixedfps',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode2, variable=varExposureMode,
        text='antishake',value='antishake',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfExposure_mode2, variable=varExposureMode,
        text='fireworks',value='fireworks',command=cmdEposureMode).pack(
            anchor=tk.W, side=tk.LEFT)
#==========================================================
#common button handler for ImageEffect without parameter setting,
#simple set camera.image_effect
def butComImageEffect():
    camera.image_effect=varImageEffect.get()
    labelImageEffectVar.set(camera.image_effect)

#----- ImageEffect 'solarise' ui event
def butImageEffect_solarize():
    camera.image_effect=varImageEffect.get()
    if cbSolarize_yuv_Var.get():
        yuv = 1
    else:
        yuv = 0
    solarize_para = (yuv,
                     scSolarize_x0_Var.get(),
                     scSolarize_y0_Var.get(),
                     scSolarize_y1_Var.get(),
                     scSolarize_y2_Var.get())
    camera.image_effect_params = solarize_para
    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_solarizePara(new_value=None):
    varImageEffect.set("solarize")
    butImageEffect_solarize()

#----- ImageEffect 'watercolor' ui event ---
def butImageEffect_watercolor():
    camera.image_effect=varImageEffect.get()
    
    if cbWatercolor_uv_Var.get():
        watercolor_para = (scWatercolor_u_Var.get(),
                           scWatercolor_v_Var.get())
        camera.image_effect_params = watercolor_para
    else:
        watercolor_para = ()
        camera.image_effect_params = watercolor_para
    
    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_watercolorPara(new_value=None):
    varImageEffect.set("watercolor")
    butImageEffect_watercolor()
    
#----- ImageEffect 'film' ui event ---
def butImageEffect_film():
    camera.image_effect=varImageEffect.get()
    
    film_para = (scFilm_strength_Var.get(),
                 scFilm_u_Var.get(),
                 scFilm_v_Var.get())
    camera.image_effect_params = film_para
    
    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_filmPara(new_value=None):
    varImageEffect.set("film")
    butImageEffect_film()
    
#----- ImageEffect 'blur' ui event ---
def butImageEffect_blur():
    camera.image_effect=varImageEffect.get()
    
    camera.image_effect_params = scBlur_size_Var.get()
    
    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_blurPara(new_value=None):
    varImageEffect.set("blur")
    butImageEffect_blur()
    
#----- ImageEffect 'colorswap' ui event ---
def butImageEffect_colorswap():
    camera.image_effect=varImageEffect.get()
    
    camera.image_effect_params = cbColorswap_dir_Var.get()
    
    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_colorswapPara(new_value=None):
    varImageEffect.set("colorswap")
    butImageEffect_colorswap()

#----- ImageEffect 'posterise' ui event ---
def butImageEffect_posterise():
    camera.image_effect=varImageEffect.get()

    camera.image_effect_params = scPosterise_steps_Var.get()

    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_posterisePara(new_value=None):
    varImageEffect.set("posterise")
    butImageEffect_posterise()

#----- ImageEffect 'colorpoint' ui event ---
def butImageEffect_colorpoint():
    camera.image_effect=varImageEffect.get()

    camera.image_effect_params = quadrantVar.get()
    
    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_colorpointPara(new_value=None):
    varImageEffect.set("colorpoint")
    butImageEffect_colorpoint()

#----- ImageEffect 'colorbalance' ui event ---
def butImageEffect_colorbalance():
    camera.image_effect=varImageEffect.get()

    colorbalance_para = (scColorbalance_lens_Var.get(),
                         scColorbalance_r_Var.get(),
                         scColorbalance_g_Var.get(),
                         scColorbalance_b_Var.get(),
                         scColorbalance_u_Var.get(),
                         scColorbalance_v_Var.get())
    camera.image_effect_params = colorbalance_para
    
    labelImageEffectVar.set(camera.image_effect +
                            " " + str(camera.image_effect_params))
    
def ev_colorbalancePara(new_value=None):
    varImageEffect.set("colorbalance")
    butImageEffect_colorbalance()
#-----------------------------------------------------
#-----------------------------------------------------
    
# Tab Image Effect
varImageEffect = tk.StringVar()
labelImageEffectVar = tk.StringVar()
image_effect_setting = camera.image_effect
varImageEffect.set(image_effect_setting)
labelImageEffectVar.set(image_effect_setting)
tk.Label(frame3, textvariable=labelImageEffectVar).pack(anchor=tk.N)

#-- image_effect

lfNoParaOpts1 = ttk.Frame(frame3)
lfNoParaOpts1.pack(fill="x", expand="yes", anchor=tk.N)

tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='none',value='none',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='negative',value='negative',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='sketch',value='sketch',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='denoise',value='denoise',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='emboss',value='emboss',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='oilpaint',value='oilpaint',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='hatch',value='hatch',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts1, variable=varImageEffect,
        text='gpen',value='gpen',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)

lfNoParaOpts2 = ttk.Frame(frame3)
lfNoParaOpts2.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lfNoParaOpts2, variable=varImageEffect,
        text='pastel',value='pastel',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts2, variable=varImageEffect,
        text='saturation',value='saturation',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts2, variable=varImageEffect,
        text='washedout',value='washedout',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts2, variable=varImageEffect,
        text='cartoon',value='cartoon',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts2, variable=varImageEffect,
        text='deinterlace1',value='deinterlace1',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfNoParaOpts2, variable=varImageEffect,
        text='deinterlace2',value='deinterlace2',command=butComImageEffect).pack(
            anchor=tk.W, side=tk.LEFT)

lfSolarize = ttk.LabelFrame(frame3, text="solarize")
lfSolarize.pack(fill="x", expand="yes", anchor=tk.N)

tk.Radiobutton(lfSolarize, variable=varImageEffect,
        text='solarize',value='solarize',command=butImageEffect_solarize).pack(
            anchor=tk.W, side=tk.LEFT)

cbSolarize_yuv_Var = tk.BooleanVar()
tk.Checkbutton(lfSolarize, text="yuv",
    variable=cbSolarize_yuv_Var, command=ev_solarizePara).pack(
        anchor=tk.W, side=tk.LEFT)

scSolarize_x0_Var = tk.IntVar()
scSolarize_x0_Var.set(128)
tk.Scale(lfSolarize, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="x0",
    variable=scSolarize_x0_Var, command=ev_solarizePara).pack(
        anchor=tk.W, side=tk.LEFT)

scSolarize_y0_Var = tk.IntVar()
scSolarize_y0_Var.set(128)
tk.Scale(lfSolarize, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="y0",
    variable=scSolarize_y0_Var, command=ev_solarizePara).pack(
        anchor=tk.W, side=tk.LEFT)

scSolarize_y1_Var = tk.IntVar()
scSolarize_y1_Var.set(128)
tk.Scale(lfSolarize, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="y1",
    variable=scSolarize_y1_Var, command=ev_solarizePara).pack(
        anchor=tk.W, side=tk.LEFT)

scSolarize_y2_Var = tk.IntVar()
scSolarize_y2_Var.set(0)
tk.Scale(lfSolarize, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="y2",
    variable=scSolarize_y2_Var, command=ev_solarizePara).pack(
        anchor=tk.W, side=tk.LEFT)

lfwatercolor = ttk.LabelFrame(frame3, text="watercolor")
lfwatercolor.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lfwatercolor, variable=varImageEffect,
        text='watercolor',value='watercolor',command=butImageEffect_watercolor
               ).pack(anchor=tk.W, side=tk.LEFT)

cbWatercolor_uv_Var = tk.BooleanVar()
cbWatercolor_uv_Var.set(False)
tk.Checkbutton(lfwatercolor, text="uv",
    variable=cbWatercolor_uv_Var, command=ev_watercolorPara).pack(
        anchor=tk.W, side=tk.LEFT)

scWatercolor_u_Var = tk.IntVar()
scWatercolor_u_Var.set(0)
tk.Scale(lfwatercolor, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="u",
    variable=scWatercolor_u_Var, command=ev_watercolorPara).pack(
        anchor=tk.W, side=tk.LEFT)
scWatercolor_v_Var = tk.IntVar()
scWatercolor_v_Var.set(0)
tk.Scale(lfwatercolor, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="v",
    variable=scWatercolor_v_Var, command=ev_watercolorPara).pack(
        anchor=tk.W, side=tk.LEFT)

lffilm = ttk.LabelFrame(frame3, text="film")
lffilm.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lffilm, variable=varImageEffect,
        text='film',value='film',command=butImageEffect_film).pack(
            anchor=tk.W, side=tk.LEFT)

scFilm_strength_Var = tk.IntVar()
scFilm_strength_Var.set(0)
tk.Scale(lffilm, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="strength",
    variable=scFilm_strength_Var, command=ev_filmPara).pack(
        anchor=tk.W, side=tk.LEFT)
scFilm_u_Var = tk.IntVar()
scFilm_u_Var.set(0)
tk.Scale(lffilm, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="u",
    variable=scFilm_u_Var, command=ev_filmPara).pack(anchor=tk.W, side=tk.LEFT)
scFilm_v_Var = tk.IntVar()
scFilm_v_Var.set(0)
tk.Scale(lffilm, from_=0, to=255,
    orient=tk.HORIZONTAL, length=200, label="v",
    variable=scFilm_v_Var, command=ev_filmPara).pack(anchor=tk.W, side=tk.LEFT)

lfblur = ttk.LabelFrame(frame3, text="blur")
lfblur.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lfblur, variable=varImageEffect,
        text='blur',value='blur',command=butImageEffect_blur).pack(
            anchor=tk.W, side=tk.LEFT)
scBlur_size_Var = tk.IntVar()
scBlur_size_Var.set(1)
tk.Scale(lfblur, from_=1, to=2,
    orient=tk.HORIZONTAL, length=100, label="size",
    variable=scBlur_size_Var, command=ev_blurPara).pack(anchor=tk.W, side=tk.LEFT)

lfcolorswap = ttk.LabelFrame(frame3, text="colorswap")
lfcolorswap.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lfcolorswap, variable=varImageEffect,
        text='colorswap',value='colorswap',command=butImageEffect_colorswap).pack(
            anchor=tk.W, side=tk.LEFT)
cbColorswap_dir_Var = tk.BooleanVar()
cbColorswap_dir_Var.set(False)
tk.Checkbutton(lfcolorswap, text="dir - 0:RGB to BGR/1:RGB to BRG",
    variable=cbColorswap_dir_Var, command=ev_colorswapPara).pack(
        anchor=tk.W, side=tk.LEFT)

lfposterise = ttk.LabelFrame(frame3, text="posterise")
lfposterise.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lfposterise, variable=varImageEffect,
        text='posterise',value='posterise',command=butImageEffect_posterise).pack(
            anchor=tk.W, side=tk.LEFT)
scPosterise_steps_Var = tk.IntVar()
scPosterise_steps_Var.set(4)
tk.Scale(lfposterise, from_=2, to=32,
    orient=tk.HORIZONTAL, length=200, label="steps",
    variable=scPosterise_steps_Var, command=ev_posterisePara).pack(
        anchor=tk.W, side=tk.LEFT)

lfcolorpoint = ttk.LabelFrame(frame3, text="colorpoint")
lfcolorpoint.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lfcolorpoint, variable=varImageEffect,
        text='colorpoint',value='colorpoint',command=butImageEffect_colorpoint).pack(
            anchor=tk.W, side=tk.LEFT)
quadrantVar = tk.IntVar()
quadrantVar.set(0)
tk.Radiobutton(lfcolorpoint, text="green",
    variable=quadrantVar, value=0, command=ev_colorpointPara).pack(
        anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfcolorpoint, text="red/yellow",
    variable=quadrantVar, value=1, command=ev_colorpointPara).pack(
        anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfcolorpoint, text="blue",
    variable=quadrantVar, value=2, command=ev_colorpointPara).pack(
        anchor=tk.W, side=tk.LEFT)
tk.Radiobutton(lfcolorpoint, text="purple",
    variable=quadrantVar, value=3, command=ev_colorpointPara).pack(
        anchor=tk.W, side=tk.LEFT)

lfcolorbalance = ttk.LabelFrame(frame3, text="colorbalance: I can't see any effect!")
lfcolorbalance.pack(fill="x", expand="yes", anchor=tk.N)
tk.Radiobutton(lfcolorbalance, variable=varImageEffect,
        text='colorbalance',value='colorbalance',command=butImageEffect_colorbalance).pack(
            anchor=tk.W, side=tk.LEFT)

scColorbalance_lens_Var = tk.DoubleVar()
scColorbalance_lens_Var.set(0)
tk.Scale(lfcolorbalance, from_=0, to=256,
    orient=tk.HORIZONTAL, length=140, label="lens",
    variable=scColorbalance_lens_Var, command=ev_colorbalancePara).pack(
        anchor=tk.W, side=tk.LEFT)

scColorbalance_r_Var = tk.DoubleVar()
scColorbalance_r_Var.set(1)
tk.Scale(lfcolorbalance, from_=0, to=256,
    orient=tk.HORIZONTAL, length=140, label="r",
    variable=scColorbalance_r_Var, command=ev_colorbalancePara).pack(
        anchor=tk.W, side=tk.LEFT)

scColorbalance_g_Var = tk.DoubleVar()
scColorbalance_g_Var.set(1)
tk.Scale(lfcolorbalance, from_=0, to=256,
    orient=tk.HORIZONTAL, length=140, label="g",
    variable=scColorbalance_g_Var, command=ev_colorbalancePara).pack(
        anchor=tk.W, side=tk.LEFT)

scColorbalance_b_Var = tk.DoubleVar()
scColorbalance_b_Var.set(1)
tk.Scale(lfcolorbalance, from_=0, to=256,
    orient=tk.HORIZONTAL, length=140, label="b",
    variable=scColorbalance_b_Var, command=ev_colorbalancePara).pack(
        anchor=tk.W, side=tk.LEFT)

scColorbalance_u_Var = tk.IntVar()
scColorbalance_u_Var.set(0)
tk.Scale(lfcolorbalance, from_=0, to=255,
    orient=tk.HORIZONTAL, length=140, label="u",
    variable=scColorbalance_u_Var, command=ev_colorbalancePara).pack(
        anchor=tk.W, side=tk.LEFT)

scColorbalance_v_Var = tk.IntVar()
scColorbalance_v_Var.set(0)
tk.Scale(lfcolorbalance, from_=0, to=255,
    orient=tk.HORIZONTAL, length=140, label="v",
    variable=scColorbalance_v_Var, command=ev_colorbalancePara).pack(
        anchor=tk.W, side=tk.LEFT)

#==========================================================
root.mainloop()

print("- bye -")


Remark:
As this is writing, picamera is still 1.13, so the maximum resolution is 3280x2464 for V2, not HQ. 



~ Another minimum version:  with minimum functions preview and capture only, using PyQt5 GUI, fixed resolution 240x240, and display the captured image on GUI. You can also choice save file name; image.jpg or img_<timestamp>.jpg, under Desktop folder.

Related:

No comments: