1. int main(int argc, char** argv)
  2. {
  3. //std::string videoFile = "E:\\C_VC_code\\Text_Photo\\dingdang.avi";
  4.  
  5. //cv::VideoCapture capture;
  6. //capture.open(videoFile);
  7. //VideoCapture capture("E:\\C_VC_code\\Text_Photo\\大屏互动+行人检测_标清.flv");
  8. VideoCapture capture();
  9. if (!capture.isOpened())
  10. {
  11. std::cout<<"read video failure"<<std::endl;
  12. return -;
  13. }
  14.  
  15. cv::BackgroundSubtractorMOG2 mog;
  16.  
  17. cv::Mat foreground;
  18. cv::Mat background;
  19.  
  20. cv::Mat frame;
  21. Mat frame1;
  22. long frameNo = ;
  23. double scalar = 0.3;
  24.  
  25. while ()
  26. {
  27.  
  28. capture>>frame1;
  29. resize(frame1,frame,Size(frame1.cols*scalar,frame1.rows*scalar),,,);
  30.  
  31. // 运动前景检测,并更新背景
  32. mog(frame, foreground, 0.2);
  33.  
  34. // 腐蚀
  35. cv::erode(foreground, foreground, cv::Mat());
  36.  
  37. // 膨胀
  38. cv::dilate(foreground, foreground, cv::Mat());
  39.  
  40. mog.getBackgroundImage(background); // 返回当前背景图像
  41.  
  42. threshold(foreground,foreground,,,CV_THRESH_BINARY_INV);
  43. cv::imshow("foreground", foreground);
  44. cv::imshow("background", background);
  45.  
  46. if (cv::waitKey() > )
  47. {
  48. break;
  49. }
  50. }
  51.  
  52. return ;
  53. }

opencv-3.0.0版本的变化:

  1. int main(int argc, char *argv[]) {
  2. cv::Mat frame;
  3. cv::Mat back;
  4. cv::Mat fore;
  5. cv::VideoCapture cap();
  6. cv::Ptr<BackgroundSubtractorMOG2> bg = createBackgroundSubtractorMOG2();
  7.  
  8. bg->setNMixtures();
  9. //bg.bShadowDetection = false;
  10. std::vector<std::vector<cv::Point> > contours;
  11.  
  12. cv::namedWindow("Frame");
  13. cv::namedWindow("Background");
  14.  
  15. for (;;) {
  16. cap >> frame;
  17. //bg.operator()(frame, fore);
  18. bg->apply(frame, fore,0.01);
  19. bg->getBackgroundImage(back);
  20. cv::erode(fore, fore, cv::Mat());
  21. cv::dilate(fore, fore, cv::Mat());
  22. cv::findContours(fore, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
  23. cv::drawContours(frame, contours, -, cv::Scalar(, , ), );
  24. threshold(fore, fore, , , CV_THRESH_BINARY_INV);
  25. cv::imshow("Foreground", fore);
  26. cv::imshow("Frame", frame);
  27. cv::imshow("Background", back);
  28. if (cv::waitKey() >= )
  29. break;
  30. }
  31. return ;
  32. }

OpenCV高斯模型的更多相关文章

  1. Opencv混合高斯模型前景分离

    #include "stdio.h" #include "string.h" #include "iostream" #include &q ...

  2. 混合高斯模型:opencv中MOG2的代码结构梳理

    /* 头文件:OurGaussmix2.h */ #include "opencv2/core/core.hpp" #include <list> #include&q ...

  3. OpenCV混合高斯模型函数注释说明

    OpenCV混合高斯模型函数注释说明 一.cvaux.h #define CV_BGFG_MOG_MAX_NGAUSSIANS 500 //高斯背景检测算法的默认参数设置 #define CV_BGF ...

  4. [zz] 混合高斯模型 Gaussian Mixture Model

    聚类(1)——混合高斯模型 Gaussian Mixture Model http://blog.csdn.net/jwh_bupt/article/details/7663885 聚类系列: 聚类( ...

  5. 运动检测(前景检测)之(二)混合高斯模型GMM

    运动检测(前景检测)之(二)混合高斯模型GMM zouxy09@qq.com http://blog.csdn.net/zouxy09 因为监控发展的需求,目前前景检测的研究还是很多的,也出现了很多新 ...

  6. [转]运动检测(前景检测)之(二)混合高斯模型GMM

    转自:http://blog.csdn.net/zouxy09/article/details/9622401 因为监控发展的需求,目前前景检测的研究还是很多的,也出现了很多新的方法和思路.个人了解的 ...

  7. PRML读书会第九章 Mixture Models and EM(Kmeans,混合高斯模型,Expectation Maximization)

    主讲人 网络上的尼采 (新浪微博: @Nietzsche_复杂网络机器学习) 网络上的尼采(813394698) 9:10:56 今天的主要内容有k-means.混合高斯模型. EM算法.对于k-me ...

  8. [学习opencv]高斯、中值、均值、双边滤波

    http://www.cnblogs.com/tiandsp/archive/2013/04/20/3031862.html [学习opencv]高斯.中值.均值.双边滤波 四种经典滤波算法,在ope ...

  9. 混合高斯模型(GMM)推导及实现

    作者:桂. 时间:2017-03-20  06:20:54 链接:http://www.cnblogs.com/xingshansi/p/6584555.html 声明:欢迎被转载,不过记得注明出处哦 ...

随机推荐

  1. C#读写文本和连接数据库

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. beautifulsoup测试

    import re from bs4 import BeautifulSoup html_doc = """ <html><head><ti ...

  3. linux 查看内存的插槽数

    [root@web ~]# dmidecode|grep -P -A5 "Memory\s+Device"| grep Size | grep -v Range #linux查看内 ...

  4. oracle安装常见问题

    版本信息:CentOS6.5 + oracle11G 1.监视器颜色错误: [oracle@bogon database]$ 正在启动 Oracle Universal Installer... 检查 ...

  5. nginx basic auth 登陆验证模块

    #1. 新建一个pw.pl文件专门用来生成密码 #!/usr/bin/perl use strict; my $pw=$ARGV[0]; print crypt($pw,$pw)."\n&q ...

  6. 使用pt-fifo-split 工具往mysql插入海量数据

    在<mysql插入/更新数据>这篇文章提到,使用LOAD DATA INFILE语句,可以从一个文件直接加载数据到mysql中,但如果文件非常大,可能还需要对文件进行切割,分多次加载,这种 ...

  7. [问题] UISearchBar 点击取消后跳动的问题

    问题详情: 首先是TableView 作为 NavigationController 的 RootViewContrller, 然后UISearchBar   添加到TableView 的 headV ...

  8. jQuery -- is() 方法

    定义和用法: 根据选择器.DOM元素或 jQuery 对象来检测匹配元素集合,如果其中至少有一个元素符合这个给定的表达式就返回true.如果没有元素符合,或者表达式无效,都返回'false'. ''' ...

  9. PHP使用数据库的并发问题(转)

    在并行系统中并发问题永远不可忽视.尽管PHP语言原生没有提供多线程机制,那并不意味着所有的操作都是线程安全的.尤其是在操作诸如订单.支付等业务系统中,更需要注意操作数据库的并发问题. 接下来我通过一个 ...

  10. java中跳出if判断

    今天学到的一点儿新东西一个if判断里面有好多东西,紧接着还有其他代码,不能使用return来结束这个if判断这时候,就需要这样: out:if (!"null".equals(re ...