多帧人脸检测和裁剪的Matlab代码?

3

我编写了用于从视频中检测人脸的Matlab代码。但它只能从单个帧中检测出人脸,并显示裁剪后的人脸图像。我想要从多个帧中检测和裁剪人脸。以下是我的代码:

clc;
clear all;

%read frames from video
obj=VideoReader('vtu.avi');

 img = read(obj,1);
 figure(1),imshow(img);

 %detect face using vision.CascadeObjectDetector
 FaceDetect = vision.CascadeObjectDetector; 
   BB = step(FaceDetect,img);
   figure(2),imshow(img);

   for i = 1:size(BB,1)

        rectangle('Position',BB(i,:),'LineWidth',3,'LineStyle','-','EdgeColor','r');
   end

    %crop faces 
     for i = 1:size(BB,1)
        J= imcrop(img,BB(i,:));
        figure(3),subplot(2,2,i);imshow(J);
     end
1个回答

2
你需要额外添加一个循环:
for index=1:1:obj.numberofframes
    img = read(mov,index);
    ... ...
    % do face detection and crop for 'img' here
    ... ...
end

多帧中如何裁剪人脸? - user3237134
1
@user3237134 对于每个img,只需执行此步骤。 - herohuyongtao

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接