Matlab does not recognize the hasFrame for input type VideoReader

17 ビュー (過去 30 日間)
isaironi
isaironi 2015 年 12 月 4 日
コメント済み: Hakin Gutiérrez 2021 年 6 月 9 日
I'm trying to just run the code to get to learn how to mess with video files. Unfortunately, one of the functions (hasFrame) doesn't seem to be working . Every time I try to use it it seems to think that the file type VideoReader is not a legitimate input. the code :
vidObj = VideoReader('xylophone.mp4');
vidHeight = vidObj.Height;
vidWidth = vidObj.Width;
s = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
'colormap',[]);
k = 1;
while hasFrame(vidObj)
s(k).cdata = readFrame(vidObj);
k = k+1;
end
error says :
Undefined function 'hasFrame' for input arguments of type 'VideoReader'.
is there some package I should have downloaded ? what's up with this?
  1 件のコメント
Stephan Köhnen
Stephan Köhnen 2016 年 7 月 21 日
Hey dude, maybe you can try this function to get your result.
Startscript:
vid = VideoReader('VideoFile.mp4');
frames = get_frames(vid, 1, 10)
Function:
function [ frame_array ] = get_frames( vid_input, start_frame, end_frame )
k = start_frame;
while k <= end_frame
frame_array{k,1} = read(vid_input,k);
disp(['Frame ' num2str(k) ' was taken.']);
k = k + 1;
end
end
Hope this will be helpfull,
cheers.

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2015 年 12 月 4 日
isaironi - according to hasFrame, this function was introduced in version R2014b so you will need at least that version in order to make use of it. (If you are using an earlier version of MATLAB, you will probably have an issue with the http://www.mathworks.com/help/matlab/ref/videoreader.readframe.htm readframe> function too.)
As an alternative, try the following
numFrames = get(vidObj,'NumberOfFrames');
for k=1:numFrames
s(k).cdata = read(vidObj,k);
end
  2 件のコメント
isaironi
isaironi 2015 年 12 月 5 日
I have R2014a, so maybe if i update the problem will go away thanks! Sairon
Image Analyst
Image Analyst 2015 年 12 月 5 日
If that solves it, can you accept the answer, and Vote for it, to give Geoff reputation points?
For what it's worth, I'm attaching a video processing demo. Not sure what MATLAB version it requires, but it does use VideoReader().

サインインしてコメントする。

その他の回答 (1 件)

Hakin Gutiérrez
Hakin Gutiérrez 2021 年 5 月 27 日
So, its 2021, I have this error displayed: "Unrecognized function or variable 'hasFrame'." And I already tried with 2019b, 2020b, and 2021a version, but it doesn't seems to be working.
  4 件のコメント
Steven Lord
Steven Lord 2021 年 5 月 27 日
The field reader in the obj struct on which you try to call hasFrame is the output of the snapshot function on a webcam object. The snapshot function returns an image and images do not have a hasFrame method. In fact I'm not sure if any of the objects you're creating has a hasFrame method. In particular it's not listed as an object function for webcam objects on its documentation page.
Instead of asking the question "do you have frames available?" which a webcam is not prepared to answer you may want to model your approach using the techniques described on this documentation page. That uses a fixed number of frames to retrieve from the webcam; you might want to instead use a while loop to process the frames as long as there's "something interesting" in the image (for some definition of "something interesting.")
Hakin Gutiérrez
Hakin Gutiérrez 2021 年 6 月 9 日
Thanks a lot, I'm currently working on it. Instead of creating a loop with the hasFrame function, I used a simple loop and it seem to work just fine

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by