Image subtraction weird effect [closed]
Hi,
I have a problem subtracting background of the scene (image file taken from a video) from the next frames of the video. I provide code snippet:
cv::absdiff(currentFrame, background, foreground);
cv::threshold(foreground, foreground, 25, 255, cv::THRESH_BINARY);
I tried adjusting some parameters but the result is always something like this:
===================== UPDATE =====================
Here are currentFrame and background:
How error like this could possibly be fixed?
Which error? May be you can post currentFrame, background and foregrounds images
That... might be correct. It looks like that's a transition between two scenes in a video. Look at the grid on the floor. And if each channel is being thresholded separately, that would explain the colors, which appear to be combinations of 0 and 255 values in each of the three channels.
Ok, things to check.
You're doing absdiff into the Mat foregrounds, and the threshold on a Mat called foreground. Is that a typo or a bug?
Secondly, I diff those images and threshold and I get something much more reasonable, without all those vertical lines.
Yes, it was a typo, I updated the code in the question. But it means that wasn't the problem.
Using this code (opencv 3.3-dev vs2015):
I got this image :
Things to check: Check whether you load the images correctly. Try loading both as Grayscale images and check once. As pointed by @Tetragramm there looks a transition in the two scenes.