Showing posts with label High Quality Camera. Show all posts
Showing posts with label High Quality Camera. Show all posts

Friday, June 18, 2021

The Moon: Raspberry Pi HQ Camera + Tamron SP 500mm f8 Mirror Lens

This photo and video was token using Raspberry Pi HQ Camera + Tamron Adaptall-2 SP 500mm f8 (55BB).


using Nikon-C adapter







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

rpiCam_20210619a.py, to capture still photo.
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("rpiCam (@2021-06-17)")
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 -")


rpiVid_20210619a.py, modified to capture video.
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 evCaptureVideoBtnPressed():
    if btnCapture.config('relief')[-1] == 'sunken':
        btnCapture.config(relief="raised")
        btnCapture['text'] = 'Start Capture Video'
        print("Stop Capture Video")
        camera.stop_recording()
    else:
        btnCapture.config(relief="sunken")
        btnCapture['text'] = 'Stop Capture Video'
        print("Start Capture Video")
        
        timeStamp = time.strftime("%Y%m%d-%H%M%S")
        targetPath="/home/pi/Desktop/vid_"+timeStamp+".h264"
        print(targetPath)
        camera.start_recording(targetPath, format='h264');
    
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
camera.resolution = (1920, 1080)  # Video
#end of set default

SCALE_WIDTH = 940;

#Prepare GUI
root = tk.Tk()
#root.geometry("650x550")
root.geometry("960x800")
root.wm_title("rpiVid (@2021-06-17)")
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 = tk.Button(frameMain, text="Start Capture Video",
                       relief="raised",
                       command=evCaptureVideoBtnPressed)

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 -")



Monday, March 22, 2021

min. version of RPi/Python Code to control Camera Module with preview on local HDMI

It's a minimum version of my another exercise "RPi/Python Code to control Camera Module with preview on local HDMI"; 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. It's used to prepare images for my coming exercise "Raspberry Pi/Python send image to ESP32/MicroPython via WiFi TCP socket".

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 camera on remote Android device, adjust focus/aperture on the lens, and check the effect on local HDMI preview at real-time.


Python3 code, qCam240_20210323.py
import sys
import picamera
from pkg_resources import require
import time
import picamera

from PyQt5.QtWidgets import (QApplication, QWidget,
                             QPushButton, QLabel, QRadioButton,
                             QMessageBox, QHBoxLayout, QVBoxLayout)
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.Qt import qRed, qGreen, qBlue
from signal import signal, SIGINT

print(sys.version)
print(require('picamera'))

rpi_icon = 'rpi_icon_240.png'

class AppWindow(QWidget):
    
    camPreviewState = False  #not in Preview
    
    def __init__(self):
        super().__init__()

        self.camera = picamera.PiCamera()
        self.camera.resolution = (240, 240)
        
        lbSysInfo = QLabel('Python:\n' + sys.version)
        lbPicameraInfo = QLabel(str(require('picamera')))
        vboxInfo = QVBoxLayout()
        vboxInfo.addWidget(lbSysInfo)
        vboxInfo.addWidget(lbPicameraInfo)
        
        #setup UI
        btnPreview = QPushButton("Start Preview", self)
        btnPreview.clicked.connect(self.evBtnPreviewClicked)
        btnCapture = QPushButton("Capture", self)
        btnCapture.clicked.connect(self.evBtnCaptureClicked)
        
        lbFileName = QLabel('save as (Desktop/):')
        self.rbtnImage = QRadioButton('image.jpg')
        self.rbtnImage.setChecked(True)
        self.rbtnStamp = QRadioButton('img_<timestamp>.jpg')
        
        vboxCamControl = QVBoxLayout()
        vboxCamControl.addWidget(btnPreview)
        vboxCamControl.addWidget(btnCapture)
        vboxCamControl.addWidget(lbFileName)
        vboxCamControl.addWidget(self.rbtnImage)
        vboxCamControl.addWidget(self.rbtnStamp)
        vboxCamControl.addStretch()
        
        self.lbImg = QLabel(self)
        self.lbImg.resize(240, 240)
        self.lbImg.setStyleSheet("border: 1px solid black;")
        
        try:
            with open(rpi_icon):
                pixmap = QPixmap(rpi_icon)
                self.lbImg.setPixmap(pixmap)
        except FileNotFoundError:
            print('File Not Found Error')
        
        hboxCam = QHBoxLayout()
        hboxCam.addWidget(self.lbImg)
        hboxCam.addLayout(vboxCamControl)

        self.lbPath = QLabel(self)

        vboxMain = QVBoxLayout()
        vboxMain.addLayout(vboxInfo)
        vboxMain.addLayout(hboxCam)
        vboxMain.addWidget(self.lbPath)
        vboxMain.addStretch()
        self.setLayout(vboxMain)
        
        self.setGeometry(100, 100, 500,400)
        self.show()

    def evBtnPreviewClicked(self):
        if self.camPreviewState:
            print('Stop Preview')
            self.camera.stop_preview()
            self.sender().setText('Start Preview')
            self.camPreviewState = False
        else:
            print('Start Preview')
            self.camera.start_preview()
            self.sender().setText('Stop Preview')
            self.camPreviewState = True
        
    def evBtnCaptureClicked(self):
        print('evBtnCaptureClicked()')
        print("Capture")
        
        if self.rbtnImage.isChecked():
            targetPath="/home/pi/Desktop/image.jpg" 
        else:
            timeStamp = time.strftime("%Y%m%d-%H%M%S")
            targetPath="/home/pi/Desktop/img_"+timeStamp+".jpg"
        
        print(targetPath)
        
        self.camera.capture(targetPath)
        self.lbPath.setText(targetPath)
        
        try:
            with open(targetPath):
                pixmap = QPixmap(targetPath)
                self.lbImg.setPixmap(pixmap)
                
                #as a exercise, get some info from pixmap
                print('\npixmap:')
                print(pixmap)
                print(type(pixmap))
                print(str(pixmap.width()) + " : " + str(pixmap.height()))
                print()
                
                print('convert to Image')
                qim = pixmap.toImage()
                print(qim)
                print(type(qim))
                print()
                
                print('read a pixel from image')
                qrgb = qim.pixel(0, 0)
                print(hex(qrgb))
                print(type(qrgb))
                
                r, g, b = qRed(qrgb), qGreen(qrgb), qBlue(qrgb) 
                print([hex(r), hex(g), hex(b)])
                print()

        except FileNotFoundError:
            print('File Not Found Error')
        
    def closeEvent(self, event):
        confirmClose = QMessageBox.question(self,
                                            "Quit App?",
                                            "Confirm to Quit?",
                                            QMessageBox.No | QMessageBox.Yes,
                                            QMessageBox.Yes)
        if confirmClose == QMessageBox.Yes:
            print('Confirmed Close')
            self.camera.close()
            event.accept()
        else:
            event.ignore()
        
if __name__ == '__main__':
    print('run __main__')
    app = QApplication(sys.argv)
    window = AppWindow()
    sys.exit(app.exec_())

print("- bye -")

Download the thumbnail image, save as "rpi_icon_240.png" in the same folder. Used as a default image only.



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:

Saturday, May 23, 2020

Python to control Raspberry Pi Camera

It's a simple Python script run on Raspberry Pi/Raspbian to perform simple control of camera, start preview, stop preview, and capture photo.

It run with Python3.

import sys
from tkinter import *
import picamera
from pkg_resources import require
import time

#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)

print(sys.version)
print(require('picamera'))


#Prepare camera
camera = picamera.PiCamera()


root = Tk()
root.geometry("600x360")
root.wm_title("Hello")
#root.configure(bg = "#909090")

labelSys = Label(root, text=sys.version, justify=LEFT)
labelSys.grid(row=0, columnspan=2, sticky=W)
labelPiCameraVer = Label(root, text=require('picamera'), justify=LEFT)
labelPiCameraVer.grid(row=1, columnspan=2, sticky=W)
                         

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

btnCapture = Button(root, text="Capture",
                    command=evCaptureBtnPressed)
btnCapture.grid(row=3, columnspan=2, sticky=W+E)


root.mainloop()

#close tasks
camera.close()

With Microsoft's Remote Desktop on Android device, it can be run remotely. The camera preview will be displayed on local screen.


xredp have to be installed in Raspberry Pi, with command:
$ sudo apt-get install xrdp

This video show how it run on Raspberry Pi 3 with Waveshare 4" HDMI LCD, run it on Android phone with Remote Desktop app. The local mounted display (4" HDMI LCD) is used as viewfinder.


Remark:
If you run the script locally, the preview will cover the GUI, but you can still click on it. Click the original position of the Stop Preview button to close the preview.


NOT WORK on High Quality Camera

Once I received High Quality Camera and tested on it, the script fail when capture continuously. Then I make a simple script to take photos using RPi Camera Module, work on v2.1, but also faile on High Quality Camera with "picamera.exc.PiCameraRuntimeError: No data received from sensor."


What's wrong on the script? or my Raspberry Pi High Quality Camera defected?

Tested on:
- Raspberry Pi 3B+
- Update Raspberry Pi OS
- Python 3.7.3
- picamera 1.13

doCappp.py
import picamera
import time

with picamera.PiCamera() as camera:
    camera.start_preview()
    for i in range(5):
        camera.resolution = (1280, 720)
        time.sleep(1)
        filename = 'imageA%02d.jpg' % i
        camera.capture(filename)
        print('Captured %s' % filename)
    time.sleep(7)
    
    print("End")
    camera.stop_preview()
    time.sleep(1)
    print("End End")
    camera.close()
    print("End End End")