質問

I am working on a project about lip recognition and I have to read a recorded a video at a frame rate of 30 fps so, if I have 70 frames I need just to acquire or select a representative frame every 8 frames as the shortest video which has number of frames in the data set is of 16 frames but my problem is to adjust the for loop every 8 frames,and it can't read any frame is the problem about the video reader??so,please if you have any idea I would be grateful thanks,,

v = VideoReader('1 - 1.avi');
s = floor((size(v,4))/8);
for t =1:s:size(v,4)
img = read(s,i);
y = imresize(img,[100,120];
役に立ちましたか?

解決

I would take the example for VideoReader and modify the code to explain -

%%// Paramters
sampling_factor = 8;
resizing_params = [100 120];

%%// Input video
xyloObj = VideoReader('xylophone.mpg');

%%// Setup other parameters
nFrames = floor(xyloObj.NumberOfFrame/sampling_factor); %%// xyloObj.NumberOfFrames;
vidHeight = resizing_params(1); %// xyloObj.Height;
vidWidth = resizing_params(1); %// xyloObj.Width;

%// Preallocate movie structure.
mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),'colormap',[]);

%// Read one frame at a time.
for k = 1 :nFrames
    IMG = read(xyloObj, (k-1)*sampling_factor+1);
    %// IMG = some_operation(IMG);
    mov(k).cdata = imresize(IMG,[vidHeight vidWidth]);
end

%// Size a figure based on the video's width and height.
hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight])

%// Play back the movie once at the video's frame rate.
movie(hf, mov, 1, xyloObj.FrameRate);

Basically the only change I have made are for 'nFrames' and the other factors revolving around it. Try changing the 'sampling_factor' and see if that makes sense . Also, I have added the image resizing that you are performing at the end of your code.

他のヒント

you can achieve this task by reading frames from video and store it in cell array. From cell array , you can easily read whatever frame you want by customizing for loop as follows.

for i=1:8:n
  frame = cell{i};
  process(frame)
end
  • cell: it contains all frames in video

  • process: it is a function to perform your task

  • n: number of frames in video

If you want to get more information for reading frames from video and store into cell array, visit the following link:

https://naveenideas.blogspot.in/2016/07/reading-frames-from-video.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top