MD with self-calibration of threshold. - Script Writing - CHDK Forum

MD with self-calibration of threshold.

  • 4 Replies
  • 2404 Views
MD with self-calibration of threshold.
« on: 19 / December / 2011, 18:31:13 »
Advertisements
One of the wors things in motion detection usage is to find the best threshold. And this is the task that takes me always a lot of time. So I decided to write MD script that calibrates threshold by itself. The whole idea is very simple - place camera where you want, run md_detect_motion function in a loop and increase threshold if motion is detected. Then run md_detect_motion again with threshold you have already found. The script (based on the script from 4pack) :

Code: [Select]
--[[
@title Motion Detect
]]

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
dl=20000    -- learn timeout (mSec)
ds=200000   -- shoot timeout (mSec)
e=200       -- comparison interval (msec) - less than 100 will slow down other CHDK functions
f=0         -- 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)



sleep(1000)

function learn()
    exit=false
    press("shoot_half")
    repeat sleep(50) until get_shooting() == true
    repeat
        print("threshold: "..f)
        zones = md_detect_motion( a, b, c, dl, e, f, g, h, i, j, k, l, m, n, o, p)
        f=f+1  --increase threshold
            if (zones>0) then
                print("too low...")
                end
            if (zones==0) then
                exit=true
                end
               
        until (exit==true)
    end


function md_shoots()
    print("shooting mode")
    print("threshold: "..f)
    repeat
        press("shoot_half")
        repeat sleep(50) until get_shooting() == true
        print("wait for motion")
        print("threshold: "..f)
        zones = md_detect_motion( a, b, c, ds, e, f, g, h, i, j, k, l, m, n, o, p)
            if (zones>0) then
                click("shoot_full")
                sleep(500)
                end
        release("shoot_half")
        until (false)
    end



learn()
release("shoot_half")
md_shoots()
« Last Edit: 20 / December / 2011, 07:34:07 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline Pauls9

  • **
  • 60
  • S3 IS
Re: MD with self-calibration of threshold.
« Reply #1 on: 20 / December / 2011, 05:09:27 »
Nice idea, Outslider. Look forward to testing this.

Re: MD with self-calibration of threshold.
« Reply #2 on: 20 / December / 2011, 05:58:18 »
Very interesting idea! Hopefully will test it out soon :-)

*

Offline Pauls9

  • **
  • 60
  • S3 IS
Re: MD with self-calibration of threshold.
« Reply #3 on: 20 / December / 2011, 06:34:43 »
In md_shoots, should md_detect_motion have parameter ds instead of dl?


Re: MD with self-calibration of threshold.
« Reply #4 on: 20 / December / 2011, 07:33:29 »
In md_shoots, should md_detect_motion have parameter ds instead of dl?

Sure, I've just used Ctrl+C/Ctrl+V. I'll repair previous post.

In a few days I'll post a little bit better script (this one is just a concept).
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics