有没有办法获得原始前景对象颜色前景减法?

时间:2018-02-12 17:52:50

标签: opencv background-subtraction

我正在使用BackgroundSubtractorMOG2()来提取视频的前景。我想知道“如何获取图像的原始颜色并将其设置为前景”。我想提取原始颜色而非阈值的对象。

前景提取代码:

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.BackgroundSubtractorMOG2(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);
            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);

原始图片

Original image

我的输出

My output

我想要这个

I want this

0 个答案:

没有答案