天天看點

背景差分法 Background Subtraction Methods

核心内容:

#include <opencv2/opencv.hpp>
using namespace cv;
Mat frame; //目前圖像
Mat fgMaskMOG2; //前景掩碼,方式MOG2
Ptr<BackgroundSubtractor> pMOG2;//初始化
int main()
{
    VideoCapture capture();
    pMOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach
    while (waitKey()!=)
    {
        //read the current frame
        capture.read(frame);
        //update the background model
        pMOG2->apply(frame, fgMaskMOG2);
        imshow("Frame", frame);
        imshow("FG Mask MOG 2", fgMaskMOG2);
    }
}