[uBasic] Bewegungserkennung (motion detection)

CHDK-Skripte, CHDK-Entwicklung, PC-Zusatzprogramme, Informationen für Tüftler

Beitragvon msl » 30.07.2008, 19:31

Hallo und willkommen,

für die Bewegungserkennung muss das Display zwingend an sein, sonst funktioniert diese Erkennung nicht.

Gruß msl
Benutzeravatar
msl
Super-Mod
Super-Mod
 
Beiträge: 4567
Bilder: 271
Registriert: 22.02.2008, 11:47
Wohnort: Leipzig
Kamera(s): A720 1.00c
SX220 1.01a

Beitragvon Maddin » 30.07.2008, 19:39

Das ist ja schade, wird Deine A 610 denn auch dabei warm ?
Und weiss jemand warum das Display an bleiben muss ?

Martin
Zuletzt geändert von Maddin am 30.07.2008, 19:51, insgesamt 1-mal geändert.
Maddin
CHDK-Einsteiger
CHDK-Einsteiger
 
Beiträge: 5
Registriert: 28.07.2008, 17:34

Beitragvon msl » 30.07.2008, 19:48

Hm, ich habe keine A610 - siehe Signatur. Du solltest Deine Signatur auch mit Deinen Kameradaten versehen. Das ist hier im Forum gern gesehen.

Die Kamera hat halt viel zu tun und erwärmt sich wie bei jedem Dauerbetrieb. Dun solltest das Raster der Zellen auch nicht unnötig erhöhen. Die Vorgabe ist schon optimal.

Gruß msl
Benutzeravatar
msl
Super-Mod
Super-Mod
 
Beiträge: 4567
Bilder: 271
Registriert: 22.02.2008, 11:47
Wohnort: Leipzig
Kamera(s): A720 1.00c
SX220 1.01a

Beitragvon Maddin » 30.07.2008, 20:24

Danke für den Tipp,
sorry hatte bei "gehtnix" die 610 gesehen...
...hab meine Signatur angelegt

schönen Gruß
Martin
A 610 CHDK:Allbest + 350 D(ohne CHDK ;-) )
Maddin
CHDK-Einsteiger
CHDK-Einsteiger
 
Beiträge: 5
Registriert: 28.07.2008, 17:34

Beitragvon Kameralaie » 30.07.2008, 20:35

Hallo no.7,

danke für die schnelle Antwort.

Ich habe nach deinen Angaben die Parameter Empfindlichkeit (Pixel) und Lichtschwellenwert verändert. Nach mehreren Vesuchen habe ich die Werte dann auf 0 gesetzt. Bei allen anderen Einstellungen habe ich die vorgegeben Werte gelassen.

Es hat funktioniert, die Entfernung ist jetzt erheblich weiter (ca. 5 Meter).
Eine weitere Entfernung ist zur Zeit bei mir nicht möglich.

Da es jetzt schon spät ist, werde ich morgen noch weitere Versuche unternehemen.

Gruß
Kameralaie
meine Powershot A610
Kameralaie
CHDK-Einsteiger
CHDK-Einsteiger
 
Beiträge: 2
Registriert: 27.07.2008, 17:40
Wohnort: Jena

Beitragvon fe50 » 31.07.2008, 08:50

Maddin hat geschrieben:...Und weiss jemand warum das Display an bleiben muss ?

Die Bewegungserkennung arbeitet mit internen (Bild)Pufferspeichern des Kamerasensors, die "Display Aus" Funktionalität von Canon schaltet den Bildsensor samt Elektronik ab, dadurch wird zwar erheblich weniger Strom verbraucht, die Bewegungserkennung hat aber keine Daten zum arbeiten...

Wird ein Videostecker (A/V Buchse) verwendet (eingesteckt), wird nur die Hintergrundbeleuchtung des LCDs abgeschaltet, der Sensor & die Elektronik arbeiten weiter - es wird ja schliesslich ein "Live-Bild" als Videosignal, z.B. für einen Fernseher ausgegeben. Das spart zwar deutlich weniger Strom (nur den für die Hintergrundbeleuchtung des LCD), ist aber besser als gar nichts...

Im Wiedergabemodus (Play Back) verhält es sich ähnlich, hier ist die Stromaufnahme niedrig, der Sensor ist nicht aktiv...
Wenn also zukünftig per Script zwischen Aufnahme,- und Wiedergabemodus umgeschaltet werden kann, dürfte dies in Verbindung mit einem Script mit der Bewegungserkennung (MD) ebenfalls nicht klappen...
◄"The grass was greener, The light was brighter"►  ◄fe50 home►  ◄TRAIL-Magazin►  ◄RTFM !►
Benutzeravatar
fe50
CHDK-Legende
CHDK-Legende
 
Beiträge: 1106
Registriert: 25.04.2008, 14:28
Wohnort: B'Württemberg
Kamera(s): Ixus50 101b, Ixus860 100c, SX10 101a

Beitragvon no.7 » 31.07.2008, 09:54

@ fe50
Danke (!) für die verständliche Erklärung der grundsätzlichen Arbeitsweise
bei Bewegungserkennung.
Habe wieder ein wenig dazu gelernt. :)
Viele Grüße
no.7
Benutzeravatar
no.7
CHDK-Begeisterter
CHDK-Begeisterter
 
Beiträge: 97
Bilder: 0
Registriert: 06.05.2008, 16:47

Beitragvon chiptune » 19.08.2008, 07:32

mhm - zum Auslösen der Aufnahme wird hier und im englischen Forum meist der Scriptbefehl "if t then click "shoot_full" eingesetzt.

Laut Handbuch von msl und CHDKLover benötigt diese Scriptbefehl 50ms.
"shoot" würde nur 40ms benötigen, press sogar nur 30ms. Bei Blitzaufnahmen würden also 10-20 ms verschenkt - oder kommen hier andere Aspekte hinzu?

Außerdem sieht man oft Verzweigungen wie diese:

Code: Alles auswählen
md_detect_motion a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p
if h>0 then
   click "shoot_full"
   bla bla bla
endif


Wenn es zutrifft, dass jede Scriptzeile 10ms beansprucht, dann werden hier gegenüber der nachfolgenden Verzweigung 10ms verschenkt.

Code: Alles auswählen
md_detect_motion a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p
if h>0 then click "shoot_full"

(bla bla bla kann man danach getrennt behandeln).

fragende Grüße
chiptune
SX100IS mit CHDK
MD_SLOWMD_FASTMD_TUNE
chiptune
CHDK-Begeisterter
CHDK-Begeisterter
 
Beiträge: 131
Registriert: 16.07.2008, 05:24

Beitragvon saemikolon » 01.09.2008, 20:28

hi zusammen,

bin neu her, ich hab mich bisher nur im englischen forum getümmelt, bis ich zufällig auf dieses geniale forum gestoßen bin.
erstmal meinen allergrößten respekt an die programmierer und problemhelfer.

ich komme wunderbar mit dem "bewegungsmelder" zurecht - nur ich frage mich, was die verschiedenen prüfungsmethoden für eine bedeutung haben, oder ob das im prinzip egal ist, welche man laufen lässt?

danke schonmal
saemikolon
CHDK-Einsteiger
CHDK-Einsteiger
 
Beiträge: 3
Registriert: 01.09.2008, 20:23

Beitragvon fe50 » 02.09.2008, 13:17

Hi saemikolon,

einiges steht ja schon im Handbuch: CHDK Wikia: Handbuch Juciphox - Parameter Bewegungserkennung, wenn Du mehr Hintergrundwissen zu der MD benötigst - z.B. für etwas speziellere Einsatzzwecke wie Sonnenauf/untergänge, Nachtaufnahmen etc. - solltest Du im (englischen) Forum stöbern, da gibt's massig Infos, einfach nach "MD" suchen ;)
◄"The grass was greener, The light was brighter"►  ◄fe50 home►  ◄TRAIL-Magazin►  ◄RTFM !►
Benutzeravatar
fe50
CHDK-Legende
CHDK-Legende
 
Beiträge: 1106
Registriert: 25.04.2008, 14:28
Wohnort: B'Württemberg
Kamera(s): Ixus50 101b, Ixus860 100c, SX10 101a

Re: Bewegungserkennung (motion detection)

Beitragvon Caefix » 18.06.2018, 18:32

Praktische Schnipsel:


Code: Alles auswählen
while Q=4
    gosub "##foc"
    Q=(get_tv96>768)
    md_detect_motion 5-Q,5+Q,1,4*Q*t,t,99,3,Q,Q+1,2,2,1,3, Q ,Q,Q
    Q=4*(Q=0)
    wend

rem get_tv96>768 löst ab s/250 aus, Q=get_tv96<768 bis s/250
rem ? Q= () * (get_focus=-1)
& noch was für die Vitrine:
rem mittelfristig selbsterklärend & DAS gosub Intro für md_abc..p Anwendungen:

:##place
do
T=get_tick_count+20
md_detect_motion a,b,c,200,e,f,random 1 3,h,i,j,k,j+(a%2=0)-(a=2),k+(b%2=0)-(b=2),0,o,9
if h*(z=0)*(f<99) then print get_capture_mode,f,"(";a;"*";b;") ",h,T-get_tick_count
j=(j-is_pressed "left"+is_pressed "right"-(j>a))|(j<2)
k=(k-is_pressed "up"+is_pressed "down"-(k>b))|(k<2)
a=((a+is_pressed "zoom_in")%13)|(a<2)
b=((b+is_pressed "zoom_out")%13)|(b<2)
i=(i+is_pressed "set")%3
if is_pressed "menu" then gosub "##foc"
until is_key "shoot_half"
if i=2 then g=1 else g=3
l=j+(a%2=0)-(a=2)
m=k+(b%2=0)-(b=2)
return

:##foc
 set_aflock 0
 press "shoot_half"
 do
  sleep 99
 until not get_shooting
 set_aflock 1
 release "shoot_half"
 print get_exp_count,-get_zoom,-get_focus
 sleep 999
return

______________________________ [ "~~~^^~~~~~~~... :-({|= LUA-Äquivalent; P.S... siehe Ubasix \:D/ ...~~~~~~~^^~~~" ] ______________________________---
Code: Alles auswählen
:...,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....
---  reusable Intro, enjoy, Caefix 2019

--[[
-- standalone too
@param    h IntroConfiguratiX  Use Keys!
 @default h 1
 @range   h 0 1
--]]--

function look(x)
    set_aelock(0); set_aflock(0)
    press("shoot_half")
    repeat sleep(42) until not get_shooting()
    set_aflock(1); set_aelock(1)
    release("shoot_half")
    if x>0 then --   ubasic:
 --   print get_min_stack_dist;"mm",get_near_limit,-get_focus,-get_far_limit
    print(get_exp_count(),-get_focus(),"-av",get_av96()/32,"-tv",get_tv96()/32) end
    x=get_free_disk_space()
wait_click(999)
return x   
end

function place(...)
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,X=...  -- for scripts/calls without settings:
if a==nil then a=3 end
if b==nil then b=3 end
c=(c or 0)%6
if d==nil then d=60000 end
if e==nil then e=20 end
if f==nil then f=3 end
if g==nil then g=2 else g=g-1 end
h=0
if i==nil then i=1 end
if j==nil then j=(a+1)/2 end
if k==nil then k=(b+1)/2 end
if l==nil then l=j end
if m==nil then m=k end
n=n or 0
if o==nil then o=3 end
if p==nil then p=16 end  --
X=X or 0
local ab=a+b

repeat
   local a2=0; if a==2 then a2=1 end
   local b2=0; if b==2 then b2=1 end
   if j>a then j=a end
   if k>b then k=b end
   l=j+1-a%2-a2; m=k+1-b%2-b2; g=g%3+1
   local T=get_tick_count()
   h=md_detect_motion(a,b,1,200,e,f,g,h,i%3,j,k,l,m,0,o,9)
   if (h>0) or (ab~=a+b) and (X<2) and (f<99) then
      print(e,-f,"(",a,-b,")",h,T-get_tick_count())
      ab=a+b
      while is_pressed("shoot_half") do
         sleep(42); II=II end
      else console_redraw() end
   wait_click(9)
   if is_key("zoom_in")  then a=a%12+1 end
   if is_key("zoom_out") then b=b%12+1 end
   if is_key("left")  and j>1 then j=j-1 end
   if is_key("right") and j<a then j=j+1 end
   if is_key("up")   and k>1 then k=k-1 end
   if is_key("down") and k<b then k=k+1 end
   if is_key("set") then i=(i+1)%3 end
   if is_pressed("menu") then look(1) end -- oder Alt-Modus für Einstellungen verlassen.
   if is_key("display") then --<< use Your key!
 --     a=(a+1)/2; b=(b+1)/2 end --oder
       if a>1 then a=a-1 end
       if b>1 then b=b-1 end end
repeat sleep(222) until get_alt_mode()
until (h==0) and (is_key("shoot_half") or (X>0)) --!
g=3; if i==2 then g=1 end
wait_click(999); wait_click(99)
return a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p
end              --V-^ keeps setting

if (h==nil) or (h>0) then --<< Use Your condition or none!
       a,b,h,d,e,f,h,h,i,j,k,l,m,n,o,p= --<< new global values, use the scripts´s!!
 place(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,0) end --<< old global values, use the scripts´s!!
--- :...,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....
P.S. (md_detect_allgemein:) Bei bestimmten Einstellungen kann das Grid (g~=0) selbst mitgerechnet werden & auslösen... OO@@@~
EsGibtKeinenErdaufgangAufDemMond! SoSimpel...
Benutzeravatar
Caefix
CHDK-Begeisterter
CHDK-Begeisterter
 
Beiträge: 78
Registriert: 15.06.2018, 19:14
Kamera(s): Einige!

Re: Bewegungserkennung (motion detection)

Beitragvon Joedi » 06.03.2023, 11:58

Hallo Leute,
ich habe mich mal intensiver mit der Bewegungserkennungsfunktion von CHDK beschäftigt und möchte meine Ergebnisse in Form des Experimentierprogramms
"mdfasap86m8k.lua" (motion detection, fast, as soon as possible, Version 86m8k)
hier im Forum teilen und bitte um Kommentare!

Eigenschaften:
- getestet hauptsächlich mit A570IS, IXUS60,M10
- kameraspezifische Befehle wurden möglichst vermieden
- Priorität hat der Schnellstauslösungsmode
- Menü-Vorwahl einiger Parameter wie Ansprechschwelle,ISO, Zoom (Stufen 1-8), Blitz an/aus, RAW an/aus usw.
- wählbar: Zoom&Grid adj: Bequeme Einstellbarkeit von Zoom und Erkennungsgitter-(Zonen)gestaltung
- wählbar: man foc adj: Manuelle Scharfstellung, dabei autofocus aus
- automatisch: Ansprechschwelle justieren oberhalb der Bildrauschens bzw. der Scenerie-Unruhe
- wählbar: Wait4calm: Programmstart erst, wenn sich die Scenerie beruhigt hat
- einstellbar: maxtakes: Anzahl der Folgebilder
- einstellbar: Pause (in Stunden) von..bis, verhindert unsinnige Bilder z.b. nachts oder bei direktem Sonnenlicht.
- AFassistBeam ein/aus
- display-on ja/nein
- wählbar: skip if tv<100: Verhindert bei wenig Licht unsinnige Bilder, bei denen das bewegte Objekt ohnehin unscharf wäre.
- test-only: Modus, in dem keine Bilder gemacht werden( noch unfertig!)
- remote call-up: wenn mit chdkptp ferngeladen und aufgerufen, dann vorbesetzte Parameter
- alle Consolen-Audrucke werden in eine Datei /CHDK/LOGS/LOG_0005.TXT geschrieben

Vielleicht könnte mal jemand das Skript anschauen und ausprobieren. Bin für alle Kommentare dankbar.
Euer Joedi.
Code: Alles auswählen
--[[
@title mdfasap86m8k.lua
@chdk_version 1.5
@param   S addshreshold 1-99
@range   S 0 99
@default S 3
@param   I ISO 0=A,1..7=50..
@default I  3
@values  I  0 1 2 3 4 5 6 7
@param   z  Zoom (0=WW...8=Tele)
@default z 0
@values  z  0 1 2 3 4 5 6 7 8 
@param   X  Zoom&Grid-Adj
@default X  0
@values  X  0 1
@param   E man-focus-adj 
@default E 0
@range   E 0 1
@param   W  Wait4calm
@default W 0
@values  W 0 1
@param   maxtakes  No. of takes
@default maxtakes  1
@range  maxtakes  1 99
@param   P  pause-start (h)
@default P  0
@range   P  0 23
@param   Q  pause-stop (h)
@default Q  0
@range   Q  0 23
@param   A AFassistBeam
@default A 1
@range   A 0 1
@param   B flash-on
@default B 0
@range   B 0 1
@param   L display-on
@default L 1
@range   L 0 1
@param   M skip if tv<100
@default M 0
@range   M 0 1
@param   p re-tr.dly
@range   p 0 600
@default p 200
@param   RAWON RAW on ?
@default RAWON 0
@range   RAWON 0 1
@param   t test-only
@default t 0
@range   t 0 2
--]]
--
-- mdfasap ("motion detection, fast, as soon as possible") is a 2022 written lua script for experiments with CHDK motion detection
-- written by (c) joedi 2021-2023, except for the following excellent "basic_iris_calc()" function taken from CHDKPlus2.8.
-- submitted to the forum for comments

-- *******************************************
-- basic_iris_calc() is  mainly taken from: (slight modif only)
-- *******************************************
--     CHDK Plus v2.8
--     Licence: GPL
--    (c) waterwingz,msl,wayback/peabody 2014
--    artistic direction provide by fabri22
-- *******************************************
-- ISO+ : BASIC EXPOSURE CALCULATION USING SHUTTER SPEED, IRIS AND ISO
-- CALLED FOR IRIS-ONLY AND "BOTH" CAMERAS
-- (CAMERAS WITH AN IRIS & ND FILTER)

function basic_iris_calc()
    tv96setpoint = tv96target
    av96setpoint = av96target 
 --  CALCULATE REQUIRED ISO SETTING
    sv96setpoint = tv96setpoint + av96setpoint - bv96meter           
-- modif to original function here, forcing hi iso recalc as per "I":
   if (I>0) then sv96max1=99+sv_table[I+1] end -- triggs comp 3 l dwn 
 -- LOW AMBIENT LIGHT ?
 --  CHECK IF REQUIRED ISO SETTING IS TOO HIGH
    if (sv96setpoint > sv96max1 ) then                               
 --  CLAMP AT FIRST ISO LIMIT
        sv96setpoint = sv96max1                                       
 --  CALCULATE NEW APERTURE SETTING
        av96setpoint = bv96meter + sv96setpoint - tv96setpoint       
 --  CHECK IF NEW SETTING IS GOES BELOW LOWEST F-STOP
        if ( av96setpoint < av96minimum ) then                       
 --  CLAMP AT LOWEST F-STOP
            av96setpoint = av96minimum                               
 --  RECALCULATE ISO SETTING
            sv96setpoint = tv96setpoint + av96setpoint - bv96meter   
 --  CHECK IF THE RESULT IS ABOVE MAX2 ISO
            if (sv96setpoint > sv96max2 ) then                       
 --  CLAMP AT HIGHEST ISO SETTING IF SO
                sv96setpoint = sv96max2                               
 --  RECALCULATE SHUTTER SPEED NEEDED
                tv96setpoint = bv96meter + sv96setpoint - av96setpoint
 --  RECALCULATE REQUIRED SHUTTER SPEED DOWN TO TV MINIMUM
                 tv96setpoint = math.max(bv96meter+sv96setpoint-av96setpoint,tv96min)
            end
        end
 -- HIGH AMBIENT LIGHT ?
 --  CHECK IF REQUIRED ISO SETTING IS TOO LOW
    elseif (sv96setpoint < sv96min ) then                             
 --  CLAMP AT MINIMUM ISO SETTING IF SO
        sv96setpoint = sv96min                                       
 --  RECALCULATE REQUIRED SHUTTER SPEED
        tv96setpoint = bv96meter + sv96setpoint - av96setpoint       
 --  CHECK IF SHUTTER SPEED NOW TOO FAST
        if (tv96setpoint > tv96max ) then                             
 --  CLAMP AT MAXIMUM SHUTTER SPEED IF SO
            tv96setpoint = tv96max                                   
 --  CALCULATE NEW APERTURE SETTING
            av96setpoint = bv96meter + sv96setpoint - tv96setpoint   
 --  CHECK IF NEW SETTING IS GOES ABOVE HIGHEST F-STOP
            if ( av96setpoint > av96max ) then                       
 --  CLAMP AT HIGHEST F-STOP
                av96setpoint = av96max                               
 --  RECALCULATE SHUTTER SPEED NEEDED AND HOPE FOR THE BEST (CALLING FUNCTION MAY ACTIVATE ND FILTER IF AVAILABLE)
                tv96setpoint = bv96meter + sv96setpoint - av96setpoint
            end
        end
       
    end
end  -- *****************************************

-- functions: --------

function wait_for_calmness()
print "We wait for the scenery to calm down..."
mab=a*b   -- max of possible zones affected by motion
--     local zones=md_detect_motion(a,b,c,d,   e,f,g,h,i,j,k,l,m,n,o,p)
repeat local zones=md_detect_motion(a,b,c,1500,e,1,g,h,i,j,k,l,m,0,o,p)
print(zones,os.date("%Y%m%d-%H%M%S"))
if zones>=(mab/2) then print("far too much noise, MD of details won't work...!") end
until zones<=1
end -- of function

function set_threshold_f()
-- sets  -f- slightly larger than  the noise ...
dold=d
-- d=500 -- timeout val only  0.5s here,
 d=1500 -- timeout val only  1.5s here,
n=0   -- no shot, only measuring...
f=0   -- starting f with a value of 1
repeat
print("assessing threshold...")
f=f+2
zones=md_detect_motion(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
sleep(200)
if t==2 then print ("     f=",f," --> zones=",zones)  end
-- does given f still produce a response ?
until  ( zones == 0 )
f=f+S  -- zur Sicherkeit  um S  mehr...
-- Param S and the below add are safety margins, added onto noise level found
if (bv96<0) then f=f-(bv96/30) end -- bei -600 ca +20
print("f set to ",f)
d=dold -- wieder den alten timeout-Wert
sleep(500)
end

function get_current_tv96()
        -- wie unten bei "measure_and_set_exposure_params()":
   press ("shoot_half")
        repeat sleep(250) until get_shooting()==true
        bv96=get_bv96()
        if t==2 then print("bv96 found as ",bv96) end
   sleep(1000)
        release("shoot_half")   
   repeat sleep(50) until get_shooting()==false
        -- NOT CALLING basic_iris_calc()
        tv96 = bv96 + sv96setpoint - av96setpoint    
   if (t==2) then print("tv96=",tv96) end
end

function measure_and_set_exposure_params()
press ("shoot_half")
repeat sleep(250) until get_shooting()==true
-- set exposure values based on "luminance of the field"
bv96=get_bv96()
if t==2 then print("bv96 found as ",bv96) end
bv96meter=bv96 -- variablenname wie oben gefordert...
sleep(1000)
release("shoot_half")   
repeat sleep(50) until get_shooting()==false
sleep(100)
--  target parameters are:
tv96target=1056    -- =1/2000 sec; as fast as poss
tv96max=1056       --= 1/2000 sec für kürzeste Zeit
tv96min=-384      --= 16 sec für allerlängste Zeit
av96target=288    -- =f/2.8 ; wg. asap
av96minimum=288    --=f/2.8 bei A570IS
av96max=576        --=f/8   bei A570IS
--           =ISO 50  100  200  400  800  1600 3200 6400 12800
sv_table     = { 380, 411, 507, 603, 699, 795, 891, 987, 1083 }
-- used in basic_iris-calc function, see there above:
--         sv96max1   = sv_table[I+1] 
sv96min      = sv_table[1]
sv96max1     = sv_table[6]
sv96max2     = sv_table[7]
if t==2 then  print("sv-min:",sv96min, "target:",sv96target,"max1:",sv96max1,"max2:",sv96max2) end
basic_iris_calc()     --  calling the expos function
if t==2 then print("setpts:sv96=",sv96setpoint,"av96=",av96setpoint,"tv96=",tv96setpoint)
end
-- apply 'em setpoints:
set_sv96(sv96setpoint)
sleep(300)
set_tv96(tv96setpoint)
sleep(300)
set_tv96_direct(tv96setpoint)
sleep(300)
set_av96(av96setpoint)
sleep(300)
end   -- of function --

function print_params()
print("bv96=",bv96,"f=",f,"ISO=",sv96_to_iso(sv96setpoint),"F/",av96_to_aperture(av96setpoint), "T=",tv96_to_usec(tv96setpoint))
end   -- of function() --

function change_zoom()
zn=z   -- z is from param header ...
repeat
   zn100=zn*100
   zoomrange=get_zoom_steps() curzoom=get_zoom()
   znov=zn100*zoomrange/800    -- correctly generalized now ...
   if (curzoom~=znov) then set_zoom(znov)  sleep(3000)  end 
-- print("cam's zoom is now:",get_zoom(),"/",get_zoom_steps())
   wait_click(1000)
   if  (is_pressed("up"))    then set_zoom_rel(1) zn=zn+1 end
   if  (is_pressed("down"))  then set_zoom_rel(-1) zn=zn-1 end
   if  (is_pressed("zoom_in"))    then set_zoom_rel(1) zn=zn+1 end
   if  (is_pressed("zoom_out"))  then set_zoom_rel(-1) zn=zn-1 end
   if zn<0 then zn=0 end
   if zn>(zoomrange-1) then zn=zoomrange-1 end
   print("zoom=",get_zoom(),"/",get_zoom_steps(),"ok?->SET,or Up/Dn")
   sleep(1000)
until   (is_key("set"))
end   -- of function --

function change_focus()
 focw=10000 -- set to 10m, a fairly distant value
 set_aflock(1) -- is important for subseq set_focus
 set_focus(focw)
 sleep(1000)   
repeat 
set_exit_key("no_key")
print("foc=",get_focus(),"ok?->SET,or Up/Dn,or TestShoot")
wait_click()
if (is_pressed("up"))  then focw=(5*focw)/3  set_focus(focw) sleep(1500) end
if (is_pressed("down")) then focw=(5*focw)/7 set_focus(focw) sleep(1500) end
if (is_pressed("zoom_in"))  then focw=focw*2  set_focus(focw) sleep(1500) end
if (is_pressed("zoom_out")) then focw=focw/2 set_focus(focw) sleep(1500) end
if (is_pressed("erase")) then focw=55  set_focus(focw) sleep(1500) end
-- for a quick manual take:
if  (is_pressed("shoot_full")) then shoot() print("TestShoot w/",get_focus(),"mm") end

until   (is_key("set"))
set_exit_key("shoot_full")
end   -- of function --



function set_grid_size()
-- note: we _do_ manipulate the global variables a,i,j,l,b,k,m  -----
-- motion detect parameters only valid here in this function:
-- a= columns, b= rows to split picture into
-- if main was loaded and started remotely:
if (type(S) =="nil") then i=1  a=15   b=12  j=7 l=9 k=7 m=6 end
--   <--as a default starting pattern
neg=1   
local c=1         -- measure mode (U,Y,V R,G,B)
local d=200       -- timeout (mSec)
local e=100       -- comparison interval (msec) - less than 100
            -- will slow down other CHDK functions
local g=1         -- draw grid (0=no,1=grid,2=sensitivityr eadout,
            -- 3=sensitivity readout & grid)   
local h=0         -- not used in LUA
local n=0         -- opt. params. (0=no action, 1=shoot immediate)
       -- n=1 & 9 apparently (always ?) rigger flash  j.j.
local o=6         -- pixel step
local p=1000       -- (re-)Start delay  in msec
-- release("set")
while not((is_pressed("set")))
 do
 a=math.max(a,3) b=math.max(b,2)
 md_detect_motion(a,b,c,d,e,f,g,0,i,j,k,l,m,n,o,p)
 print("i",i,"a/b=",a,b,"jklm=",j,k,l,m," ok?->SET")
--              COLS  ROWS Maskengrösse in Spalten/Zeilen:
--                         links oben   rechs  unten               
--              a     b    j     k      l      m

 wait_click(0)

  if (is_pressed("zoom_in")) then a=math.max((a+5),4) b=math.max((b+4),6) rb=math.max(a/10,1) j=rb k=rb l=a-rb m=b-rb end
 if (is_pressed("zoom_out")) then a=math.max((a-5),4) b=math.max((b-4),6) rb=math.max(a/10,1) j=rb k=rb l=a-rb m=b-rb end

if (t~=2) then -- normal mode of grid adjust ---
 if  (is_pressed("display"))  then i=(i+1) if i>2 then i=0 end end
 if  (is_pressed("left"))  then a=a-1 b=b-1  j=j-1 k=k-1 end
 if  (is_pressed("up"))    then j=j-1 l=l+1 k=k-1  m=m+1 end
 if  (is_pressed("right")) then a=a+1 b=b+1 j=j+1 k=k+1 end
 if  (is_pressed("down"))  then j=j+1 l=l-1 k=k+1 m=m-1 end
 if  (is_pressed("erase")) then a=38 b=36 j=16 l=22 k=16 m=20 end
else  -- t==2  -->grid debug mode ----------------
 if  (is_pressed("shoot_half"))  then neg=(-neg) end -- dir flag toggle
 if  (is_pressed("display"))  then i=(i+1) if i>2 then i=0 end end
 if  (is_pressed("left"))  then j=j+neg end
 if  (is_pressed("up"))    then k=k-neg end
 if  (is_pressed("right")) then l=l+neg end
 if  (is_pressed("down"))  then m=m-neg end
-- now make use of curr params from here, & leaving test mode:
 if  (is_pressed("erase")) then t=0 end -- a subsequent "set" leaves loop
end

 end  -- of the do loop

end     -- of the lua function


-- =========================================================
-- ----- M A I N  P R O G   S T A R T S   H E R E :---------
-- =========================================================
-- -- tested with A570IS mainly
props=require("propcase")
-- general preparations (=only once)
set_console_layout(1,1,44,4)

-- modified defaults if main was loaded and started remotely:
if (type(S) =="nil") then print("remote callup w/ spec. default params") end
if (type(S) =="nil") then S=8 I=0 z=0 X=0 maxtakes=1 A=0 L=1 M=1 p=600 t=0 P=0 Q=0 RAWON=0 end

-- switch to shooting mode if necessary
if ( get_mode() == false ) then   
   set_record(1)
   while ( get_mode() == false ) do sleep(100) end
   sleep(1000)
   end

-- all printing is logged into this file:/CHDK/LOGS/LOG_0005.TXT
set_console_autoredraw(0) ; print_screen(-5)

if (get_raw()==false) and (RAWON==1) then error("switch RAW on in CHDK's main menu!") end
if (get_raw()==true) and (RAWON==0) then set_raw(false) end

-- switching flash off
if (B==0) then set_prop(props.FLASH_MODE, 2) sleep(1000) end  -- flash off
set_prop(props.IS_MODE, 3)        -- IS_MODE off
set_prop(props.AF_ASSIST_BEAM,A)  -- AF assist on/off

-- Zoom&Grid-Adj-----
if X==1 then
        -- Start values  now reasonably correct (:-))):
        i=1 a=15 b=12 j=2 k=2 l=a-j+1 m=b-k+1
        change_zoom()
        cls()
        set_grid_size()
        else
         -- use the 0...8 value of z from header:
        proz=(z*100/8)
   szv=get_zoom_steps()*proz/100
        set_zoom(szv) 
end

-- Manual focus setting if that was selected in menu
ovm=get_sd_over_modes()
if (E==1) and (ovm==0x07) then change_focus() end

-- print prog's name:
sn=get_config_value(1054)
sn=string.sub(sn,16) -- "CHDK" und "SCRIPTS" ausblenden
print() print("=========================")
print("This is ",sn) print(os.date("%Y%m%d-%H%M%S"))
set_console_layout(1,1,40,14)
zones=0 -- triggers the inital noise margin measurement...
print("I=",I) asa=50*I  print("ISO-target=",asa)
set_iso_mode(I) -- IS0 80 - 1600 -- maybe overridden later...??
sleep(300)
print("iso-mode now set to:",get_iso_mode())

-- motion detect parameters are preset, if X==0, as follows:
-- a= columns, b= rows to split picture into
--??         COLS  beg..end    ROWS beg..end  mask mode
if X==0 then a=8   j=2 l=7     b=6  k=2 m=5    i=1    end
c=1         -- measure mode (U,Y,V R,G,B)
d=300000    -- timeout (mSec)
e=100       -- comparison interval (msec) - less than 100
            -- will slow down other CHDK functions, they say
g=1         -- draw grid (0=no,1=grid,2=sensitivityr eadout,
            -- 3=sensitivity readout & grid)   
h=0         -- not used in LUA
-- j,k,l,m see above
n=1         -- optional parameters  (1=shoot immediate)
o=6         -- pixel step
p=800       -- (re-)Start delay  in msec
print("p set to ",p)

if (L==0) then set_lcd_display(0) end
sleep(500)

press ("shoot_half")
  repeat sleep(250) until get_shooting()==true
  -- use autofocus; if impossible, then use hyp-dist.
  dof=get_dofinfo() fw=5000
  if (dof.hyp_valid == true ) then fw=dof.hyp_dist end
  entf=get_focus()
  gfok=get_focus_ok()
  if gfok==0 then set_aflock(1) set_focus(fw) end
  if (E==1) then set_aflock(1) set_focus(focw) end 
  print("FOKUS=",get_focus())
release("shoot_half")

if t>=1 then pzz=0
   repeat -- testing the expo params' calculus ---
   set_console_layout(0,0,48,14)
   measure_and_set_exposure_params()
   set_threshold_f() -- a bit higher than the noise
   print_params()
   if (pzz/10)==0 then pzz=0 print(sn,"TEST,key=cont,shoot=stop") end
   pzz=pzz+10
   wait_click()
   until (0==1)
end

if (W==1) then wait_for_calmness() end

check0=get_exp_count() -- monit stor img no.
zones=0 -- initial value, nothing detected yet, of course
dlt=60000 -- delay time initially 1 min, 32 min max

-- **** M A I N'S *** M o t D e t  L O O P   starts here: *************
repeat -- forever, see bottom line's "until(false)" statement     
-- if nothing had been detected till timeout,
-- we now fist check if any inactivity time is due:
--from the internet:
--Gets the current time: Examples:
--print (os.date ("%x")) --> 25/04/07
--print (os.date ("%c")) --> 25/04/07 10:10:05
--print (os.date ("%A, %m %B %Y")) --> Wednesday, 04 April 2007
-- t = os.date ("*t") --> produces a table like this:
-- { t.sec=18 ,t.min=13,t.hour=10, t.day=25 t.month=4, t.year=2007,
-- t.wday=4, t.yday=115, t.isdst=false }

if (not((P==0) and (Q==0)))
   then
   AT=os.date("%c")  -- = Zuweisung an einfachen String
        -- nur Stunde herausholen
   ASX=string.byte(string.sub(AT,8,8))-48
   ASE=string.byte(string.sub(AT,9,9))-48
        AS=10*ASX+1*ASE
   -- print(AT,AS)
   -- print(P, AS, Q)
        -- sleep(9000)
        if (  (P<=AS) and (Q>AS))
   then
                print("Pause bis ", Q,": 00")
   slms=(Q-AS)*3600*1000
                sleep(slms)
   -- verbleibende Zeit verschlafen
        else
   end
end 

-- and we now recalculate expo and threshold:
if zones==0 then
   measure_and_set_exposure_params()
   set_threshold_f() -- a bit higher than the noise   
end
-- set some params:
g=1   -- show grid only
n=9   -- =1001 bin, immediate triggering and hold, see  handbook
p=1000  -- ????? as an anti-looping
check1=get_exp_count() -- monit stor img no.
banz=get_exp_count()-check0
--(os.date("%Y%m%d-%H%M%S"))  <---format example       
if zones~=0 then du=(os.date("%H%M%S")) print_params()
            print(sn,"#:",banz,"IMG_",check1,"@",du,"h")
            end
sleep(400)  -- it appears it's necessary...
set_console_layout(0,0,40,5)
-- prepare for first take, in fast mode: (ds is "disk space")
ds0=get_free_disk_space()
if (t>=1) then print("M=",M," tv96stp=",tv96setpoint,"bv96=",bv96) end
get_current_tv96()

-- The very Motion Detection follows here: -----------
-- n.b. M==1 is "do not shoot if expo time is too slow"
if M==0 or (M==1 and tv96>640)  -- +640 = 1/100 s
then
    dlt=60000
    -- now MotDet with n=9, which shoots immediately if someting is detected:
    print(banz,"taken, waitin' for motion now:")
    tb4=get_tick_count()  -- get time before md start (ms)       

    -- sys bug? it appears that MotDet with n=9 retriggers flash although
    --  it was turned off?:
    -- work-around: if (tv<640), i.e. low light, we use n=0's slow MotDet instead:
    if (tv96<640)
   then nold=n n=0
   zones=md_detect_motion(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
    n=nold
   if (zones>0) then press("shoot_half") press("shoot_full") end
   print("tv96 was:",tv96,"slow MD used")
   else
   zones=md_detect_motion(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
   print("tv96 was:",tv96,"fast MD used")
   end

   tb5=get_tick_count()  -- get time afer md finished (ms)
   -- too many takes in a short period may mean: too much noise yet--:
   mddur=tb5-tb4 
   if mddur<(d/20) then S=S+2 end -- inc S, thus desesitize
   release("shoot_full") -- mandatory anyway in the e.g. n=9 case
   release("shoot_half")   
   sleep(2000)
        else
   dlt=dlt*2 
   if dlt>1800000 then dlt=1800000 end
        dltm=dlt/60000
        print("waitin'",dltm,"min for more light...")
   zones=0 sleep(dlt)
end

        repeat sleep(150) until (get_shooting()==false)

        if zones~=0
          then
          repeat sleep(150) until (get_exp_count()~=check1)
     repeat sleep(100) ds1=get_free_disk_space() until ds1<ds0
     repeat dsv=get_free_disk_space() sleep(100) until
              get_free_disk_space()==dsv   -- Stabilität abwarten
     takeno=1
          -- 'maxtakes' trail takes now taken asap: --------
        while (takeno<maxtakes)   
             do
        takeno=takeno+1
         ds0=get_free_disk_space()
             check2=get_exp_count() -- mon stor img no.
             shoot()
             repeat sleep(50) until (get_exp_count()~=check2)
        repeat sleep(50) ds1=get_free_disk_space() until ds1<ds0
        repeat dsv=get_free_disk_space() sleep(50) until    
                                 get_free_disk_space()==dsv
        end -- (of "trailer imgs taken" section)
          -- gotten here, we loop back quickly
          end 
         
          -- Note; a 'zones==0' retd from MD would trigger re-calc etc
   
until (false) -- loops forever. Press "shoot full" to stop!
-- ****** the main M o t  D e t  L O O P  ends here ************   
-- ======= M A I N  P R O G   E N D S   H E R E ================
 

"Sorry", die Benutzerführung und meine Kommentare im Skript sind meistens Englisch...
Joedi
CHDK-Einsteiger
CHDK-Einsteiger
 
Beiträge: 17
Registriert: 17.02.2020, 21:02
Wohnort: MA/HD
Kamera(s): IXUS60, A470, A530, A570IS, A590IS, SX230, M10

Vorherige

Zurück zu Code-Ecke

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste

cron