opencv2中的背景/前景分离(类BackgroundSubtractor)
2015-10-15 09:18
621 查看
class
CV_EXPORTS_W BackgroundSubtractor:public Algorithm
class BackgroundSubtractorMOG : public BackgroundSubtractor
class BackgroundSubtractorMOG2 : public BackgroundSubtractor¶
在智能视频分析中,混合高斯建模算法(GMM)是使用最为广泛的算法之一,近来项目对速度要求较高,原先研发的算法在实时性上无法满足需求,因此转向GMM。
在Opencv中,有GMM算法的三个实现版本,分别是BackgroundSubtractorMOG、BackgroundSubtractorMOG2和BackgroundSubtractorGMG,在多种实际场景测试和比较中,发现BackgroundSubtractorMOG综合性能要优于其他两种,因此采用BackgroundSubtractorMOG为原型进行改写。
#include<opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
// Open the video file
VideoCapture capture("E:/图片/bike.avi");
// check if video successfully opened
if (!capture.isOpened())
return 0;
// current video frame
Mat frame;
// foreground binary image
Mat foreground;
namedWindow("Extracted Foreground");
// The Mixture of Gaussian object
// used with all default parameters
BackgroundSubtractorMOG mog;
bool stop(false);
// for all frames in video
while (!stop) {
// read next frame if any
if (!capture.read(frame))
break;
// update the background
// and return the foreground
mog(frame,foreground,0.01);
// Complement the image
threshold(foreground,foreground,128,255,cv::THRESH_BINARY_INV);
// show foreground
imshow("Extracted Foreground",foreground);
// introduce a delay
// or press key to stop
if (waitKey(10)>=0)
stop= true;
}
waitKey();
}
运行结果:
CV_EXPORTS_W BackgroundSubtractor:public Algorithm
class BackgroundSubtractorMOG : public BackgroundSubtractor
class BackgroundSubtractorMOG2 : public BackgroundSubtractor¶
在智能视频分析中,混合高斯建模算法(GMM)是使用最为广泛的算法之一,近来项目对速度要求较高,原先研发的算法在实时性上无法满足需求,因此转向GMM。
在Opencv中,有GMM算法的三个实现版本,分别是BackgroundSubtractorMOG、BackgroundSubtractorMOG2和BackgroundSubtractorGMG,在多种实际场景测试和比较中,发现BackgroundSubtractorMOG综合性能要优于其他两种,因此采用BackgroundSubtractorMOG为原型进行改写。
#include<opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
// Open the video file
VideoCapture capture("E:/图片/bike.avi");
// check if video successfully opened
if (!capture.isOpened())
return 0;
// current video frame
Mat frame;
// foreground binary image
Mat foreground;
namedWindow("Extracted Foreground");
// The Mixture of Gaussian object
// used with all default parameters
BackgroundSubtractorMOG mog;
bool stop(false);
// for all frames in video
while (!stop) {
// read next frame if any
if (!capture.read(frame))
break;
// update the background
// and return the foreground
mog(frame,foreground,0.01);
// Complement the image
threshold(foreground,foreground,128,255,cv::THRESH_BINARY_INV);
// show foreground
imshow("Extracted Foreground",foreground);
// introduce a delay
// or press key to stop
if (waitKey(10)>=0)
stop= true;
}
waitKey();
}
运行结果:
相关文章推荐
- Linux流行版本
- 【nginx运维基础(4)】Nginx的日志管理(日志格式与定时分割日志)
- 【Linux常识篇(3)】文件及文件夹的ctime atime mtime的含义详解
- 【Linux高频命令专题(20)】du
- 解读x86、ARM和MIPS三种主流芯片架构
- iOS 应用架构谈 本地持久化方案
- Tomcat的URL中文乱码解决以及传输优化
- Tomcat的URL中文乱码解决以及传输优化
- 使用Dockerfile创建带Apache服务的Centos Docker镜像
- 主机Window不能访问该虚拟机Linux Samba文件服务提供了一个文件夹
- linux后台server开发环境的部署配置和验证(nginx+apache+php-fpm+FASTCGI(C/C++))
- Apache Commons 工具类介绍及简单使用
- 学习日志---linux打卡10
- linux进程(一)
- Linux战地日记—date命令详细示例
- Emacs 寻找新的维护者
- 0day-简单动态获取API(shellcode)分析NO.1
- 一个基于 Web 的 WebSphere MQ 监控工具
- CentOS install btsync
- centOs install tomcat