Search code examples
matlabimage-processingcomputer-visionvideo-processingmatlab-cvst

Frames missing while reading video frame by frame in matlab


This code detect faces and crop the faces and stores them in database folder.Face image 11 and 12 are missing in database folder. what is the reason?

clc;
clear all;
%read video file
obj=vision.VideoFileReader('basu_converted.avi');

%read frame by frame
for k=1:100

         videoFrame      = step(obj);

         FaceDetect = vision.CascadeObjectDetector;%using viola jones algorithm

         BB = step(FaceDetect,videoFrame);

         figure(1),imshow(videoFrame)


     for i = 1:size(BB,1)

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

      end

     %crop and save detected face images
     for i = 1:size(BB,1)

     J= imcrop(videoFrame,BB(i,:));
     I=rgb2gray(imresize(J,[292,376]));

     filename = ['G:\matlab_installed\bin\database\' num2str(i+k*(size(BB,1))) '.jpg'];
     imwrite(I,filename);

    end


end

Solution

  • I noticed a error you made indexing the images. BB has a variable size, thus you can't use it to linearise the indices. Instead of num2str(i+k*(size(BB,1))) I would use a counter which is incremented each iteration.