背景差分法 Background Subtraction Methods

核心內容:

#include <opencv2/opencv.hpp>
using namespace cv;
Mat frame; //當前圖像
Mat fgMaskMOG2; //前景掩碼,方式MOG2
Ptr<BackgroundSubtractor> pMOG2;//初始化
int main()
{
    VideoCapture capture(0);
    pMOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach
    while (waitKey(30)!=27)
    {
        //read the current frame
        capture.read(frame);
        //update the background model
        pMOG2->apply(frame, fgMaskMOG2);
        imshow("Frame", frame);
        imshow("FG Mask MOG 2", fgMaskMOG2);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章