How to extract frames from a video in MATLAB?

Hi, I have managed to read the video frames, but how do i extract them?
videoFReader = vision.VideoFileReader('face.avi');
videoPlayer = vision.VideoPlayer;
while ~isDone(videoFReader)
videoFrame = step(videoFReader);
step(videoPlayer, videoFrame);
end
release(videoPlayer);
release(videoFReader);
Any help would be appreciated
Thank you

 Accepted Answer

And what is the difference between a "video frame", and a "screen shot"? Please upload an image of each one so we can tell the difference. Do you mean like you want the task bar, parts of MATLAB, the figure toolbar, and any other programs that might happen to be running on your program, as well as parts of your desktop to be captured and saved?

6 Comments

apologies for not being clear, all i want to do is extract video frames from a recorded video. this code snipped i have just reads the number of frames in the video.
would you know how i would extract the video frames?
You need to use read().
% Extract the frame from the movie structure.
thisFrame = read(videoObject, frame);
See attached example.
thank you for that, also if i want the video to detect expressions how would i do that?
I have already detected various expressions and calculated the distance between the eyes and the mouth. from what i know i would need to create a threshold. something like this:-
A = smile expression B = Neutral expression
A < T < B
any ideas?
There is nothing in MATLAB that does expression detection. Like I told tlili amel in another answer this week:
"There was a paper delivered this month at IS&T's 2014 Electronic Imaging Conference entitled "Video-based facial discomfort analysis for infants" by Eleni Fotiadou, Svitlana and others from the Technische University Eindhoven (Netherlands). It has a camera in a hospital looking down on infants and looks at their face to determine how comfortable they are, whether they are happy, smiling, crying, grimacing, etc. I suggest you look up the paper or look them up. See http://spie.org/EI/conferencedetails/visual-information-processing-communication"
Hi, can you please help me if this threshold is right, it doesn't seem to work when i run it. I have looked at alot of the paper on the site you recommended. you can recognise emotions if you set up a threshold in which it detects the distance between the corner points of the mouth and eyes. the method is Euclidean Distance.
A = smile expression B = Neutral expression
A < T < B
Euclidean Distance Threshold
a=max(eucl_dist_list);
b=min(eucl_dist_list);
if(b>a)
msgbox('UNKNOWN IMAGE','error','error');
else
imshow(gray2rgb(uint8(finalimg)));
end
Sorry but it could be a complicated project and I can't afford to spend a lot of time helping you. Your code looks weird. The min is never going to be more than the max so that "if (b>a)" statement is useless - it will always do the imshow() and never ever do the msgbox(). There's no point at all to that code.

Sign in to comment.

More Answers (1)

cp sahu
cp sahu on 30 Apr 2015
Edited: cp sahu on 30 Apr 2015
%this code can run on newer versions of Matlab for older versions use %mmreader instead of VideoReader
video=VideoReader('d:\dataset\taxi.mpg');
%pass the path of the video file with extension
for k = 1 : 40
%fill in the no of frames the video contains or anything less than that, The
%no of frames in a video can be identified by reading info about the video.
%i.e. the frame rate in fps, multiply it with video length in sec.
this_frame = read(video, k);
a=sprintf('Frame #%d.jpg', k); % store the name of the frame in 'a'.
imwrite(this_frame,a,'jpg'); % store the extracted frame under the compression scheme with third parameter.
end

2 Comments

the imwrite function is not working. It says that "Unable to open file "Frame #1.jpg" for writing. You might not have write permission." I am using Matlab 2018a. Please provide me a solution
What is the folder you're writing to? It's not under Program Files is it, because Windows does not allow you to write there.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!