Ask Your Question
0

How to remove detected shadows from foreground image using Background Subtraction MOG2

asked 2013-03-19 11:27:22 -0600

Agen gravatar image

Im using in built function shadow detection fro Background subtraction MOG2, i want to remove the shadow detected from the foreground image so i can do i blob dectection....any help will be most apreciated thanks in advance

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-03-21 18:29:24 -0600

mhaghighat gravatar image

Try this:

cv::Ptr<cv::BackgroundSubtractorMOG2> pMOG2 = cv::createBackgroundSubtractorMOG2();
cv::Mat fgMask;  // Foreground mask

// Update the background model and get the foreground mask
pMOG2->apply(frame, fgMask);

// Blur the foreground mask to reduce the effect of noise and false positives
cv::blur(fgMask, fgMask, cv::Size(15, 15), cv::Point(-1, -1));

// Remove the shadow parts and the noise
cv::threshold(fgMask, fgMask, 128, 255, cv::THRESH_BINARY);
edit flag offensive delete link more

Comments

Although your answer is correct, reviving topics from 2013 seems rather useless in a so fastly changing communtity ...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-03-22 05:46:22 -0600 )edit
1

answered 2013-03-24 05:36:40 -0600

Agen gravatar image

sry still noob in openCV actually its simple the function shadow detection(MOG2) assign the shadow detected to value 127, so to remove the shadow just threshold the foreground image with value 127 as minimum. hopes any1 who has this problem........

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-03-19 11:27:22 -0600

Seen: 8,277 times

Last updated: Mar 21 '17