int main(int argc, char** argv)
{
//std::string videoFile = "E:\\C_VC_code\\Text_Photo\\dingdang.avi"; //cv::VideoCapture capture;
//capture.open(videoFile);
//VideoCapture capture("E:\\C_VC_code\\Text_Photo\\大屏互动+行人检测_标清.flv");
VideoCapture capture();
if (!capture.isOpened())
{
std::cout<<"read video failure"<<std::endl;
return -;
} cv::BackgroundSubtractorMOG2 mog; cv::Mat foreground;
cv::Mat background; cv::Mat frame;
Mat frame1;
long frameNo = ;
double scalar = 0.3; while ()
{ capture>>frame1;
resize(frame1,frame,Size(frame1.cols*scalar,frame1.rows*scalar),,,); // 运动前景检测,并更新背景
mog(frame, foreground, 0.2); // 腐蚀
cv::erode(foreground, foreground, cv::Mat()); // 膨胀
cv::dilate(foreground, foreground, cv::Mat()); mog.getBackgroundImage(background); // 返回当前背景图像 threshold(foreground,foreground,,,CV_THRESH_BINARY_INV);
cv::imshow("foreground", foreground);
cv::imshow("background", background); if (cv::waitKey() > )
{
break;
}
} return ;
}

opencv-3.0.0版本的变化:

int main(int argc, char *argv[]) {
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
cv::VideoCapture cap();
cv::Ptr<BackgroundSubtractorMOG2> bg = createBackgroundSubtractorMOG2(); bg->setNMixtures();
//bg.bShadowDetection = false;
std::vector<std::vector<cv::Point> > contours; cv::namedWindow("Frame");
cv::namedWindow("Background"); for (;;) {
cap >> frame;
//bg.operator()(frame, fore);
bg->apply(frame, fore,0.01);
bg->getBackgroundImage(back);
cv::erode(fore, fore, cv::Mat());
cv::dilate(fore, fore, cv::Mat());
cv::findContours(fore, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
cv::drawContours(frame, contours, -, cv::Scalar(, , ), );
threshold(fore, fore, , , CV_THRESH_BINARY_INV);
cv::imshow("Foreground", fore);
cv::imshow("Frame", frame);
cv::imshow("Background", back);
if (cv::waitKey() >= )
break;
}
return ;
}

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. Ubuntu系统安装(win7双系统)

    ubuntuan安装 1.安装方法及工具 1. 安装方法介绍 本人采用的是LiveUSB安装方法,也就是通常所说的U盘安装. 2.工具 硬件工具:U盘,华硕A53s电脑(我的是win7系统) 软件工具 ...

  2. chmod 和 chown 的用法

    一.chown 命令 用途:更改文件的所有者或组.命令由单词change owner组合而成. 使用示例: 1,更改文件的所有者: chown jim program.c 文件 program.c 的 ...

  3. c#找不到类型或命名空间名称“Word”

    c#找不到类型或命名空间名称“Word” 2012-10-10 11:17:33|  分类: VC#技术|举报|字号 订阅     using Word = Microsoft.Office.Inte ...

  4. crontab执行脚本中文乱码,手动执行没有问题

    crontab执行脚本中文乱码,手动执行没有问题 产生原因:       这是因为Unix/Linux下使用crontab时的运行环境已经不是用户环境了,因此原本用户下的一些环境变量的设置就失效了.例 ...

  5. 自然语言15_Part of Speech Tagging with NLTK

    https://www.pythonprogramming.net/part-of-speech-tagging-nltk-tutorial/?completed=/stemming-nltk-tut ...

  6. Java关键字——super

    使用super关键字可以从子类中调用父类中的构造方法.普通方法和属性 与this调用构造方法的要求一样,语句必须放在子类构造方法的首行 this和super都可以调用构造方法,但是两者不能同时出现,调 ...

  7. JavaWeb学习笔记——开发动态WEB资源(二)HelloWord

    该工程的功能是在页面上输出一段话 首先在src里面新建一个class,在interface里面添加javax.servlet.Servlet 以下是HelloServlet.java中的代码: pac ...

  8. canvas入门(画圆)

    1.想在H5上画一个canvas,必须在页面上你需要的地方添加canvas标签, <canvas id="myCanvas"></canvas>   接着需 ...

  9. dedecms笔记

    截取字符串 方法一: [field:title function="cn_substr(@me,10)"/] 方法二: {dede:arclist typeid=’9′ title ...

  10. js正则,电话,邮箱

    1. <script type="text/javascript"> var str="Is this all th05777-89856825ere is5 ...