opencv高斯背景建模
2016-03-31 19:09
393 查看
#include <iostream> #include <string> #include <opencv2/opencv.hpp> int main(int argc, char** argv) { std::string videoFile = "../test.avi"; cv::VideoCapture capture; capture.open(videoFile); if (!capture.isOpened()) { std::cout<<"read video failure"<<std::endl; return -1; } cv::BackgroundSubtractorMOG2 mog; cv::Mat foreground; cv::Mat background; cv::Mat frame; long frameNo = 0; while (capture.read(frame)) { ++frameNo; std::cout<<frameNo<<std::endl; // 运动前景检测,并更新背景 mog(frame, foreground, 0.001); // 腐蚀 cv::erode(foreground, foreground, cv::Mat()); // 膨胀 cv::dilate(foreground, foreground, cv::Mat()); mog.getBackgroundImage(background); // 返回当前背景图像 cv::imshow("video", foreground); cv::imshow("background", background); if (cv::waitKey(25) > 0) { break; } } return 0; }
相关文章推荐
- Linux磁盘管理之添加硬盘
- Linux 批量修改服务器密码
- Linux crond
- OpenCV安装
- 在线评测的网站
- 论软件架构师的基本素养: 三要和三不要
- 【Data Algorithms_Recipes for Scaling up with Hadoop and Spark】Chapter 13 k-Nearest Neighbors
- 11个让你吃惊的 Linux 终端命令
- 使用ngxtop统计nginx请求
- Linux 命令使用
- 使用官方仓库在Ubuntu 14.04 LTS上安装Webmin
- JOptionPane类提示框的一些常用的方法
- 我的IOC和AOP实现
- 免备案\免审批号\廉价教你构建自己的网站\域名DNS解析\超实用的端口映射转发
- CentOS7.2详细安装步骤(三)
- linux中vi的使用
- Linux查看物理CPU个数、核数、逻辑CPU个数
- CentOS7.2详细安装步骤(二)
- 随机修改nginx端口脚本及思路
- CentOS7.2安装详细步骤