--[[
@title MDFB 2013 v1.3.2
@chdk_version 1.3
-- based on fudgey's Fast/Slow/Video Motion Detector.
-- converted to Lua by waterwingz
@subtitle SEE MDFB2103.txt for
@subtitle ADDITIONAL DOCUMENTATION!
additional documentation.
md_detect_motion( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
a -- columns to split picture into
b -- rows to split picture into
c -- measure mode (Y,U,V R,G,B) U=0, Y=1, V=2, R=3, G=4, B=5
d -- timeout (mSec)
e -- comparison interval (msec) - less than 100 may slow down other CHDK functions
f -- trigger threshold
g -- draw grid (0=no, 1=grid, 2=sensitivity readout, 3=sensitivity readout & grid)
h -- not used in LUA
i -- region masking mode: 0=no regions, 1=include, 2=exclude
j -- first column
k -- first row
l -- last column
m -- last row
n -- optional parameters (1=shoot immediate, 8=don't release shoot_full)
o -- pixel step
p -- trigger delay in msec
@param s Mode
@default s 0
@values s Photo Video
@param u Reaction Mode
@default u 0
@values u Fast Normal Test
@param f Trigger Threshold
@default f 10
@range f 0 255
@param p Trigger Delay (0.1 sec)
@default p 5
@range p 0 100
@param r Burst/Review/Video time (s)
@default r 0
@range r 0 1000
@param e Compare Interval (ms)
@default e 7
@range e 0 10000
@param d Timeout (seconds)
@default d 300
@range d 0 1000
@param o Pixel Step (pixels)
@default o 6
@range o 1 255
@param c Detection Channel
@default c 1
@values c U Y V Red Green Blue
@param a Columns
@default a 6
@range a 1 16
@param b Rows
@default b 4
@range b 1 16
@param i Masking ~(00)~
@default i 0
@values i No Mask Use
@param j - mask columns left
@default j 0
@range j 0 16
@param k - mask rows top
@default k 0
@range k 0 16
@param l - mask columns right
@default l 0
@range l 0 16
@param m - mask rows bottom
@default m 0
@range m 0 16
@param y IS Disable mode?
@default y 0
@values y OFF 0 1 2 3 4 5 6
@param t Display Power Saving
@default t 1
@values t Off Bcklite LCD
@param h IntroConfiguratiX Use Keys!
@default h 1
@range h 0 1
@param v Splash Screen
@default v 1
@range v 0 1
@param w Logging?
@default w 0
@values w Off Console SDCard Both
--]]
require("drawings")
props
=require("propcase")
script_version
="1.3.2"
-- convert user @params to intellible variable names
post_shot_delay
= r
*1000 -- burst/review/video time
av_mode
= s
-- picture / video mode ?
lcd_mode
= t
-- LCD backlight or display to be turned off?
lcd_state
= 1 -- assume script starts with LCD display & backlight enabled
reaction_mode
= u
-- shoot immediate in MD function / normal / test mode
splash_screen
= v
-- display version info at startup
logging
= w
-- selects where to log program status stuff
set_IS_mode
= y
-- value+1 used to attempt IS mode disable (0 = no attempt)
-- allow motion detection function to use single character variable names for convenience
d
=d
*1000
j
=j+
1
k
=k+
1
l
=a-l
m
=b-m
p
=p
*100
function detect_motion
(compare,threshold,grid,options
)
local t
= md_detect_motion
( a, b, c, d, compare, threshold, grid, h, i, j, k, l, m, options, o, p
)
return t
end
function restore
() -- Zeilen etwas anders arrangiert and_or 0, Caefix 2019
if ( lcd_mode
== 1 ) then set_backlight
(1) end
if ( lcd_mode
== 2 ) then set_lcd_display
(1) end
set_console_autoredraw
(1)
if (set_IS_mode
> 0) then set_prop
(props.IS_MODE, is_mode
or 0) end
set_prop
(props.FLASH_MODE, flash_mode
or 0)
set_prop
(props.AF_ASSIST_BEAM,AF_assist_mode
or 0)
end
function printf
(...
)
print(string.format(...
))
end
function update_display_state
(state
)
if ( lcd_mode
> 0 ) then
if ( lcd_mode
== 1 ) then
set_backlight
(0)
elseif (lcd_state
== 1 ) then
set_lcd_display
(0)
lcd_state
= 0
end
end
end
function logging_init
()
if( logging
== 0 ) then
set_console_autoredraw
(-
1) -- console off, SD card log off
print_screen
(0)
cls
()
elseif ( logging
== 1) then
set_console_autoredraw
(1) -- console on, SD card log off
print_screen
(0)
elseif ( logging
== 2) then
set_console_autoredraw
(-
1) -- console off, SD card log on
print_screen
(1)
cls
()
elseif ( logging
==3 ) then
set_console_autoredraw
(0) -- console on, SD card log on
print_screen
(1)
end
end
function splash
(message
)
if (splash_screen
== 1 ) then
local line
= 10
local title
= "MDFB 2013 v".. script_version
local ver
= string.format(" %s %s-%s", bi.version, bi.build_number, build
)
local xpos1
= 200-
string.len(title
)*5
local xpos2
= 200-
string.len(message
)*5
local xpos3
= 200-
string.len(ver
)*5
draw.add
("rectf", xpos2-
22, line
*8, xpos2+
10*string.len(message
)+
10, line
*18,
"blue",
"yellow",
3)
draw.add
("string", xpos1, line
*10, title,
"red",
"yellow")
draw.add
("string", xpos2, line
*12, message,
"blue",
"yellow")
draw.add
("string", xpos3, line
*14, ver,
"blue",
"yellow")
for cnt
=1,
8 do
draw.overdraw
()
sleep
(500)
end
draw_clear
()
end
collectgarbage()
end
function fast_md
()
splash
("Fast Reaction Photo MD")
repeat
repeat
release
("shoot_half")
press
("shoot_half")
repeat sleep
(10) until (get_shooting
()==true)
update_display_state
()
until ( detect_motion
(e,f,
1,
9) >0 )
if (post_shot_delay
> 0) then sleep
(post_shot_delay
) end
release
("shoot_full")
release
("shoot_half")
repeat sleep
(10) until (get_shooting
()==false)
wait_click
(1000) -- allow time for backlight reset before looping back
until not( is_key
("no_key"))
end
function standard_md
()
splash
("Normal Reaction Photo MD")
repeat
repeat
sleep
(10)
update_display_state
()
until (detect_motion
(e,f,
1,
0) >0)
if (post_shot_delay
>0) then
press
("shoot_full")
sleep
(post_shot_delay
)
release
("shoot_full")
release
("shoot_half")
repeat sleep
(10) until (get_shooting
()==false)
else
shoot
()
end
wait_click
(2000) -- allow time for saving current file & backlight reset before looping back
until not( is_key
("no_key"))
end
function fast_video_md
()
if ( video_button
) then
standard_video_md
() -- no fast video mode for models with separate video buttons
else
splash
("Fast Reaction Video MD")
if post_shot_delay
<5000 then post_shot_delay
=5000 end
repeat
repeat
update_display_state
()
release
("shoot_half")
press
("shoot_half")
sleep
(3000) -- allow time for focussing - may crash without this
until (detect_motion
(e,f,
1,
9)>0) -- note : press "shoot_full" will be done in by detect_motion()
sleep
(300)
release
("shoot_full")
sleep
(post_shot_delay
)
click
("shoot_full")
wait_click
(2000) -- allow time for saving current file & backlight reset before looping back
until not( is_key
("no_key"))
end
end
function standard_video_md
()
splash
("Standard Mode Video MD")
if post_shot_delay
<5000 then post_shot_delay
=5000 end
repeat
repeat
sleep
(10)
update_display_state
()
until (detect_motion
(e,f,
1,
0)>0)
if( video_button
) then click
"video"
else
press
("shoot_full")
sleep
(300)
release
("shoot_full")
end
sleep
(post_shot_delay
)
if( video_button
) then
click
"video"
else
press
("shoot_full")
sleep
(300)
release
("shoot_full")
end
wait_click
(2000) -- allow time for saving current file & backlight reset before looping back
until not( is_key
("no_key"))
end
function test_md
()
splash
("Starting MD Testing Mode")
repeat
detect_motion
(500,
255,
3,
0)
wait_click
(20)
until not( is_key
("no_key"))
end
--- :...,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....
--- v1.3.2 : nothing changed, planted reusable Intro, enjoy, Caefix 2019
function look
(x
)
set_aelock
(0); set_aflock
(0)
press
("shoot_half")
repeat sleep
(42) until 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
>0 then --<< choose Your condition
a,b,h,d,e,f,h,h,i,j,k,l,m,n,o,p
= --<< new global values, use the scrips´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 scrips´s!!
--- :...,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....
--[[ =============V============ Main Program ========================================================================= --]]
set_console_layout
(1 ,
1,
45,
14 )
printf
("MDFB 2013 started")
bi
=get_buildinfo
()
version
= tonumber(string.sub(bi.build_number,
1,
1))*100 +
tonumber(string.sub(bi.build_number,
3,
3))*10 +
tonumber(string.sub(bi.build_number,
5,
5))
if ( tonumber(bi.build_revision
) > 0 ) then
build
= tonumber(bi.build_revision
)
else
build
= tonumber(string.match
(bi.build_number,
&#
39;-
(%d+
)$
&#
39;))
end
if ( version
< 120) or ( build
< 3149) then
printf
("%s %s-%s %s %s %s", bi.version, bi.build_number, bi.build_revision, bi.platform, bi.platsub, bi.build_date
)
printf
("CHDK 1.2.0 or higher, build 3149 or higher, required")
else
-- switch to shooting mode if necessary
if ( get_mode
() == false ) then
set_record
(1)
while ( get_mode
() == false ) do sleep
(100) end
sleep
(1000)
else
sleep
(500)
end
-- setup
flash_mode
= get_prop
(props.FLASH_MODE
)
set_prop
(props.FLASH_MODE,
2) -- flash off
AF_assist_mode
= get_prop
(props.AF_ASSIST_BEAM
)
set_prop
(props.AF_ASSIST_BEAM,
0) -- AF assist off
if (set_IS_mode
> 0) then
is_mode
= get_prop
(props.IS_MODE
)
set_prop
(props.IS_MODE, set_IS_mode-
1) -- IS_MODE off
end
logging_init
()
if ( version
>= 130 ) then set_draw_title_line
(0) end
if( get_video_button
() == 1) then video_button
= true else video_button
= false end
-- run
if (av_mode
==1) then
if (reaction_mode
==0) then fast_video_md
()
elseif (reaction_mode
==1) then standard_video_md
()
else test_md
()
end
else
if (reaction_mode
==0) then fast_md
()
elseif (reaction_mode
==1) then standard_md
()
else test_md
()
end
end
--done
restore
()
endErstellt in 0.043 Sekunden, mit
GeSHi 1.0.8.9