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. Jint .net平台的javascript引擎

    使用需求 有时候一段Javascript代码写的很棒,而我们又无法将之翻译成.net或翻译之成本很高的时候 我们就可以使用Jint引擎来运行Javascript代码,来得到我们想要的结果 或者上 ht ...

  2. js 正则表达式提取内容

    var wlan = /([a-zA-Z0-9]+)\s+Scan completed :/ var current_wlan="" if (line.match("Sc ...

  3. 用sql 语句给字段添加描述

    用sql 语句给字段添加描述 IF not exists (SELECT * FROM ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', ...

  4. 自然语言19_Lemmatisation

    QQ:231469242 欢迎喜欢nltk朋友交流 https://en.wikipedia.org/wiki/Lemmatisation Lemmatisation (or lemmatizatio ...

  5. can not import Flask错误

    在学习flask官方文档——应用构建代码时,遇到了一个小问题照例子敲好代码以后出现了can not import  Flask错误,思考很久也没有解决,最后发现是因为应用模块和flask重名了.下面是 ...

  6. Interesting things in Unity 4.5 you probably didn't know about

    http://va.lent.in/interesting-things-in-unity-4-5-you-probably-didnt-know-about/

  7. 数据库实现多站点共享Session

    数据库实现多站点共享Session 多站点共享Session有很多方法,多站点共享Session常见的做法有: 使用.net自动的状态服务(Asp.net State Service); 使用.net ...

  8. 用淘宝ip地址库查ip

    这是一个通过调用淘宝ip地址库实现ip地址查询的功能类 using System; using System.Collections.Generic; using System.Linq; using ...

  9. OWIN support for the Web API 2 and MVC 5 integrations in Autofac

    Currently, in the both the Web API and MVC frameworks, dependency injection support does not come in ...

  10. Java多线程编程核心技术--定时器

    Timer类主要负责计划任务,也就是在指定的时间开始执行某一个任务. 方法schedule(TimerTask task, Date time) public class Task { private ...