CHDK Motion Detect Plus Script - Script Writing - CHDK Forum

CHDK Motion Detect Plus Script

  • 31 Replies
  • 26710 Views
CHDK Motion Detect Plus Script
« on: 26 / February / 2012, 22:49:10 »
Advertisements
Update: I updated the links in this first post to the latest version of Motion Detect Plus 0.3.1



I created a CHDK motion detection script called "Motion Detect Plus" to take repetitive shots with motion detection.

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.

Download
You can download the CHDK Motion Detect Plus script here.

Development Blog
I created a page for the Motion Detect Plus script on my blog to track the development of this script.


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


Script Controls
There are several settings that can be set in the CHDK Script preferences:

This upgrade adds a "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).



Script Installation

1. Copy the motionp.lua script to the CHDK scripts folder on your SD memory card.

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.



3. Set the script parameters for Motion Detect Plus and define your motion detection grid size, and masking region settings.

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>

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.




Controlling the 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.


An illustration of motion detection regions.

To enable every block on the grid
Region:0 (No)

This will set the whole screen to be active for motion detection.


In this illustration all of the grid regions are enabled.

To enable just the center block
Region: In
Start Column: 2
End Column: 2
Start Row: 2
End Row: 2


In this illustration the center region is enabled.

To enable the center and center-right blocks choose
Region: In
Start Column: 2
End Column: 3
Start Row: 2
End Row: 2


In this illustration the center and center-right regions are enabled.

To enable a lower corner 2x2 block section choose
Region: In
Start Column: 2
End Column: 3
Start Row: 2
End Row: 3


In this illustration a square region on the lower right is enabled.

To enable a vertical column on the right side choose

Region: In
Start Column: 3
End Column: 3
Start Row: 1
End Row: 3


In this illustration a vertical column region on the right side is enabled.

To enable the top two rows choose
Region: In
Start Column: 1
End Column: 3
Start Row: 1
End Row: 2


In this illustration a double rows region at the top is enabled.

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.
« Last Edit: 16 / September / 2012, 08:21:57 by andrewhazelden »
Canon SD780IS

Re: CHDK Motion Detect Plus Script
« Reply #1 on: 26 / February / 2012, 23:05:08 »
Hi Andrew.  Great post - thanks. 

Download sites seem to go offline on a regular basis so I've also posted your script here :

Code: [Select]
--[[
@title Motion Detect Plus
rem Version 0.1
rem This script adds a repetitive shot mode and is
rem based upon the standard "motion.lua" script

rem Created on Feb 26, 2012
rem by Andrew Hazelden
rem email:  andrewhazelden@gmail.com 
rem blog:   [url=http://www.andrewhazelden.com/]www.andrewhazelden.com/[/url]

@param y Start Delay (min)
@param z Start Delay (sec)

@param g Draw Grid 0=No 1=Yes
@param a Grid Columns
@param b Grid Rows

@param i Region 0=No 1=In 2=Out

@param j Start Column
@param l End Column
@param k Start Row
@param m End Row

rem default delay values
@default y 0
@default z 3


rem default grid values
@default g 1
@default a 3
@default b 3

rem enabled grid cells
@default i 0
@default j 0
@default k 0
@default l 0
@default m 0
--]]


-- 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
q=0         -- the number of shots taken
-- r=get_tick_count()  -- beginning of script timer value

-- Start the delay timer
cls()
print("Waiting:")

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
zones = md_detect_motion( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)

--check if the zones value is nil due to pausing the script
if( zones ~= nil) then
if( zones > 0 ) then
shoot()
q=q+1  -- Increment the shots taken counter
print(q .. " Shots Taken")
end
end

cls()

until ( false )

I'll delete it if you don't want it posted here.

« Last Edit: 26 / February / 2012, 23:25:34 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: CHDK Motion Detect Plus Script
« Reply #2 on: 27 / February / 2012, 09:13:09 »
Hi waterwingz.

Good idea to post the code on the thread.

After I do some compatibility testing with a different Powershot camera model I will post the script on the Wiki.
Canon SD780IS

Re: CHDK Motion Detect Plus Script
« Reply #3 on: 01 / April / 2012, 09:25:11 »
Soory for my english  ;)

Is this script run on a Canon a3300 ? I receive the mine thursday.

Thank you

Re: CHDK Motion Detect Plus Script
« Reply #4 on: 01 / April / 2012, 09:48:44 »
Will this script run on a Canon a3300 ?
Yes
Ported :   A1200    SD940   G10    Powershot N    G16

Re: CHDK Motion Detect Plus Script
« Reply #5 on: 01 / April / 2012, 12:17:54 »
Thank you

Re: CHDK Motion Detect Plus Script
« Reply #6 on: 02 / May / 2012, 05:22:41 »
Sample Motion Detect Plus Images

Here are two bird photos I captured using the Motion Detect Script.


Black-capped Chickadee


American Robin
Canon SD780IS

*

Offline d4005

  • *
  • 28
Re: CHDK Motion Detect Plus Script
« Reply #7 on: 04 / May / 2012, 04:02:34 »
Is there a way to adjust sensitivity in motion detect scripts? For example, in those images in the thread with the birds, I can imagine there being a small amount of "natural" change in successive image samples that might be enough to trigger images. I'm talking about something like those trees in the background or the blades of grass in the foreground swaying in the breeze. I would want to have a threshold parameter where you could set how much change in the image is required to make it trigger. Obviously the birds entering would result in a large amount of change, but blades of grass swaying shouldn't.
 
Also, can these scripts trigger video instead of shooting images? Kind of like a security camera that only records video when something's happening, thereby avoiding video of nothing happening. That would make for "reviewing the security footage" becoming a much less arduous task. I would imagine for the video part, each trigger event (where motion is detected) results in a restart if a 10 second timer. As long as motion keeps happening, that 10 second timer keeps getting restarted. Only once no more motion is being detected would the timer ever get a chance to time out and stop.
In regular use: Canon S100, Canon SX40HS (*CHDK*), Ricoh R8
Still around but unused: Canon S3 iS (*CHDK*), Canon G11 (loaned out), Casio EX-FS10

Re: CHDK Motion Detect Plus Script
« Reply #8 on: 04 / May / 2012, 08:50:56 »
Is there a way to adjust sensitivity in motion detect scripts?
http://chdk.wikia.com/wiki/Motion_Detection

Quote
Also, can these scripts trigger video instead of shooting images?
http://chdk.wikia.com/wiki/UBASIC/Scripts/CanonA640:_Motion_Detect_Video

The search function on the CHDK wiki is actually quite nice.  :blink:
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline d4005

  • *
  • 28
Re: CHDK Motion Detect Plus Script
« Reply #9 on: 05 / May / 2012, 08:17:57 »
The search function on the CHDK wiki is actually quite nice.  :blink:
Thanks. I found all the scripts I needed now :D
In regular use: Canon S100, Canon SX40HS (*CHDK*), Ricoh R8
Still around but unused: Canon S3 iS (*CHDK*), Canon G11 (loaned out), Casio EX-FS10

 

Related Topics


SimplePortal © 2008-2014, SimplePortal