Hybrid Motion Detect/Time Lapse script? - Script Writing - CHDK Forum

Hybrid Motion Detect/Time Lapse script?

  • 22 Replies
  • 4677 Views
Hybrid Motion Detect/Time Lapse script?
« on: 28 / December / 2012, 01:47:16 »
Advertisements
I want to do long term time lapses, perhaps 2-4 days at a time (maybe less, or more)... my goals is to make a hybrid time lapse and motion detect script. For example, if no motion detected in 5m, then take a picture and start over.

http://chdk.wikia.com/wiki/UBASIC/Scripts:_Multipurpose_Motion_Detection

This script ^ seems to have potential, as it can reset itself after a predetermined amount of time. I'm just not sure how to command it to shoot a picture at the same time that it resets. Can someone point me in the right direction? Thanks tons :)

Re: Hybrid Motion Detect/Time Lapse script?
« Reply #1 on: 28 / December / 2012, 08:56:16 »
Modify the code down near the bottom like this :

Code: [Select]

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

Ported :   A1200    SD940   G10    Powershot N    G16

Re: Hybrid Motion Detect/Time Lapse script?
« Reply #2 on: 28 / December / 2012, 11:26:57 »
Ah, that nesting wasn't obvious to me in the original script. Thanks for breaking that down. Now I see where I should have put it. I sure appreciate the help! I'll give this a shot (or two, or a hundred)

Re: Hybrid Motion Detect/Time Lapse script?
« Reply #3 on: 28 / December / 2012, 12:05:55 »
Ah, that nesting wasn't obvious to me in the original script. Thanks for breaking that down. Now I see where I should have put it. I sure appreciate the help! I'll give this a shot (or two, or a hundred)

This will probably work better for you then - I removed the "testing" mode  :

Code: [Select]
@title Motion Detection
rem Original author: MLuna - based om MX3 sample script

rem Shot without auto-focus/with auto-focus/continuously (need to put in continuous mode manually)
@param a Shot (0=nf/1=f/2=c)
@default a 1

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

rem This value determines how much change in picture brighness will trigger a shot
rem Experiment with this value to find one fitted to your needs
@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 continuously 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>2 then let a=2
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

print "press Shutter Button to Stop"

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

if t>0 then
print "Detected cells: ",t
if a=0 then click "shoot_full"
if a=1 then shoot
if a=2 then goto "continuos"
else
print "No detection in 10 min!"
shoot
endif

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"
let t=0
goto "repete"

end
Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline lapser

  • *****
  • 1093
Re: Hybrid Motion Detect/Time Lapse script?
« Reply #4 on: 28 / December / 2012, 12:15:45 »
Ah, that nesting wasn't obvious to me in the original script. Thanks for breaking that down. Now I see where I should have put it. I sure appreciate the help! I'll give this a shot (or two, or a hundred)
I couldn't figure it out last night either. Waterwingz is a great resource on this board. I really appreciate all the help he's given me. He's been a real "shot" in the arm when I don't understand something.
http://idioms.thefreedictionary.com/shot+in+the+arm (for the Deutschlanders)
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: Hybrid Motion Detect/Time Lapse script?
« Reply #5 on: 28 / December / 2012, 12:23:38 »
Ah, that nesting wasn't obvious to me in the original script. Thanks for breaking that down. Now I see where I should have put it. I sure appreciate the help! I'll give this a shot (or two, or a hundred)
I couldn't figure it out last night either. Waterwingz is a great resource on this board. I really appreciate all the help he's given me. He's been a real "shot" in the arm when I don't understand something.
http://idioms.thefreedictionary.com/shot+in+the+arm (for the Deutschlanders)
I like the third definition the best ....
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Hybrid Motion Detect/Time Lapse script?
« Reply #6 on: 28 / December / 2012, 12:44:29 »
:D

So, I modified the script, but all it does is flash the green grid on the screen over and over. This was the same problem that I had when I tried to modify it myself last night. It works fine before modification. Ideas?

WAIT- just saw your modified script- trying that now...

Modified script appears to be working- Thank you! I am testing it now and will post with any questions I have.
« Last Edit: 28 / December / 2012, 12:55:15 by geocrasher »

Re: Hybrid Motion Detect/Time Lapse script?
« Reply #7 on: 28 / December / 2012, 12:58:01 »
:D

So, I modified the script, but all it does is flash the green grid on the screen over and over. This was the same problem that I had when I tried to modify it myself last night. It works fine before modification. Ideas?

WAIT- just saw your modified script- trying that now...

Modified script appears to be working- Thank you! I am testing it now and will post with any questions I have.
The parameters specified as "c" and "f" are critical to good motion detection.  Unfortunately the optimal values are very dependent on ambient lighting conditions.  You need to tune them for your shooting condition.

I've been playing with a new MD detect algorithm that includes automatic gain control.  Nothing to publish yet but its looking promising.

Ported :   A1200    SD940   G10    Powershot N    G16


Re: Hybrid Motion Detect/Time Lapse script?
« Reply #8 on: 28 / December / 2012, 22:23:14 »
Thank you so much for posting the fixed script. It works very nicely. I added a variable for the Intervalometer portion of the script- it defaults at 300sec (5m) but can be set anywhere really. I could clean it up and add min/sec but all seconds is fine for now.

I added "k" as a parameter and then changed

let T=600000

to

let T=k*1000

and that seems to have worked nicely. I did some tests with it today and it came out exactly as I wanted. Very nice! I look forward to messing with it some more and learning how to program the camera, and in uBasic. Although, it seems that some features are only available in Lua, so maybe I'll end up learning both. My next step is to buy a camera that can handle FAT32 so I can do 8 and 16GB cards for the really long term stuff, but I should be able to use the 2GB card I have quite effectively for now.


Re: Hybrid Motion Detect/Time Lapse script?
« Reply #9 on: 28 / December / 2012, 23:00:35 »
My next step is to buy a camera that can handle FAT32 so I can do 8 and 16GB cards for the really long term stuff, but I should be able to use the 2GB card I have quite effectively for now.
The dual partition scheme CHDK uses will let you handle 8G & 16G cards just fine with almost all existing cameras.  Details on setting that up are here :  http://chdk.wikia.com/wiki/Prepare_your_SD_card#For_Cameras_Released_Before_2011_:
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics