About the Script[]
The CHDK "Motion Detect Plus" script takes a series of images that are triggered using motion detection. This script was created by Andrew Hazelden
This Motion Detect Plus script adds a repetitive shot feature to the standard CHDK "motion.lua" script. This is useful for creating a motion time-lapse sequence using motion detection to trigger the photos instead of a traditional intervalometer.
The script is called motionp.lua and should work with most cameras that support CHDK.
There is a CHDK forum thread for the Motion Detect Plus Script. There is also a wiki page that covers some of the basics of CHDK Motion Detection
There is also a development blog page for the script where you can post questions and get technical support.
If you want an alternative to the Motion Detect Plus script that works in challenging low light conditions, check out Timofey Gorlov's Lantern Surveillance script development thread on the CHDK Forum.
Download[]
You can download the CHDK Motion Detect Plus script from the project's GitHub page here.
Script Installation[]
Step 1. Copy the motionp.lua script to the CHDK scripts folder on your SD memory card. Step 2. Start CHDK and from the ALT Menu open the Scripting Parameters Menu. In the script window select the Load Script from File... menu option. Then in the "Select Script File" window select the MOTIONP.LUA script and press the Func. Set button to load the script.
Step 3. Set the script parameters for Motion Detect Plus and define your motion detection grid size, and masking region settings.
Step 4. Exit the CHDK Menus and start the Motion Detect Plus script by pressing the shutter button when the text ALT is displayed on screen. If you enabled a Start Delay period the camera will play a short beeping noise to indicate when the start delay period is over.
The grey rectangles on the LCD screen show the active motion detection regions. If motion occurs within one of the selected rectangles a new photo will be taken.
The script will display a counter showing how many photos have been taken since the script was started.
The Motion Detect Plus photo counter looks like this:
3 Shots Taken Motion Detect Plus <ALT>
If the script takes photos nonstop you should adjust the motion threshold parameter in the CHDK Alt Menu Script window. A motion threshold value of 12 seems to work for sunny days and a motion threshold value of 24 works well for cloudy or overcast days.
Step 5. You can stop the script at any point by pressing the shutter button.
Note: There appears to be an issue where the motion detection function doesn't reset for the next photo unless the image review mode is disabled. To disable the image review feature, open the main Canon menu by pressing the menu button on your camera. Scroll down to the option labeled Review and set it to Off. It is also important to set the camera to single shot mode.
Script Controls[]
There are several settings that can be set in the CHDK Script preferences:
The "Motion Threshold" parameter that lets you control the responsiveness of the motion detection feature. If the camera takes photos continuously increase the "Motion Threshold" setting for a reduced motion detection response.
Here are several typical motion threshold levels:
12=Sun 24=Cloudy 36=Dawn/Dusk
You can set a start delay in minutes and seconds. This gives you time to set up your shot before the motion detection is enabled.
The "Number of Shots" variable takes a burst of photos during a motion detection event. This gives you a better chance of catching interesting photos when the motion detection trigger is set off.
The hollow boxes onscreen are the detection grid. You can choose to show or hide the detection grid.
You can set up a detection grid by defining the number of Grid Columns and Grid Rows. Once the grid is defined you can enable specific cells in the detection grid by specifying the Start Column / End Column and Start Row / End Row values.
The region value controls the motion detection masking zones. The region value can then be set to either:
0 = No (disable regions) 1 = In (The area inside the start / end region is the detection zone) 2 = Out (The area outside the start / end region is the detection zone).
Getting Longer Camera Runtime[]
If you want to run your Canon Powershot camera for a longer duration you can purchase an external power module (Like the Canon ACK-DC 10) for your camera that usually comes in the form of a "dummy battery" that goes in the camera and a wall power supply.
Another option is to insert the Canon Powershot video output cord into the camera's AV port. This will disable the LCD screen and save battery power.
Version History[]
Version 0.3.1 - Created Sept 16, 2012
- Changed the zones variable to avoid a naming conflict.
- Added a "Number of Shots" variable that takes a burst of photos during a motion detection event.
Version 0.3 - Created August 20, 2012
- Improved the motion threshold settings.
Version 0.2 -
Created June 25, 2012
- Added a "Motion Threshold" parameter
Version 0.1
- Created on Feb 26, 2012
- Initial Release of Motion Detect Plus
Controlling the CHDK Motion Detection Regions[]
The Motion Detect Plus script allows you to create any type of grid layout you desire in the scripting parameters window. Non-uniform grids layouts are also supported such as a 12x10 layout.
In this demonstration I will present a few of the more common motion detection grid arrangements possible with the Motion Detect Plus script. For this example I am using a 3x3 grid layout with 3 columns, and 3 rows.
To enable every block on the grid
- Region:0 (No)
This will set the whole screen to be active for motion detection.
To enable just the center block
- Region: In
- Start Column: 2
- End Column: 2
- Start Row: 2
- End Row: 2
To enable the center and center-right blocks choose
- Region: In
- Start Column: 2
- End Column: 3
- Start Row: 2
- End Row: 2
To enable a lower corner 2x2 block section choose
- Region: In
- Start Column: 2
- End Column: 3
- Start Row: 2
- End Row: 3
To enable a vertical column on the right side choose
- Region: In
- Start Column: 3
- End Column: 3
- Start Row: 1
- End Row: 3
To enable the top two rows choose
- Region: In
- Start Column: 1
- End Column: 3
- Start Row: 1
- End Row: 2
To enable a vertical column on the left side choose
- Region: In
- Start Column: 1
- End Column: 1
- Start Row: 1
- End Row: 3
Bonus Tip[]
With the region set to 2 (Out) the motion detection script will exclude motion from the active grid box. This allows you to define the unselected areas as the place where motion will be detected.
Source Code - motionp.lua[]
--[[ @title Motion Detect Plus rem Version 0.3.1 - Sept 16, 2012 rem Build 27 rem This file is a CHDK LUA script and should have the name "motionp.lua" rem by Andrew Hazelden rem email: andrewhazelden@gmail.com rem blog: www.andrewhazelden.com rem This script adds a repetitive shot mode and is rem based upon the standard "motion.lua" script rem Make sure to disable Review Mode in the Canon menus. rem Standard sensitivity threshold levels: 12=Sun 24=Cloudy 36=Dawn/Dusk rem If the camera takes photos continuously increase the rem threshold setting level for a reduced motion detection rem responsiveness. rem (a higher motion threshold number = lower responsiveness) rem Version History rem --------------- rem Version 0.3.1 rem Sept 16, 2012 rem Changed the zones variable to avoid a naming conflict. rem Added a "Number of Shots" variable that takes a burst of photos rem during a motion detection event. rem Version 0.3 rem Aug 20, 2012 rem Improved motion threshold settings rem Version 0.2 rem Created June 25, 2012 rem Added a "Motion Threshold" parameter rem Version 0.1 rem Created on Feb 26, 2012 rem Initial Release of Motion Detect Plus @param f Motion Threshold @default f 24 @range f 0 100 rem Script start delay values @param y Start Delay (min) @default y 0 @param z Start Delay (sec) @default z 3 rem default number of shots taken during a motion detection event @param w Number of Shots @default w 1 @param g Draw Grid 0=No 1=Yes @default g 1 @range g 0 1 @param a Grid Columns @param b Grid Rows @default a 3 @default b 3 @param i Region 0=No 1=In 2=Out @default i 0 @range i 0 2 rem Enabled grid cells @param j Start Column @param l End Column @param k Start Row @param m End Row @default j 0 @default k 0 @default l 0 @default m 0 --]] shots=0 -- photos taken counter -- make sure number of shots is positive if w<0 then w=1 end num_shots = w -- make sure the start column is smaller then the end column if j>l then j=l end -- make sure the start row is smaller then the end row if k>m then k=m end --make sure the region number is valid if i>2 then i=0 end -- Motion detection variables -- a=6 -- columns to split picture into -- b=6 -- rows to split picture into c=1 -- measure mode (Y,U,V R,G,B) U=0, Y=1, V=2, R=3, G=4, B=5 d=300000 -- timeout (mSec) e=200 -- comparison interval (msec) - less than 100 will slow down other CHDK functions -- f=5 -- threshold (difference in cell to trigger detection) -- g=1 -- draw grid (0=no, 1=yes) h=0 -- not used in LUA - in uBasic is the variable that gets loaded with the number of cells with motion detected -- i=0 -- region masking mode: 0=no regions, 1=include, 2=exclude -- j=0 -- first column -- k=0 -- first row -- l=0 -- last column -- m=0 -- last row n=0 -- optional parameters (1=shoot immediate) o=2 -- pixel step p=0 -- triggering delay (msec) -- Other variables -- r=get_tick_count() -- beginning of script timer value -- Start the delay timer cls() print("Typical Motion Threshold") print("12=Sun 24=Cloudy 36=Dawn") if y>0 then print( y .. " min " .. z .. " sec to start...") else print( z .. " sec to start...") end sleep( (z*1000)+(y*1000*60) ) -- Start the motion detection loop cls() print("Starting Motion Detection") play_sound(3) --plays the self timer sound effect repeat md_zone = md_detect_motion( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) cls() --check if the md_zone value is nil due to pausing the script if( md_zone ~= nil) then if( md_zone > 0 ) then --shoot multiple photos in a burst using (Number of Shots) if(num_shots>0) then burst = num_shots repeat shoot() cls() shots=shots+1 -- Increment the shots taken counter burst=burst-1 -- update the photo burst counter until ( burst==0 ) print(shots .. " Shots Taken" ) sleep(250) end end end until ( false )