I am trying to extract frames from a video and I have the following code.As I run the code the folder does not show the extracted frames and I don't know why?
1 次查看(过去 30 天)
显示 更早的评论
I have the following code.It does not give any error but the folder that is supposed to hold all the extracted frames does not show any frames.Why?
videoObject=VideoReader('clouds.mp4');
% Determine how many frames are there .
numberOfFrames = videoObject.NumberOfFrames;
vidHeight = videoObject.Height;
vidWidth = videoObject.Width;
% Ask user if they want to write the individual frames out to disk.
promptMessage = sprintf('Do you want to save the individual frames out to individual disk files?');
button = questdlg(promptMessage, 'Save individual frames?', 'Yes', 'No', 'Yes');
if strcmp(button, 'Yes')
writeToDisk=true;
% Extract out the various parts of the filename.
[folder, baseFileName, extentions] = fileparts('clouds.mp4');
% Make up a special new output subfolder for all the separate
% movie frames that we're going to extract and save to disk.
folder = pwd; % Make it a subfolder of the folder where this m-file lives.
outputFolder = sprintf('%s/Movie Frames from %s', folder, baseFileName);
% Create the folder if it doesn't exist already.
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
else
writeToDisk = false;
end
% Loop through the movie, writing all frames out.
% Each frame will be in a separate file with unique name.
meanGrayLevels = zeros(numberOfFrames, 1);
meanRedLevels = zeros(numberOfFrames, 1);
meanGreenLevels = zeros(numberOfFrames, 1);
meanBlueLevels = zeros(numberOfFrames, 1);
for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = read(videoObject, frame);
% Display it
hImage = subplot(2, 2, 1);
image(thisFrame);
caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
title(FRAMES, 'FontSize', 10);
drawnow; % Force it to refresh the window.
end
0 个评论
采纳的回答
Walter Roberson
2016-10-7
Your code does not write anything to disk, other creating the folder. You display the frames but you do not imwrite() them to disk.
更多回答(0 个)
另请参阅
类别
在 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!