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

採用された回答

Walter Roberson
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 ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by