《学习OpenCV》codebook法实现背景建模(page308)

对着书本、例程研究了一个下午,感觉codebook还是难以理解。将例程分解成一句一句就能够看懂,但综合起来就不太懂了。

第二天再研究了一阵子,感觉大概懂了。

/**********************************************************************************************/
/*	A few more thoughts on codebook models
	codebook方法实现背景减除
	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 "cv.h"	
#include "highgui.h"
#include "cxcore.h"

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

/**********************************************************************************/
//下面为码本码元的数据结构
//处理图像时每个像素对应一个码本code_book,每个码本中可有若干个码元code_element
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* cbBounds, int numChannels )
// Updates the codebook entry with a new data point
//
// p			Pointer to a YUV pixel
// c			Codebook for this pixel
// cbBounds		Learning bounds for codebook (Rule of thumb: 10)
// numChannels	Number of color channels we're learning
//
// NOTES		cbBounds must be of size cbBounds[numChannels]
//		
// RETURN		codebook index
/***************************
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值