SDM For Face Alignment流程介绍及Matlab代码实现之测试篇

测试很简单了,只需要载入数据,然后做正则化处理,使用训练模型产生的 {Rk} ,就可以预测特征点了。
face_alignment.m:用来预测特征点

function shape = face_alignment( ShapeModel, DataVariation,...
    LearnedCascadedModel, Data, img, shape, options )

%% setup the fixed parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nData = length(Data);
shapeDim = size(ShapeModel.MeanShape,1);
n_init_randoms_test = options.n_init_randoms_test;

MeanShape2 = vec_2_shape(ShapeModel.MeanShape);

aligned_shape = zeros(n_init_randoms_test,shapeDim);

%% detect the face region using face detectors or ground-truth %%%%%%%%%%%%
%% if using ground-truth
 boxes = detect_face( img , options );
%% predict the face box
 bbox2 = get_correct_region2( boxes, shape,img, 1 );
bbox= [];

if isempty(bbox)
    %% if using ground-truth
    bbox = getbbox(shape);
end

%% randomize n positions for initial shapes
[rbbox] = random_init_position( ...
    bbox, DataVariation, n_init_randoms_test );
[rbbox2] = random_init_position( ...
    bbox2, DataVariation, n_init_randoms_test );
%% randomize which shape is used for initial position
rIdx = randi([1,nData],n_init_randoms_test);

%% iterations of n initial points %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ir = 1 : n_init_randoms_test

    %% get random positions and inital shape indexs
    idx    = rIdx(ir);
    init_shape = Data(idx).shape; %% get randomly shape from others
    cbbox  = rbbox(ir,:);
    cbbox2  = rbbox2(ir,:);
    %init_shape = resetshape(cbbox, init_shape);
    init_shape = resetshape(cbbox, MeanShape2);
    init_shape2 = resetshape(cbbox2, MeanShape2);
   %test box between  ground-truth and face detector
    if 0
        figure(1); imshow(img); hold on;
        draw_shape(init_shape(:,1), init_shape(:,2),'r');
        draw_shape(init_shape2(:,1), init_shape2(:,2),'g');
        hold on;
        rectangle('Position',  cbbox, 'EdgeColor', 'y');
        rectangle('Position',  cbbox2, 'EdgeColor', 'k');
        hold off;
        pause;
    end

    %% detect landmarks using cascaded regression
    aligned_shape(ir,:) = cascaded_regress( ShapeModel, ...
        LearnedCascadedModel, img, init_shape, options );

end
if n_init_randoms_test == 1
    shape = vec_2_shape(aligned_shape');
else
    shape = vec_2_shape(mean(aligned_shape)');
end

end

我们来看一下效果:


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值