CHDK Wiki
Register
Advertisement

Multipurpose Motion Detector

Written for/on: Powershot S3IS
Also works on:
Required CHDK build: Fingalo's build 119

This is a script for motion detection based on the samples provided by MX3. The aim is just to make the life of people that don't know how to program easier.

Documentation/Help (save as a small "Motion Detection.txt" file to your /CHDK/SCRIPTS/ folder)


Tested on S3IS only Requires Fingalo's build v 119 Use with caution!

For better performance, turn off the shot review in camera menu. This script uses luminance variation to detect motion. The timeout is set to 600 sec. It means that if nothing is detected in 10 min, the detection "trap" is re-armed. To stop the script, press the shutter button anytime.

[ INPUTS ]

Shot (0=nf/1=f/2=c/3=t)

0 -> shoot without auto-focusing. It's like pressing the shutter button fully. Use with manual focus to improve speed.

1 -> shoot with auto-focusing. It's like pressing the shutter button half way to the camera find the proper settings and then fully to tale the shot.

2 -> shoot holding the shutter button for a while. It needs to be in continuos mode.

3 -> test mode. It doesn't shoot, it just shows information on how many cells detected movement. Use it to tweak the settings.

Continuos shoot (secs)

How long the shutter button will be pressed in continuos mode (in seconds).

Threshold (0-255)

Sensitivity of motion detection. It seems the lower the value, the more sensitive it becomes.

Compare Interval (msecs)

This is the sample rate. It tests if the image changed in the givem interval, if so, a motion is detected.

Compare Interval (secs)

Same as above, but for longer test time. Just to make easier to input longer times. More than 600 secs is useless due to the 600 secs timeout.

Begin Delay (secs)

I'm not sure about what this parameter means. It seems like a lag after a motion is detected. In my tests, if the value is lower then five secs, after the first detection, the camera starts shooting continuosly. Test values to suit your needs. It can be a bit lower if you turned off the review shot feature or ir you're using few detection cells. In test mode (3), this value can be much lower, be cautious.

Pix step (speed/accuracy adj)

I'm not sure how this works. It seems the lower the value, the more sensitive it becomes.

Columns

Number of columns sensitive to motion (luminance variations) in the MD grid.

Rows

Number of rows sensitive to motion (luminance variations) in the MD grid.

Dead frame

This is the width of a frame that is not sensitive to motion. If you want that the motion is detected only when it occurs at the center of your camera display, put a value greater than zero here. Just alter the value and see how the detection grid changes in your camera display.


Script Code (save as "Motion Detection.bas" to your /CHDK/SCRIPTS/ folder)

rem Author: MLuna - based om MX3 sample script
rem Tested on S3IS only
rem Requires Fingalo's build v 119
rem Use with caution!

@title Motion Detection

rem Shot without auto-focus/with auto-focus/continously (nedd to put in continous mode manually)
rem T implies test mode with MD cells drawing and no shots taken
@param a Shot (0=nf/1=f/2=c/3=t)
@default a 1

rem How long the shutter button will be pressed in continous mode
@param b Continuos shoot (secs)
@default b 10

@param c Threshold (0-255)
@default c 5

@param d Compare Interval (msecs)
@default d 20

@param e Compare Interval (secs)
@default e 0

rem If this value is too small, the camera goes continously shooting after the 1st shot.
rem Experiment with this value to find one fitted to your needs
@param f Begin Delay (secs)
@default f 5

@param g Pix step(speed/accuracy adj)
@default g 5

@param h Columns 
@default h 6

@param i Rows 
@default i 6

rem Frame width in which no MD is performed (in cell units)
@param j Dead frame 
@default j 0

if a<0 then let a=0
if a>3 then let a=3
if c<0 then let c=0
if d<0 then let d-0
if e<0 then let e=0
if g<1 then let g=1
if h<1 then let h=1
if i<1 then let i=1
if j<0 then let j=0

rem Conversions secs to msecs
let b=b*1000
let e=e*1000
let f=f*1000

let d=d+e

rem This is the timeout in msecs. After this period, the motion trap is rearmed.
let T=600000

rem Parameters for the Dead Frame
let J=j+1
let H=h-j
let I=i-j

let t=0

print "press Shutter Button to Stop"

:repete

	md_detect_motion h, i, 1, T, d, c, 1, t, 1, J, J, H, I, 0, g, f

	if a=0 and t>0 then click "shoot_full"
	if a=1 and t>0 then shoot
	if a=2 and t>0 then goto "continuos"
	if a=3 then goto "test"

	let t=0

goto "repete"

:continuos
	let X=get_tick_count
	press "shoot_full"

	:contloop
		let U=get_tick_count
		let V=(U-X)
	if V<b then goto "contloop"

	release "shoot_full"
goto "repete"

:test
	if t>0 then print "Detected cells: ",t else print "No detection in 10 min!"
	let t=0
goto "repete"

end

--201.20.117.111

Advertisement