核心内容:
#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);
}
}