Ask Your Question
0

Image subtraction weird effect [closed]

asked 2017-10-08 13:45:23 -0600

fatben gravatar image

updated 2017-10-09 01:56:00 -0600

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:

image description

===================== UPDATE =====================

Here are currentFrame and background:

image description

image description

How error like this could possibly be fixed?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2017-10-11 01:46:08.918122

Comments

Which error? May be you can post currentFrame, background and foregrounds images

LBerger gravatar imageLBerger ( 2017-10-08 14:23:33 -0600 )edit
1

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.

Tetragramm gravatar imageTetragramm ( 2017-10-08 15:15:32 -0600 )edit

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.

Tetragramm gravatar imageTetragramm ( 2017-10-08 17:42:23 -0600 )edit

Yes, it was a typo, I updated the code in the question. But it means that wasn't the problem.

fatben gravatar imagefatben ( 2017-10-09 02:00:24 -0600 )edit

Using this code (opencv 3.3-dev vs2015):

Mat foreground,background;
foreground = imread("15075018148975703.png", IMREAD_COLOR);
background = imread("15075018217250966.jpg", IMREAD_COLOR);
cv::absdiff(foreground, background, foreground);
cv::threshold(foreground, foreground, 25, 255, cv::THRESH_BINARY);
imshow("r", foreground);
waitKey();

I got this image : image description

LBerger gravatar imageLBerger ( 2017-10-09 02:29:38 -0600 )edit

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.

John_OpenCVdev gravatar imageJohn_OpenCVdev ( 2017-10-09 03:06:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-10-10 17:29:13 -0600

fatben gravatar image

updated 2017-10-10 17:30:08 -0600

I solved the issue. It seems that it was a problem with conversion between Qt QImage and OpenCV Mat. So the issues were not really OpenCV related... But thank you for all your responses.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-08 13:45:23 -0600

Seen: 463 times

Last updated: Oct 09 '17