#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using namespace cv;
int main()
{
string file = "/home/zhanghan/itemloss/myself/video/2.mp4";
VideoCapture cap(file);
Mat frame,frameGray;
Mat foreground,fgmask;
Mat bgimg;
Ptr<BackgroundSubtractorMOG2> mog = createBackgroundSubtractorMOG2();
bool success = true;
int num = 1;
while(success)
{
if(!cap.read(frame))
success = false;
mog->apply(frame,fgmask,-1);
mog->getBackgroundImage(bgimg);
string name = "cap_" + to_string(num) + ".jpg";
imwrite(name,fgmask);
GMM背景建模与前景提取
最新推荐文章于 2021-03-21 19:48:49 发布