Get width and height of a video frame

14 次查看(过去 30 天)
I am trying to exctract frames from an avi video and save each on an Array. The code is the following:
if true
folder = fileparts(which('Field_adv_diff_2D.avi'));
movieFullFileName= fullfile(folder,'Field_adv_diff_2D.avi');
videoObject = VideoReader(movieFullFileName);
numberOfFrames = videoObject.NumberOfFrames;
for frame = 1:numberOfFrames
thisFrame = read(videoObject,frame);
info = imfinfo(thisFrame);
w = info.Width;
h = info.Height;
processo=zeros(560,420,numberOfFrames);
processo(:,:,frame)=thisFrame;
end
end
I get this error:
Error using imfinfo (line 81) Expected FILENAME to be one of these types:
char
Instead its type was uint8.
Error in Get_Frame_Color_and_Set (line 51) info = imfinfo(thisFrame);
So, how might I get Width and Height of a video frame witch is uint8 instead of char?
Many thanks

回答(1 个)

Walter Roberson
Walter Roberson 2017-11-6
height = size(thisFrame,1)
width = size(thisFrame, 2)
Note: in avi files, the frame size is always the same for all frames in a movie.
  2 个评论
Davide Magnelli
Davide Magnelli 2017-11-6
Thanks, Now the issue returned is about dimension.
if true
for frame = 1:numberOfFrames
thisFrame = read(videoObject,frame);
h = size(thisFrame,1);
w = size(thisFrame,2);
processo=zeros(h,w,numberOfFrames);
processo(:,:,frame)=thisFrame;
end
end
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in Get_Frame_Color_and_Set (line 57) processo(:,:,frame)=thisFrame;
The dimension of thisFrame is 420x560x3 uint8.
Walter Roberson
Walter Roberson 2017-11-6
for frame = 1:numberOfFrames
thisFrame = read(videoObject,frame);
if frame == 1
h = size(thisFrame,1);
w = size(thisFrame,2);
processo = zeros(h, w, 3, numberOfFrames);
end
processo(:, :, :, frame) = thisFrame;
end

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by