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:
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);
}
You haven't enabled shadow detection when initializing bgMOG2:
cv::BackgroundSubtractorMOG2 bgMOG2 = cv::BackgroundSubtractorMOG2(3000, 16.0, **false**);
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.
@berak There is an answer in this question but I cannot see it
@LBerger, spam, removed (but from the moderation page, not from here. small glitch in forum software).