Ask Your Question
2

How to remove detected shadows from foreground image in the light projector

asked 2015-09-04 10:56:13 -0600

updated 2015-09-04 21:04:10 -0600

Hi guys, i applying background subtraction MOG2 to detect hand in the beam light of projector. I already done this much, but i can remove shadow in foreground image. I already changes the parameter threshold to 127 to remove shadow and changes bShadowDetection in MOG2. Please help me to solve it, give me suggestion or anythings.

This is sample picture that i take:

image description

int main(int argc, char *argv[]) {
cv::Mat src, srcdown, bg, frMOG2, erframe, dlframe;
namedWindow("windows 1", CV_WINDOW_AUTOSIZE);
cv::VideoCapture cap(0);
cv::BackgroundSubtractorMOG2 bgMOG2 = cv::BackgroundSubtractorMOG2(3000, 16.0, true);
if (!cap.isOpened()){ printf("--(!)no frame from camera\n"); return -1; };
for (;;) {
    cap >> src;
    bgMOG2.operator()(src, frMOG2);
    cv::threshold(frMOG2, thrframe, 127, 255, cv::THRESH_BINARY);
    cv::dilate(thrframe, dlframe, cv::Mat());
    cv::erode(dlframe, erframe, cv::Mat());
    std::vector<std::vector<cv::Point>>contours;
    cv::findContours(erframe, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
    for (int i = 0; i < contours.size(); i++) {
        if (contourArea(contours[i]) >= 500) {
            vector<vector<Point> > tcontours;
            tcontours.push_back(contours[i]);
            cv::drawContours(srcdown, tcontours, -1, cv::Scalar(0, 0, 255), 2);
        }
    }
    cv::imshow("windows 1", srcdown);
    if (waitKey(30) >= 0) break;
}
return(0);
}
edit retag flag offensive close merge delete

Comments

You haven't enabled shadow detection when initializing bgMOG2: cv::BackgroundSubtractorMOG2 bgMOG2 = cv::BackgroundSubtractorMOG2(3000, 16.0, **false**);

LorenaGdL gravatar imageLorenaGdL ( 2015-09-04 12:12:08 -0600 )edit

oh... i see, thank you. I already try to changes that parameter. But when i changes that parameter the result still same. I think the shadows considered as moving hands as well. I thinking to you use color after MoG2, but it result just silhouette in black and white.

sevli gravatar imagesevli ( 2015-09-04 21:01:23 -0600 )edit

@berak There is an answer in this question but I cannot see it

LBerger gravatar imageLBerger ( 2015-09-05 03:20:41 -0600 )edit

@LBerger, spam, removed (but from the moderation page, not from here. small glitch in forum software).

berak gravatar imageberak ( 2015-09-05 03:23:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-09-06 21:26:48 -0600

I am thinking to use color detection after background subtraction. Is it possible to use this method after background subtraction MOG2 applied?

edit flag offensive delete link more

Comments

I don't know if it is possible to color detection. But if it's not good you can see your problem as an homomorphic filtering

LBerger gravatar imageLBerger ( 2015-09-07 01:32:16 -0600 )edit

Is it possible to provide a link to one short video? I'm pretty sure MOG2 can deal with shadows, it usually does well

LorenaGdL gravatar imageLorenaGdL ( 2015-09-07 05:36:35 -0600 )edit

I try to record video via opencv but i can't record the contour along with the video, so i try record with desktop recorder. This is result the video I already set "true" for bShadowDetection and there is no changes at all. I try to my lecturer and he said try to remove it with color detection. I just don't get it how to use that. Please help me guys.

sevli gravatar imagesevli ( 2015-09-08 09:11:25 -0600 )edit

Well, I was asking for the input video to try myself... Anyway, if you want to try color detection, just apply some kind of thresholding operation to eliminate very dark pixels in your moving object

LorenaGdL gravatar imageLorenaGdL ( 2015-09-08 09:35:56 -0600 )edit

Thank you @LBerger and @LorenaGdL for the suggestion. btw it's my bad, i thought you ask for the result lol... I included the original video this time. Yes, my lecturer said just like you. But i don't know the parameter of dark pixels in the video, can you give me hint to catch only that pixels.

sevli gravatar imagesevli ( 2015-09-08 20:47:45 -0600 )edit

i don't know how to select certain area in original frame in size of foreground image. Anybody please suggest me a sample code.

sevli gravatar imagesevli ( 2015-09-12 08:02:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-04 10:56:13 -0600

Seen: 4,842 times

Last updated: Sep 06 '15