Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is there a way get original foreground object colors foreground substarction?

Hello guys.I am using BackgroundSubtractorMOG2() to extract foreground of video.I am wondering about "how to get original colors of the image and set it foreground"

Foreground Extraction 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.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

Is there a way get original foreground object colors foreground substarction?

Hello guys.I am using BackgroundSubtractorMOG2() to extract foreground of video.I am wondering about "how to get original colors of the image and set it foreground"foreground".I can extract objects with original colors not threshold.

Foreground Extraction 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.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

Is there a way get original foreground object colors foreground substarction?

Hello guys.I am using BackgroundSubtractorMOG2() to extract foreground of video.I am wondering about "how to get original colors of the image and set it foreground".I can extract objects with original colors not threshold.

Foreground Extraction 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.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 imageOriginal image

Original image

My output

My output

I want this

I want this

Is there a way get original foreground object colors foreground substarction?

Hello guys.I am using BackgroundSubtractorMOG2() to extract foreground of video.I am wondering about "how to get original colors of the image and set it foreground".I can extract objects with original colors not threshold.

Foreground Extraction 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.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

Original image

My output

My output

I want this

I want this

click to hide/show revision 5
retagged

updated 2018-10-24 05:48:52 -0600

berak gravatar image

Is there a way get original foreground object colors foreground substarction?

Hello guys.I am using BackgroundSubtractorMOG2() to extract foreground of video.I am wondering about "how to get original colors of the image and set it foreground".I can extract objects with original colors not threshold.

Foreground Extraction 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.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

Original image

My output

My output

I want this

I want this

Is there a way get original foreground object colors foreground substarction?

Hello guys.I am using BackgroundSubtractorMOG2() to extract foreground of video.I am wondering about "how to get original colors of the image and set it foreground".I can extract objects with original colors not threshold.

Foreground Extraction 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.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

Original image

My output

My output

I want this

I want this