Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab code for detecting face from multiple frames and crop faces?

I wrote matlab code for detecting face from video.But it is detecting face from single frame.It is showing cropped faces for single frame.i want to detect and crop face from multiple frames.Here is my code

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
like image 602
user3237134 Avatar asked Sep 10 '26 05:09

user3237134


1 Answers

You need an extra loop:

for index=1:1:obj.numberofframes
    img = read(mov,index);
    ... ...
    % do face detection and crop for 'img' here
    ... ...
end
like image 148
herohuyongtao Avatar answered Sep 12 '26 19:09

herohuyongtao