vs2019使用opencv实现ViBe算法

vs2019使用opencv实现ViBe算法

参考代码网址:https://github.com/upcAutoLang/BackgroundSplit-OpenCV/tree/master/src/ViBe
链接
ViBe参考文章:https://www.jianshu.com/p/48baa72c6e5f
链接
(1)Vibe.h

#include<iostream>
#include<cstdio>
#include<opencv2/opencv.hpp>

using namespace cv;
using namespace std;

//每个像素点的样本个数默认值
#define DEFAULT_NUM_SAMPLES 20

//#min指数默认值
#define DEFAULT_MIN_MATCHES 2

//Sqthere半径默认值
#define DEFAULT_RADIUS 20

//子采样概率默认值
#define DEFAULT_RANDOM_SAMPLE 16

class ViBe
{
   
public:
	ViBe(int num_sam = DEFAULT_NUM_SAMPLES,
		int min_match = DEFAULT_MIN_MATCHES,
		int r = DEFAULT_RADIUS,
		int rand_sam = DEFAULT_RANDOM_SAMPLE);
	~ViBe(void);

	//背景模型初始化
	void init(Mat img);

	//处理第一帧图像
	void ProcessFirstFrame(Mat img);

    //运行ViBe算法,提取前景区域并更新背景模型样本库
	void Run(Mat img);

	//获取前景模型二值图像
	Mat getFGModel();

	//删除样本库
	void deleteSamples();

	//x的邻居点
	int c_xoff[9];

	//y的邻居点
	int c_yoff[9];

private:
	//样本库
	unsigned char*** samples;

	//前景模型二值图像
	Mat FGModel;

	//每个像素点的样本个数
	int num_samples;

	//#min指数
	int num_min_matches;

	//Sqthere半径
	int radius;

	//子采样概率
	int random_sample;

};

(2)Vibe.cpp

#include"Vibe.h"
/*
构造函数ViBe
参数:
int num_sam:每个像素点的样本个数
int min_match:#min 指数
int r: Sqthere 半径
int rand_sam:子采样概率
*/

ViBe::ViBe(int num_sam, int min_match, int r, int rand_sam)
{
   
    num_samples = num_sam;
    num_min_matches = min_match;
    radius = r;
    random_sample = rand_sam;
    int c_off[9] = {
    -1,0,1,-1,1,-1,0,1,0 };
    for (int i = 0; i < 9; i++) {
   
        c_xoff[i] = c_yoff[i] = c_off[i];
    }
}

/*析构函数:~ViBe
  说明:释放样本库内存
*/

ViBe::~ViBe(void)
{
   
    deleteSamples();
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值