Fast HOG源码注释

本文深入解析Fast HOG(Histogram of Oriented Gradients)算法的源码,探讨其加速技巧和关键步骤,帮助读者更好地理解和应用该特征提取方法。
摘要由CSDN通过智能技术生成
DPM中使用的HOG特征提取方法,和原始的HOG不太一样,比原来的要快一些,检测效果也好一些。下边的代码是从作者的目标检测中抽出的,详情见这里。虽然已经比原始HOG快了不少,但仍有一些优化空间,比如代码中存在一些不必要的乘法,多余的计算等。


//fast hog 源码注释,求出的特征和原始的特征不太一样
//参考论文“Object detection with discriminatively train part based models”
//zhangyaocold@gmail.com


#include <math.h>
#include "mex.h"

// small value, used to avoid division by zero
#define eps 0.0001

// unit vectors used to compute gradient orientation
//把cos(a)和sin(a)按[0, pi]分为9个bin,快速近似计算梯度方向使用
double uu[9] = {1.0000, 
		0.9397, 
		0.7660, 
		0.500, 
		0.1736, 
		-0.1736, 
		-0.5000, 
		-0.7660, 
		-0.9397};
double vv[9] = {0.0000, 
		0.3420, 
		0.6428, 
		0.8660, 
		0.9848, 
		0.9848, 
		0.8660, 
		0.6428, 
		0.3420};

static inline float min(float x, float y) { return (x <= y ? x : y); }
static inline float max(float x, float y) { return (x <= y ? y : x); }

static inline int min(int x, int y) { return (x <= y ? x : y); }
static inline int max(int x, int y) { return (x <= y ? y : x); }

// main function:
// takes a double color image and a bin size 
// returns HOG features
//输入:三通道图像,每个cell的大小8x8
mxArray *process(const mxArray *mximage, const mxArray *mxsbin) {
  double *im = (double *)mxGetPr(mximage);
  const int *dims = mxGetDimensions(mximage);//图像维度三个值分别是{H, W, C};
  if (mxGetNumberOfDimensions(mximage) != 3 ||
      dims[2] != 3 ||
      mxGetClassID(mximage) != mxDOUBLE_CLASS)
    mexErrMsgTxt("Invalid input");

  int sbin = (int)mxGetScalar(mxsbin);

  // memory for caching orientation histograms & their norms
  int blocks[2];//这里用block来表示一个8x8的小块,paper里是用cell来表示,表搞混了,这个数组存的是H和W各可以划分多少cell
  blocks[0] = (int)round((double)dims[0]/(double)sbin);//H方向多少个cell
  blocks[1] &
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值