opencv2中的背景/前景分离(类BackgroundSubtractor)

opencv2中的背景/前景分离(类BackgroundSubtractor)

class CV_EXPORTS_W BackgroundSubtractor:public Algorithm

class BackgroundSubtractorMOG : public BackgroundSubtractor

class BackgroundSubtractorMOG2 : public BackgroundSubtractor

 在智能视频分析中,混合高斯建模算法(GMM)是使用最为广泛的算法之一,近来项目对速度要求较高,原先研发的算法在实时性上无法满足需求,因此转向GMM。

在Opencv中,有GMM算法的三个实现版本,分别是BackgroundSubtractorMOG、BackgroundSubtractorMOG2和BackgroundSubtractorGMG,在多种实际场景测试和比较中,发现BackgroundSubtractorMOG综合性能要优于其他两种,因此采用BackgroundSubtractorMOG为原型进行改写。


#include<opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/video/background_segm.hpp> #include <iostream> using namespace std; using namespace cv; int main() {  // Open the video file      VideoCapture capture("E:/图片/bike.avi");  // check if video successfully opened  if (!capture.isOpened())  return 0;
 // current video frame  Mat frame;   // foreground binary image  Mat foreground;
 namedWindow("Extracted Foreground");  // The Mixture of Gaussian object  // used with all default parameters  BackgroundSubtractorMOG mog;
 bool stop(false);  // for all frames in video  while (!stop)   {  // read next frame if any  if (!capture.read(frame))  break;  // update the background  // and return the foreground  mog(frame,foreground,0.01);  // Complement the image  threshold(foreground,foreground,128,255,cv::THRESH_BINARY_INV);  // show foreground  imshow("Extracted Foreground",foreground);  // introduce a delay  // or press key to stop  if (waitKey(10)>=0)  stop= true;  }  waitKey(); }

运行结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值