opencv3/C++视频背景建模
来源:互联网 发布:程序员的技术栈 编辑:程序博客网 时间:2024/05/17 06:07
视频背景建模主要使用到:
高斯混合模型(Mixture Of Gauss,MOG)
createBackgroundSubtractorMOG2(int history=500, double varThreshold=16,bool detectShadows=true);
K最近邻(k-NearestNeighbor,kNN)
createBackgroundSubtractorKNN(int history=500, double dist2Threshold=400.0, bool detectShadows=true);
history:history的长度。
varThreshold:像素和模型之间马氏距离的平方的阈值。
detectShadows:默认为true,检测阴影并标记它们(影子会被标记为灰色)。 会降低了部分速度。
实例:
#include<opencv2/opencv.hpp>using namespace cv;int main(){ VideoCapture capture; capture.open("E:/image/01.avi"); if(!capture.isOpened()) { printf("can not open video file \n"); return -1; } Mat frame; namedWindow("input", CV_WINDOW_AUTOSIZE); namedWindow("MOG2", CV_WINDOW_AUTOSIZE); namedWindow("KNN", CV_WINDOW_AUTOSIZE); Mat maskMOG2, maskKNN; Ptr<BackgroundSubtractor> pMOG2 = createBackgroundSubtractorMOG2(500,25,true); Ptr<BackgroundSubtractor> pKNN = createBackgroundSubtractorKNN(); Mat kernel = getStructuringElement(MORPH_RECT, Size(5,5)); while (capture.read(frame)) { imshow("input", frame); pMOG2->apply(frame, maskMOG2); pKNN->apply(frame, maskKNN); //对处理后的帧进行开操作,减少视频中较小的波动造成的影响 morphologyEx(maskMOG2,maskMOG2, MORPH_OPEN, kernel, Point(-1,-1)); morphologyEx(maskKNN,maskKNN, MORPH_OPEN, kernel, Point(-1,-1)); imshow("MOG2", maskMOG2); imshow("KNN", maskKNN); waitKey(3); } capture.release(); return 0;}
视频中移动的玻璃球:
MOG分离出的小球区域:
KNN分离出的小球区域:
阅读全文
0 0
- opencv3/C++视频背景建模
- 图像/视频背景建模
- opencv3 背景建模提取前景图像
- 背景建模测试数据库、视频库
- 视频 背景建模,运动物体检测
- “背景建模/背景减法/前景检测”测试视频库
- 背景建模技术(四):视频分析(VideoAnalysis)模块
- 背景建模技术(五):视频捕获(VideoCapture)模块
- 基于背景建模方法处理视频(常用的函数)
- 混合高斯背景建模-视频的运动目标检测
- 背景建模
- 背景建模
- 背景建模
- 背景建模
- 背景建模
- VIBE背景建模算法之C语言实现
- 高斯混合模型背景建模(BackgroundSubtractorMOG2)在opencv3.0与opencv2.4中的使用方法区别
- 背景建模--基于码本背景建模
- idea 误删文件恢复
- Introduction to Linear Algebra 学习笔记(一)
- Toj 3777 Function Problem
- Java培训总结-第1周
- bzoj1026 [SCOI2009]windy数
- opencv3/C++视频背景建模
- HTML 5概述
- SCRAPY_part4_Items
- 长期失眠如何调理?经常熬夜的朋友的福音来了。
- AMH面板彻底删除网站的方法
- shell版俄罗斯方块
- 变量名与变量地址的一些理解
- Spring框架 WEB-INF下访问login.jsp
- div中嵌套input 以及input默认样式的清除