Matlab does not recognize the hasFrame for input type VideoReader
조회 수: 18 (최근 30일)
이전 댓글 표시
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
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
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
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
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
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
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 Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!