16,482
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/video.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2\opencv.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\objdetect\objdetect.hpp>
#include <opencv2\imgproc\types_c.h>
#include <opencv2\objdetect\objdetect_c.h>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat frame;
Mat foreground;
VideoCapture capture("bike.avi");
if (!capture.isOpened())
{
return 0;
}
namedWindow("Extracted Foreground");
namedWindow("Source Video");
// 混合高斯物体
BackgroundSubtractorMOG mog;
bool stop(false);
while (!stop)
{
if (!capture.read(frame))
{
break;
}
mog(frame, foreground, 0.01);
threshold(foreground, foreground, 128, 255, THRESH_BINARY_INV);
imshow("Extracted Foreground", foreground);
imshow("Source Video", frame);
if (waitKey(10) == 27)
{
stop = true;
}
}
}