How can i extract the first frame of a video and save it as an image?

9 Ansichten (letzte 30 Tage)
abbxucy11
abbxucy11 am 26 Sep. 2016
Kommentiert: Geoff Hayes am 27 Sep. 2016
i use this code but it doesnt work. it has the error below, but im sure that the video is in the correct path.
THE CODE:
video =[handles.FilePath handles.FileName];
axes(handles.axesRoiVideo);
img = frame2im(VideoReader(video,1));
ERRORS:
Error using VideoReader/init (line 607)
The filename specified was not found in the MATLAB path.
Error in VideoReader (line 172)
obj.init(fileName);

Antworten (1)

Geoff Hayes
Geoff Hayes am 26 Sep. 2016
Bearbeitet: Geoff Hayes am 27 Sep. 2016
abbxucy11 - if we assume that handles.FilePath and handles.FileName are valid, then use fullfile to create the full path and file name for your video.
videoPathAndFileName = fullfile(handles.FilePath,handles.FileName);
fprintf('Loading video file %s...\n, videoPathAndFileName);
videoObj = VideoReader(videoPathAndFileName);
I'm not sure why you are passing in a 1 as the second input parameter to VideoReader. What does this integer mean to you?
Now use readFrame to get the first frame of the video (see read video files for more details) as
firstFrame = readFrame(videoObj);
  3 Kommentare
Geoff Hayes
Geoff Hayes am 27 Sep. 2016
When you run the above code, what happens? Are you still observing an error and if so, what is it? Please copy and paste the results of the fprintf and verify that the path to the media is valid.
Also, what version of MATLAB are you using? And does the documentation (for your version) indicate that a 1 can be passed in to extract the first frame?

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