Filter löschen
Filter löschen

Get width and height of a video frame

13 Ansichten (letzte 30 Tage)
Davide Magnelli
Davide Magnelli am 6 Nov. 2017
Kommentiert: Walter Roberson am 6 Nov. 2017
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

Antworten (1)

Walter Roberson
Walter Roberson am 6 Nov. 2017
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 Kommentare
Davide Magnelli
Davide Magnelli am 6 Nov. 2017
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 am 6 Nov. 2017
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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by