Background and foreground in OpencV

后端 未结 1 1501
[愿得一人]
[愿得一人] 2020-12-31 23:19

i\'m working on a project using OpenCV243, I need to get the foreground during a stream, my Problem is that I use the cv::absdiff to get it doesn\'t really help, here is m

相关标签:
1条回答
  • 2021-01-01 00:07

    BackgroundSubtractorMOG2 should work with #include "opencv2/video/background_segm.hpp" The samples with OpenCV have two nice c++ examples (in the samples\cpp directory).

    • bgfg_segm.cpp shows how to use the BackgroundSubtractorMOG2
    • bgfg_gmg.cpp uses BackgroundSubtractorGMG

    To get the last values (and asuming you meant to get the foreground pixel values) you could copy the frame using the foreground mask. This is also done in the first example, in the following snippet:

    bg_model(img, fgmask, update_bg_model ? -1 : 0);
    fgimg = Scalar::all(0);
    img.copyTo(fgimg, fgmask);
    
    0 讨论(0)
提交回复
热议问题