bgsubtrator - add manual GC else node kills my pi. Add delete of images once consumed.

This commit is contained in:
Simon Hailes 2017-11-11 12:51:00 +00:00
parent 4f58515187
commit 1e8587fe9a

View File

@ -3,6 +3,9 @@ var path = require('path'),
var bg = null; var bg = null;
require("v8").setFlagsFromString('--expose_gc');
var gc = require("vm").runInNewContext('gc');
var do_sync = function(done){ var do_sync = function(done){
// When opening a file, the full path must be passed to opencv // When opening a file, the full path must be passed to opencv
@ -14,6 +17,7 @@ var do_sync = function(done){
vid.read(function(err, m2){ vid.read(function(err, m2){
if (err) throw err; if (err) throw err;
var mat = bg.apply(m2); var mat = bg.apply(m2);
delete m2;
// mat is a monochrome img where moving objects are white // mat is a monochrome img where moving objects are white
if (x++<100){ if (x++<100){
//console.log("iter "+x); //console.log("iter "+x);
@ -21,6 +25,7 @@ var do_sync = function(done){
} else { } else {
delete vid; delete vid;
console.log("bg sync done"); console.log("bg sync done");
gc();
if (undefined !== done) if (undefined !== done)
done(); done();
} }
@ -40,6 +45,7 @@ var do_async = function(done){
vid.read(function(err, m2){ vid.read(function(err, m2){
if (err) throw err; if (err) throw err;
bg.apply(m2, function(err, mat){ bg.apply(m2, function(err, mat){
delete mat;
if (err) throw err; if (err) throw err;
// mat is a monochrome img where moving objects are white // mat is a monochrome img where moving objects are white
if (x++<100){ if (x++<100){
@ -48,6 +54,7 @@ var do_async = function(done){
} else { } else {
console.log("bg async done"); console.log("bg async done");
delete vid; delete vid;
gc();
if (undefined !== done) if (undefined !== done)
done(); done();
} }
@ -70,9 +77,8 @@ var do_gmg = function( done ){
console.log("doing GMG"); console.log("doing GMG");
bg = cv.BackgroundSubtractor.createGMG(); bg = cv.BackgroundSubtractor.createGMG();
do_sync( function(){ do_sync( function(){
console.log("not doing GMG Async - crashes my pi"); //console.log("not doing GMG Async - crashes my pi");
//do_async(done); do_async(done);
done();
}); });
} }