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
0 个评论
回答(1 个)
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 个评论
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!