This is looking really good. I modified your code below so I could run some tests. What it does is run a loop that first records the actual cell levels for the original scene. It then does a standard wait for motion to happen. Once motion is detected, it checks the current cell levels until they are the same as the original scene. This test doesn't trigger the camera but only displays a message.
Function fill_md_array(name) records the scene levels and function compare_scenes(original, current, sensitivity) does the scene comparison. The sensitivity value allows for the fact that the levels will probably never match exactly.
This works fine on my desk - now for a real life test.
Dave
--[[
@title Motion Tester
@param a Columns
@default a 3
@param b Rows
@default b 2
@param f Trigger Threshold
@default f 10
@param d Time out (s)
@default d 20
@param s Sensitivity
@default s 5
]]
c=1 -- measure mode (Y,U,V R,G,B) U=0, Y=1, V=2, R=3, G=4, B=5
g=3 -- draw grid (0=no, 1=yes)
h=0 -- not used in LUA
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=1 -- pixel step
p=0 -- Trigger Delay (mSec)
function fill_md_array(name)
for row = 1, b do
for col = 1, a do
name[(row - 1) * a + col] = md_get_cell_abs(col,row)
end -- for col
end -- for row
end -- fill_array()
function compare_scenes(original, current, sensitivity)
for row = 1, b do
for col = 1, a do
if math.abs(original[(row - 1) * a + col] - current[(row - 1) * a + col]) > sensitivity then
return false
end -- if
end -- for col
end -- for row
return true
end -- compare_scenes()
if ( get_mode() == false ) then
set_record(1)
while ( get_mode() == false ) do
sleep(100)
end
end
sleep(2000)
md_original = {}
md_current = {}
repeat
zones = md_detect_motion( a, b, c, 200, 100, f, g, h, i, j, k, l, m, n, o, p)
fill_md_array(md_original)
print("Original snapped.")
zones = md_detect_motion( a, b, c, d*1000, 100, f, g, h, i, j, k, l, m, n, o, p)
if zones > 0 then
print("Event started.")
repeat
zones = md_detect_motion( a, b, c, 200, 100, f, g, h, i, j, k, l, m, n, o, p)
fill_md_array(md_current)
until compare_scenes(md_original, md_current, s) == true
print("Event over.")
else
print("Timed out.")
end
until false