Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mods
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
mods
Commits
d957a99e
Commit
d957a99e
authored
7 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
first change detection
parent
acca33cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/image/motion detect
+18
-8
18 additions, 8 deletions
modules/image/motion detect
with
18 additions
and
8 deletions
modules/image/motion detect
+
18
−
8
View file @
d957a99e
...
...
@@ -148,7 +148,7 @@ function timeout() {
setTimeout(timeout,parseFloat(mod.time.value)*1000)
}
function compare_images() {
mod.change.nodeValue = Date.now()
//
mod.change.nodeValue = Date.now()
var blob = new Blob(['('+worker.toString()+'())'])
var url = window.URL.createObjectURL(blob)
var webworker = new Worker(url)
...
...
@@ -156,12 +156,7 @@ function compare_images() {
window.URL.revokeObjectURL(url)
var h = mod.img.height
var w = mod.img.width
/*
var buf = new Uint8ClampedArray(evt.data.buffer)
var imgdata = new ImageData(buf,w,h)
var ctx = mod.img.getContext("2d")
ctx.putImageData(imgdata,0,0)
*/
mod.change.nodeValue = 'relative change: '+evt.data.change.toFixed(3)
if (w > h) {
var x0 = 0
var y0 = mod.canvas.height*.5*(1-h/w)
...
...
@@ -198,7 +193,22 @@ function worker() {
var t = evt.data.threshold
var buf = new Uint8ClampedArray(evt.data.buffer)
var lastbuf = new Uint8ClampedArray(evt.data.lastbuffer)
self.postMessage({buffer:buf.buffer})
var change = 0
for (var row = 0; row < h; ++row) {
for (var col = 0; col < w; ++col) {
r = buf[(h-1-row)*w*4+col*4+0]
g = buf[(h-1-row)*w*4+col*4+1]
b = buf[(h-1-row)*w*4+col*4+2]
rl = lastbuf[(h-1-row)*w*4+col*4+0]
gl = lastbuf[(h-1-row)*w*4+col*4+1]
bl = lastbuf[(h-1-row)*w*4+col*4+2]
change += (Math.abs(r-rl)/255
+Math.abs(g-gl)/255
+Math.abs(b-bl)/255)/3
}
}
change = change/(w*h)
self.postMessage({change:change})
})
}
// return values
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment