node-opencv
node-opencv copied to clipboard
Error using BackgroundSubtractor
Hi, I'm trying to use the BackgroundSubtractor for motion detection purposes. I have the following configuration:
When I try to excute the following code NodeJS crashes with "segmentation fault (core dumped)"
var backgroundSub = new cv.BackgroundSubtractor();
...
function(cb) {
// 2. Read picture (takes between 60 and 100 ms)
cv.readImage( lastPng, function(err, im) {
cb(err,im);
});
},
function(im, cb) {
// 3. update Background and foreground objects
if (backgroundSub) {
backgroundSub.applyMOG(im, function (err, foregroundImg) {
cb(err, foregroundImg);
});
}
},
Investigating the problem I've used this module (https://github.com/ddopson/node-segfault-handler) and I realized that the error is exactly in applyMOG call
PID 180 received SIGSEGV for address: 0x0 /app/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x1514)[0x7fa8de0fd514] /lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0)[0x7fa8f07b8cb0] /app/plugins/webflight-coptermotion/node_modules/opencv/build/opencv/v3.2.0/Release/node-v11-linux-x64/opencv.node(_ZN24BackgroundSubtractorWrap8ApplyMOGERKN2v89ArgumentsE+0x607)[0x7fa8de336d77]
Am I doing something wrong? Could you help me understanding what's going on?
Can reproduce this crasher on NodeJs 4.6. Also using OpenCV 3.x, but have adapted the code to be compatible.
I looked into this a bit. It seems that cv::createBackgroundSubtractorMOG() return 0 during ::New(), so trying to call ->apply() on it later crashes.
I have a nasty suspicion that this happens because the background subtractors were moved out to opencv_contrib in OpenCV 3, https://github.com/opencv/opencv_contrib/tree/master/modules/bgsegm They should really throw an error with explanatory message, not return a null object...