《学习openCV》例程解析 ex_9_3(codeBook模型实现背景减除)

本文详细解析并介绍了使用codeBook模型进行背景减除的方法,通过核心代码展示其在处理56帧和63帧时的效果,相较于平均背景法,codeBook模型表现出更优的性能。
摘要由CSDN通过智能技术生成

56帧时

63帧时


/**
比平均背景法性能更加良好的方法,codeBook模型实现背景减除

核心代码详细解析和实现 by zcube
*/

/************************************************************************/
/*			A few more thoughts on codebook models
In general, the codebook method works quite well across a wide number of conditions, 
and it is relatively quick to train and to run. It doesn’t deal well with varying patterns of 
light — such as morning, noon, and evening sunshine — or with someone turning lights 
on or off indoors. This type of global variability can be taken into account by using 
several different codebook models, one for each condition, and then allowing the condition 
to control which model is active.		                                */
/************************************************************************/

#include "stdafx.h"
#include <cv.h>			
#include <highgui.h>
#include <cxcore.h>

#define CHANNELS 3		
// 设置处理的图像通道数,要求小于等于图像本身的通道数

///
// 下面为码本码元的数据结构
// 处理图像时每个像素对应一个码本,每个码本中可有若干个码元
// 当涉及一个新领域,通常会遇到一些奇怪的名词,不要被这些名词吓坏,其实思路都是简单的
typedef struct ce {
	uchar	learnHigh[CHANNELS];	// High side threshold for learning
	// 此码元各通道的阀值上限(学习界限)
	uchar	learnLow[CHANNELS];		// Low side threshold for learning
	// 此码元各通道的阀值下限
	// 学习过程中如果一个新像素各通道值x[i],均有 learnLow[i]<=x[i]<=learnHigh[i],则该像素可合并于此码元
	uchar	max[CHANNELS];			// High side of box boundary
	// 属于此码元的像素中各通道的最大值
	uchar	min[CHANNELS];			// Low side of box boundary
	// 属于此码元的像素中各通道的最小值
	int		t_last_update;			// This is book keeping to allow us to kill stale entries
	// 此码元最后一次更新的时间,每一帧为一个单位时间,用于计算stale
	int		stale;					// max negative run (biggest period of inactivity)
	// 此码元最长不更新时间,用于删除规定时间不更新的码元,精简码本
} code_element;						// 码元的数据结构

typedef struct code_book {
	code_element	**cb;
	// 码元的二维指针,理解为指向码元指针数组的指针,使得添加码元时不需要来回复制码元,只需要简单的指针赋值即可
	int				numEntries;
	// 此码本中码元的数目
	int				t;				// count every access
	// 此码本现在的时间,一帧为一个时间单位
} codeBook;							// 码本的数据结构


///
// int updateCodeBook(uchar *p, codeBook &c, unsigned 
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值