Effacer les filtres
Effacer les filtres

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

14 vues (au cours des 30 derniers jours)
abbxucy11
abbxucy11 le 26 Sep 2016
Commenté : Geoff Hayes le 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);

Réponses (1)

Geoff Hayes
Geoff Hayes le 26 Sep 2016
Modifié(e) : Geoff Hayes le 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 commentaires
Geoff Hayes
Geoff Hayes le 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?
Geoff Hayes
Geoff Hayes le 27 Sep 2016
Or try
firstFrame = read(videoObj,1);

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by