Ask Your Question

Revision history [back]

You might be having memory reference problems, try to clone the frame into its own memory space.

Try this:

cv::Mat frame_clone;
frame.copyTo(frame_clone)
// process the image to obtain a mask image.
pMOG->operator()(frame_clone, fgMaskMOG);
click to hide/show revision 2
I gave an alternative solution

You might be having memory reference problems, try to clone the frame into its own memory space.

Try this:

cv::Mat frame_clone;
frame.copyTo(frame_clone)
// process the image to obtain a mask image.
pMOG->operator()(frame_clone, fgMaskMOG);

[EDIT]

I tried your code with a video taken with a crappy webcam and the live feed of the same webcam. I get the same result: Good with video, bad with live feed.

But I observed something: the images on the recorded video are far more stable (do not change much from frame to frame) than the ones from the live feed (there is a lot of noise from frame to frame).

I think that by requesting the live stream of the webcam you get a highly compressed low quality image, that is causing the MOG algorithm to give you crappy results with the default parameters.

Possible solutions: find a way to increase the quality of the live feed or tweak the parameters of the MOG to deal with the frame-to-frame variability of the live feed.

You might be having memory reference problems, try to clone the frame into its own memory space.

Try this:

cv::Mat frame_clone;
frame.copyTo(frame_clone)
// process the image to obtain a mask image.
pMOG->operator()(frame_clone, fgMaskMOG);

[EDIT]

I tried your code with a video taken with a crappy webcam and the live feed of the same webcam. I get the same result: result as you: Good with video, bad with live feed.

But I observed something: the images on the recorded video are far more stable (do not change much from frame to frame) than the ones from the live feed (there is a lot of noise from frame to frame).

I think that by requesting the live stream of the webcam you get a highly compressed low quality image, that is causing the MOG algorithm to give you crappy results with the default parameters.

Possible solutions: find a way to increase the quality of the live feed or tweak the parameters of the MOG to deal with the frame-to-frame variability of the live feed.