Ask Your Question
0

cv.BackgroundSubtractorMOG() doesn't work on opencv.js

asked 2018-02-14 14:04:57 -0600

generator gravatar image

updated 2018-02-14 14:11:03 -0600

Hello guys.I want to use BackgroundSubtractorMOG() on my opencv .js project but cv.BackgroundSubtractorMOG() doesn't work on my javascript code.I get following error:

BindingError: BackgroundSubtractor has no accessible constructor

My Code:

let video = document.getElementById('videoInput');
let cap = new cv.VideoCapture(video);

let frame = new cv.Mat(video.height, video.width, cv.CV_8UC4);
let fgmask = new cv.Mat(video.height, video.width, cv.CV_8UC1);
let fgbg = new cv.BackgroundSubtractorMOG(500, 16, true);

const FPS = 30;
function processVideo() {
    try {
        if (!streaming) {
            // clean and stop.
            frame.delete(); fgmask.delete(); fgbg.delete();
            return;
        }
        let begin = Date.now();
        // start processing.
        cap.read(frame);
        fgbg.apply(frame, fgmask);

        frame.copyTo(fgmask, fgmask)



        let M = cv.Mat.eye(3, 3, cv.CV_32FC1);
        let anchor = new cv.Point(-1, -1);
        cv.filter2D(fgmask, fgmask, cv.CV_8U, M, anchor, 0, cv.BORDER_DEFAULT);


        cv.imshow('canvasOutput', fgmask);
        // schedule the next one.
        let delay = 1000/FPS - (Date.now() - begin);
        setTimeout(processVideo, delay);
    } catch (err) {
        utils.printError(err);
    }
};

// schedule the first one.
setTimeout(processVideo, 0);
edit retag flag offensive close merge delete

Comments

new cv.BackgroundSubtractorMOG2 does not match your question title

berak gravatar imageberak ( 2018-02-14 14:07:48 -0600 )edit

aah sorry.I forget to edit my html.Thank you but cv.BackgroundSubtractorMOG() really doesn't work.(sorry for my bad english)

generator gravatar imagegenerator ( 2018-02-14 14:10:50 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-14 14:15:07 -0600

berak gravatar image

updated 2018-02-14 14:15:24 -0600

not sure about the js bindings, but cv.BackgroundSubtractorMOG is from opencv_contrib , unlikely, that there are js bindings for that as of now.

(in other words: you probably can only use the MOG2 version)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-02-14 14:04:57 -0600

Seen: 483 times

Last updated: Feb 14 '18