From: Ilya Lysenkov Date: Fri, 3 Jun 2011 14:13:03 +0000 (+0000) Subject: Added displaying of the mean background image in the bgfg_segm sample (ticket #317). X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~7129 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d4afe81e06eac7d36fe26362dd4e3feee1e7e9a;p=platform%2Fupstream%2Fopencv.git Added displaying of the mean background image in the bgfg_segm sample (ticket #317). --- diff --git a/samples/cpp/bgfg_segm.cpp b/samples/cpp/bgfg_segm.cpp index 2beb409..e6464fc 100644 --- a/samples/cpp/bgfg_segm.cpp +++ b/samples/cpp/bgfg_segm.cpp @@ -31,12 +31,14 @@ int main(int argc, char** argv) return -1; } - namedWindow("BG", 1); - namedWindow("FG", 1); + namedWindow("image", CV_WINDOW_NORMAL); + namedWindow("foreground mask", CV_WINDOW_NORMAL); + namedWindow("foreground image", CV_WINDOW_NORMAL); + namedWindow("mean background image", CV_WINDOW_NORMAL); BackgroundSubtractorMOG2 bg_model; - Mat img, fgmask; - + Mat img, fgmask, fgimg; + for(;;) { cap >> img; @@ -44,10 +46,24 @@ int main(int argc, char** argv) if( img.empty() ) break; + if( fgimg.empty() ) + fgimg.create(img.size(), img.type()); + + //update the model bg_model(img, fgmask, update_bg_model ? -1 : 0); - + + fgimg = Scalar::all(0); + img.copyTo(fgimg, fgmask); + + Mat bgimg; + bg_model.getBackgroundImage(bgimg); + imshow("image", img); imshow("foreground mask", fgmask); + imshow("foreground image", fgimg); + if(!bgimg.empty()) + imshow("mean background image", bgimg ); + char k = (char)waitKey(30); if( k == 27 ) break; if( k == ' ' )