因为监控发展的需求,目前前景检测的研究还是很多的,也出现了很多新的方法和思路。个人了解的大概概括为以下一些:
帧差、背景减除(GMM、CodeBook、 SOBS、 SACON、 VIBE、 W4、多帧平均……)、光流(稀疏光流、稠密光流)、运动竞争(Motion Competition)、运动模版(运动历史图像)、时间熵……等等。如果加上他们的改进版,那就是很大的一个家族了。
ViBe是一种像素级视频背景建模或前景检测的算法,效果优于所熟知的几种算法,对硬件内存占用也少,很简单。我之前根据stellar0的(在这里,非常感谢stellar0)改写成一个Mat格式的了,现在摆上来和大家交流,具体如下:(在VS2010+OpenCV2.4.2中测试通过)
ViBe.h
- #pragma once
- #include <iostream>
- #include "opencv2/opencv.hpp"
- using namespace cv;
- using namespace std;
- #define NUM_SAMPLES 20 //每个像素点的样本个数
- #define MIN_MATCHES 2 //#min指数
- #define RADIUS 20 //Sqthere半径
- #define SUBSAMPLE_FACTOR 16 //子采样概率
- class ViBe_BGS
- {
- public:
- ViBe_BGS(void);
- ~ViBe_BGS(void);
- void init(const Mat _image); //初始化
- void processFirstFrame(const Mat _image);
- void testAndUpdate(const Mat _image); //更新
- Mat getMask(void){return m_mask;};
- private:
- Mat m_samples[NUM_SAMPLES];
- Mat m_foregroundMatchCount;
- Mat m_mask;
- };
ViBe.cpp