Haar 特征提取

double HaarExtract(double const ** image ,
	 int type_, cv::Rect roi)
{
    double value;
    double wh1, wh2;
    double bk1, bk2;
    int x = roi.x;
    int y = roi.y;
    int width = roi.width;
    int height = roi.height;
    switch (type_)
    {
    // Haar水平边缘
    case 0:	// HaarHEdge
	wh1 = calcIntegral(image, x, y, width, height);
	bk1 = calcIntegral(image, x + width, y, width, height);
	value = (wh1 - bk1) / static_cast<double>(width * height);
	break; 
	// Haar竖直边缘 
    case 1:	
	wh1 = calcIntegral(image, x, y, width, height);
	bk1 = calcIntegral(image, x, y + height, width, height);
	value = (wh1 - bk1) / static_cast<double>(width * height);
	break; 
	// Haar水平线型
    case 2:	
	wh1 = calcIntegral(image, x, y, width * 3, height);
	bk1 = calcIntegral(image, x + width, y, width, height);
	value = (wh1 - 3.0 * bk1) / 
		static_cast<double>(2 * width * height);
	break;
	// Haar垂直线型 
    case 3:	
	wh1 = calcIntegral(image, x, y, width, height * 3);
	bk1 = calcIntegral(image, x, y + height, width, height);
	value = (wh1 - 3.0 * bk1) / 
		static_cast<double>(2 * width * height);
	break;
    // Haar棋盘型
    case 4:	
	wh1 = calcIntegral(image, x, y, width * 2, height * 2);
	bk1 = calcIntegral(image, x + width, y, width, height);
	bk2 = calcIntegral(image, x, y + height, width, height);
	value = (wh1 - 2.0 * (bk1 + bk2)) / 
		static_cast<double>(2 * width * height);
	break;
    // Haar中心包围型
    case 5:	
	wh1 = calcIntegral(image, x, y, width * 3, height * 3);
	bk1 = calcIntegral(image, x + width,
		 y + height, width, height);
	value = (wh1 - 9.0 * bk1) / 
		static_cast<double>(8 * width * height);
	break;
    } 
    return value;
}
// 计算单窗口的积分图
double calcIntegral(double const  ** image, 
	int x, int y, int width, int height)
{
    double term_1 = image[y - 1 + height][x - 1 + width];
    double term_2 = image[y - 1][x - 1];
    double term_3 = image[y - 1 + height][x - 1];
    double term_4 = image[y - 1][x - 1 + width];
    return (term_1 + term_2) - (term_3 + term_4);
}




转载:http://blog.csdn.net/zhuwei1988

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值