概述
#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);
++num;
}
return 0;
}
2.
#ifndef _DETECTOR_H
#define _DETECTOR_H
#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 <string>
using namespace std;
using namespace cv;
class Detector{
public:
Detector();
~Detector();
void SetThresh(const int& area);
bool Detect(const Mat& img);
private:
Ptr<BackgroundSubtractorMOG2> mog;
bool alarm = false;
Mat fgmask;
int thresh;
int num;
};
#endif
3.
#include "detect.hpp"
using namespace cv;
Detector::Detector()
{
mog = createBackgroundSubtractorMOG2();
num = 0;
};
Detector::~Detector(){};
void Detector::SetThresh(const int& area)
{
thresh = area;
};
bool Detector::Detect(const Mat& img)
{
Ptr<BackgroundSubtractorMOG2> mog;
mog->apply(img,fgmask,-1);
num += 1;
string name = "cap_" + to_string(num) + ".jpg";
imwrite(name,fgmask);
};
4.
#!/usr/bin env sh
#g++ gmm.cpp -std=c++11
# -L/usr/lib/x86_64-linux-gnu/
# -I/usr/include/opencv/
# -I/usr/include/opencv2/
#
-o gmm
g++ gmm.cpp -std=c++11
-I/usr/include/opencv
-I/usr/include/opencv2
-L/usr/lib/x86_64-linux-gnu/
-lopencv_highgui -lopencv_imgproc -lopencv_core
-o gmm
最后
以上就是灵巧海燕为你收集整理的GMM背景建模与前景提取的全部内容,希望文章能够帮你解决GMM背景建模与前景提取所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复