Sunteți pe pagina 1din 2

ImFolder=uigetdir;

pngFile = dir(strcat(ImFolder,'\*.png'));
S = [pngFile(:).datenum];
[S,S] = sort(S);
pngFiles = pngFile(S);
VideoFile=strcat(ImFolder,'\Video');
writeObj = VideoWriter(VideoFile);
fps= 15;
writeObj.FrameRate = fps;
open(writeObj);
for t= 1:length(pngFiles)
Frame=imread(strcat(ImFolder,'\',pngFiles(t).name));
writeVideo(writeObj,im2frame(Frame));
end
close(writerObj);
Explanation of the above code:
# ImFolder=uigetdir; --> This line when executed, will open a browse window in
which you can select your desired folder, where the frames or sequence of image
s is. The path will be stored in the variable ImFolder.
# pngFile = dir(strcat(ImFolder,'\*.png')); --> here the variable pngFile will b
e a structure that contain all the names of PNG files that are in the directory
you have specified. If your image files are in jpeg format, so give the above co
mmand as dir(strcat(ImFolder,'\*.jpg')). Here '\*.png' will be acting as a wildc
ard for all the PNG files available in that folder.
# S = [pngFile(:).datenum];
[S,S] = sort(S);
--> This 2 lines of code will sort the files according to the datenum property o
f the pngFile structure.
# pngFiles = pngFile(S); --> creating another variable pngFiles same as pngFile
, but the former contains the files list in sorted form.
# VideoFile=strcat(ImFolder,'\Video'); --> Creating a Video File name as Video
# writeObj = VideoWriter(VideoFile); --> This will create a Video Object named w
riteObj.
# fps= 15; --> specifying the frame rate as 15 (or whatever is required or whate
ver you want). Your video file length will be decided by the value of fps and th
e number of the image files.
# writeObj.FrameRate = fps; --> we have set the FrameRate property of writeObj
video object as specified in the variable fps.
# open(writeObj); --> Open to start writing the frames in the writeObj video ob
ject.
# for t= 1:length(pngFiles)
Frame=imread(strcat(ImFolder,'\',pngFiles(t).name));
writeVideo(writeObj,im2frame(Frame));
end
--> These 4 lines will write the frames in the newly created video file, that is
initially empty.
# close(writeObj); --> close the writeObj to complete the video write process.

After this line of code's execution a video file will be created the the root fo
lder with the name Video.avi or what ever you have specified.
Screenshots:
Initial Frame Sequence, that we have, before applying this code on this folder,
Create A Video File From A Sequence Of Image, Using MATLAB
Initial Frame Sequence, that we have, before applying this code on this folder
The working directory indicating the frames along with the output video file, Cr
eate A Video File From A Sequence Of Image Stored in a Folder, Using MATLAB
The working directory indicating the frames along with the output video file
Create A Video File From A Sequence Of Image Stored in a Folder, Using MATLAB,Th
e output video file along with the frames,
The output video file along with the frames,
The main idea behind the code was obtained from the blog below (We adapted it fo
r Our need though!), it does has various topics about image processing, do refer
it:
http://imageprocessingblog.com/how-to-create-a-video-from-image-files/
AUTHOR: VIBHUTESH KUMAR SINGH
An active & prominent author at Digital iVision Labs! Specializing in MATLAB, C+
+, Arduino, OpenCV, NI Labview, Web Designing & other Electronics stuffs! Just s
tarted M.Tech. From IIIT Delhi, looking for excellent PhD Opportunities with pro
minent researchers. Drop a mail: vibhutesh[at]gmail.com or Follow him at....
Facebook
Twitter
Google+
Linkedin
Start Linkedin Registered Social networking site Picture Frame Digital photo fra
me
Facebooks Promotional Codes Overstock promo codes 2 Line Start Linkedin
1 comment:
MerPati PutehDecember 10, 2013 at 6:30 AM
its ok...i already frust... still

Read more: http://www.divilabs.com/2013/12/create-video-file-from-sequence-of.ht


ml#ixzz3Q23pWnsD

S-ar putea să vă placă și