行人检测

我的第一个的

我现在在做行人检测的,在此下载了一些行人检测的代码的,基于matlab版本的,但是不是很理解的,希望请教大家的:


这个三个代码怎么的运行的???



第一个代码:用来计算binhogfeature

function binfeat = BinHOGFeature(blockGr, blockInd, CellSize, BinNum)


% devide the block
block_ori1=blockGr(1:CellSize,1:CellSize);
block_ori2=blockGr(1:CellSize,(1+CellSize):2*CellSize);
block_ori3=blockGr((1+CellSize):2*CellSize,1:CellSize);
block_ori4=blockGr((1+CellSize):2*CellSize,(1+CellSize):2*CellSize);
block_grad1=blockInd(1:CellSize,1:CellSize);
block_grad2=blockInd(1:CellSize,(1+CellSize):2*CellSize);
block_grad3=blockInd((1+CellSize):2*CellSize,1:CellSize);
block_grad4=blockInd((1+CellSize):2*CellSize,(1+CellSize):2*CellSize);


% here we calculate 4 cells
binfeat = zeros(BinNum*4, 1);
feat1 = zeros(BinNum, 1);
feat2 = zeros(BinNum, 1);
feat3 = zeros(BinNum, 1);
feat4 = zeros(BinNum, 1);


for i=1:BinNum
    feat1(i) = sum(block_ori1(find(block_grad1==i)));
end




for i=1:BinNum
    feat2(i) = sum(block_ori2(find(block_grad2==i)));
end




for i=1:BinNum
    feat3(i) = sum(block_ori3(find(block_grad3==i)));
end




for i=1:BinNum
    feat4(i) = sum(block_ori4(find(block_grad4==i)));
end


binfeat = [feat1;feat2;feat3;feat4];
% binfeat = binfeat./sum(binfeat);     % here we normallize the feature
sump=sqrt(sum(binfeat.^2));
binfeat = binfeat./(sump+eps);


第二个代码:HOGGradient

function [gradx, grady] = HOGGradient(G)


% here we defing the mask as [-1, 0, 1], the edge of the image use [-1, 1]
[height, width] = size(G);


gradx = zeros(height, width);
grady = zeros(height, width);


% Process the Image edge
gradx(:,1) = sum(G(:,1:2).*repmat([-1, 1], height, 1), 2);
gradx(:,width) = sum(G(:, width-1:width).*repmat([-1, 1], height, 1), 2);


grady(1,:) = sum(G(1:2, :).*repmat([-1; 1], 1, width), 1);
grady(height,:) = sum(G(height-1:height, :).*repmat([-1; 1], 1, width), 1);


for j=2:height-1
    for i=2:width-1
        tmpx = G(j, i-1:i+1);
        tmpy = G(j-1:j+1, i);
        gradx(j,i) = sum(tmpx.*[-1, 0, 1], 2);
        grady(j,i) = sum(tmpy.*[-1; 0; 1], 1);
    end
end


第三个代码: ImgHOGFeature

function [imgHOGFeature] = ImgHOGFeature(ImgPathName, SkipStep, BinNum, Angle, CellSize, filter_para)
% compare with ImgHOGFeature2, this function use image name instead of Image data 


if nargin<5
    disp('Not enough parameters!');
    return;
end
if nargin==6
    filter_hsize=filter_para(1);
    filter_delta=filter_para(2);
end


%% Gamma/Colour Normalization
Img = imread(ImgPathName);
if size(Img,3) == 3
    G = rgb2gray(Img);
else
    G = Img;
end


[height, width] = size(G);


%% Gradient and Gradient angle Computation
if filter_hsize == 0
    [GradientX,GradientY] = gradient(double(G));
else
    h=fspecial('gaussian', filter_hsize, filter_delta);
    [GradientX, GradientY] = HOGGradient(double(G));
end
% calculate the norm of gradient
Gr = sqrt(GradientX.^2+GradientY.^2);
% Calculate the angle
index = find(GradientX == 0);
GradientX(index) = 1e-5;
YX = GradientY./GradientX;
if Angle == 180, A = ((atan(YX)+(pi/2))*180)./pi; end
if Angle == 360, A = ((atan2(GradientY,GradientX)+pi).*180)./pi; end
%% Spatial / Orientation Binning
nAngle = Angle/BinNum;
IndTag = ceil(A./nAngle);


xStepNum = floor((width-2*CellSize)/SkipStep+1);
yStepNum = floor((height-2*CellSize)/SkipStep+1);
overL = SkipStep;


FeatDim = BinNum*4;
imgHOGFeature = zeros(FeatDim, xStepNum*yStepNum);
currFeat = zeros(FeatDim,1);


% BinHOG = inline('BinHOGFeature(blockGr, blockInd, CellSize, BinNum)', 'blockGr', 'blockInd', 'CellSize', 'BinNum');


for j=1:xStepNum
    for k=1:yStepNum
        x_Off = (j-1)*overL+1;
        y_Off = (k-1)*overL+1;


        % here we define each block have 4 cells
        blockGr = Gr(y_Off:y_Off+2*CellSize-1,x_Off:x_Off+2*CellSize-1);
        blockInd = IndTag(y_Off:y_Off+2*CellSize-1,x_Off:x_Off+2*CellSize-1);


        % calculate the block tag and Grain of each pixel
        currFeat = BinHOGFeature(blockGr, blockInd, CellSize, BinNum);
        
        % calculate the feature of the block
        imgHOGFeature(:, (j-1)*yStepNum+k) = currFeat;
    end
end

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值