How to save images on a new folder created automaticaly and named after a video.

3 ビュー (過去 30 日間)
Jack Wolf
Jack Wolf 2021 年 10 月 7 日
コメント済み: Jack Wolf 2021 年 10 月 7 日
So, I`m extracting frames from a video and saving them as JPEG images. However I want to save the frames automaticaly in a folder named after the video they`re from. I`m really struggling with this. This is the code I`m using. The frame extrating works as intended, the new automatic folder is the problem.
%reading video frames
vid=VideoReader('C:\Users\Myname\Documents\Test\Videos\Thevideo.avi');
numFrames = vid.NumberOfFrames;
n=numFrames;
% making a folder to save the frames
Folder = 'C:\Users\Myname\Documents\Test\Videos\Extrac\';
% writing extracted frames into the specified folder
for iFrame = 1:n
frames = read(vid, iFrame);
imwrite(frames, fullfile(Folder, sprintf('%03d.jpg', iFrame)));
end
I tried using mkdir but I`m really confused by its syntax and how to get the new folder`s path.
For example : mkdir vid.Path vid.Name . This should create a new folder named after the video`s name right ?
How do I get the path of this folder ? This syntax does not seem to work

採用された回答

Stephen
Stephen 2021 年 10 月 7 日
編集済み: Stephen 2021 年 10 月 7 日
"For example : mkdir vid.Path vid.Name. This should create a new folder named after the video`s name right ? "
No it won't, because you used command syntax it will create a folder literally called "vid.Name", whereas you must use function syntax if you want to include an input variable:
mkdir(vid.Path,vid.Name)
"How do I get the path of this folder ?"
newFolder = fullfile(vid.Path,vid.Name)
Note that you should probably remove the file extension (rather than naming the folder using the complete filename) for which FILEPARTS is the correct tool. And to ensure consistency you should use the name that you create using FULLFILE, so your code should probably be something like this:
[~,noex] = fileparts(vid.Name);
fpth = fullfile(vid.Path,noex);
mkdir(fpth)
.. fullfile(fpth,sprintf(..))
  1 件のコメント
Jack Wolf
Jack Wolf 2021 年 10 月 7 日
Thank you so much for you time ! It works.
I still need to study a lot =)

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by