Ask Your Question

Revision history [back]

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

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, false);
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);}

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

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, false);
true);
if (!cap.isOpened()){ printf("--(!)no frame from camera\n"); return -1; };
for (;;) {
    cap >> src;
    bgMOG2.operator()(src, frMOG2); 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);}
return(0);
}