简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM