1
$\begingroup$

I wrote matlab code for face detection.In my code it is detecting face for first 100 frames and it crop faces from each frame and saves it in database folder.Problems iam facing

1.Detecting face frame by frame is very slow.Is there any idea to run faster since i have to work on 4000 frames.

2.In my database folder it has to show 1 to 100 face images but it is not showing 11th and 12th face images directly it showing 13th face image after 10th image.23rd face image is blurr.Likewise so many images are missing and some are blurr.Last image number it is showing as 216.But total 106 face images are there in database folder.In that 12 images are blurr.Remaining are correct images.

clc;
  clear all;

  obj=vision.VideoFileReader('basu.avi');

  for k=0:99

  videoFrame      = step(obj);
  %using viola-jones algorithm
  FaceDetect = vision.CascadeObjectDetector;

 %FaceDetect
  BB = step(FaceDetect,videoFrame);
  %BB
   figure(2),imshow(videoFrame);

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

  %crop faces and convert it to gray
  for i = 1:size(BB,1)
  J= imcrop(videoFrame,BB(i,:));
  I=rgb2gray(imresize(J,[292,376]));

  %save cropped faces in database folder
  filename = ['G:\matlab_installed\bin\database\' num2str(i+k*(size(BB,1))) '.jpg'];
  imwrite(I,filename);
  end
  end
$\endgroup$

2 Answers 2

0
$\begingroup$

Set the MinSize parameter to be as big as possible. The algorithm spends most of the time looking for small faces. If you are not interested in those then it can be made much faster.

$\endgroup$
3
  • $\begingroup$ Where i have to set MinSize? $\endgroup$
    – prash2
    Commented Apr 27, 2014 at 9:35
  • $\begingroup$ mathworks.com/help/vision/ref/… $\endgroup$
    – Aaron
    Commented Apr 27, 2014 at 15:53
  • $\begingroup$ ya its working. $\endgroup$
    – prash2
    Commented Apr 29, 2014 at 17:01
1
$\begingroup$

There are a few of things you can try:

  • Definitely move FaceDetect = vision.CascadeObjectDetector; outside of the loop. You only need to create the face detector object once.
    Re-creating it for every frame is definitely your performance
    bottleneck.

  • vision.VideoFileReader returns a frame of class 'single' by default. If you change the output data type to 'uint8', that should speed up the face detector.Use obj=vision.VideoFileReader('basu.avi', 'VideoOutputDataType', 'uint8');

  • vision.VideoFileReader can also do the conversion to grayscale for
    you. Use obj=vision.VideoFileReader('basu.avi',
    'VideoOutputDataType', 'uint8', 'ImageColorSpace', 'Intensity'); This may be faster than calling rgb2gray.

  • Try limiting the size of the faces being detected using 'MinSize' and 'MaxSize' options of vision.CascadeObjectDetector and/or try
    downsampling the frame before detecting faces.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.