Skip to content
Snippets Groups Projects
Commit cb6ea13a authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

motion detection working?

parent ae973490
Branches
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ var name = 'motion detect' ...@@ -27,6 +27,7 @@ var name = 'motion detect'
var init = function() { var init = function() {
mod.threshold.value = 0.1 mod.threshold.value = 0.1
mod.time.value = 15 mod.time.value = 15
mod.dpi = 100
timeout() timeout()
} }
// //
...@@ -51,14 +52,11 @@ var inputs = { ...@@ -51,14 +52,11 @@ var inputs = {
var outputs = { var outputs = {
image:{type:'RGBA', image:{type:'RGBA',
event:function(){ event:function(){
var ctx = mod.img.getContext("2d")
var img = ctx.getImageData(0,0,mod.img.width,mod.img.height)
mods.output(mod,'image',img)}}, mods.output(mod,'image',img)}},
imageInfo:{type:'object', imageInfo:{type:'object',
event:function(){ event:function(obj){
var obj = {}
obj.name = mod.name.nodeValue
obj.dpi = parseFloat(mod.dpitext.value)
obj.width = mod.img.width
obj.height = mod.img.height
mods.output(mod,'imageInfo',obj)}}, mods.output(mod,'imageInfo',obj)}},
trigger:{type:'event', trigger:{type:'event',
event:function(){ event:function(){
...@@ -154,9 +152,26 @@ function compare_images() { ...@@ -154,9 +152,26 @@ function compare_images() {
var webworker = new Worker(url) var webworker = new Worker(url)
webworker.addEventListener('message',function(evt) { webworker.addEventListener('message',function(evt) {
window.URL.revokeObjectURL(url) window.URL.revokeObjectURL(url)
mod.change.nodeValue = 'relative change: '+evt.data.change.toFixed(3)
if (evt.data.change > parseFloat(mod.threshold.value)) {
var obj = {}
var date = new Date()
var year = date.getFullYear()
var month = ('0'+(1+parseInt(date.getMonth()))).slice(-2)
var day = ('0'+date.getDate()).slice(-2)
var hour = ('0'+date.getHours()).slice(-2)
var minute = ('0'+date.getMinutes()).slice(-2)
var second = ('0'+date.getSeconds()).slice(-2)
var name = year+'-'+month+'-'+day+'-'+hour+'-'+minute+'-'+second+'.png'
obj.name = name
obj.dpi = mod.dpi
obj.width = mod.img.width
obj.height = mod.img.height
outputs.imageInfo.event(obj)
outputs.image.event()
}
var h = mod.img.height var h = mod.img.height
var w = mod.img.width var w = mod.img.width
mod.change.nodeValue = 'relative change: '+evt.data.change.toFixed(3)
if (w > h) { if (w > h) {
var x0 = 0 var x0 = 0
var y0 = mod.canvas.height*.5*(1-h/w) var y0 = mod.canvas.height*.5*(1-h/w)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment