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!