constructing a video from a sequence images

조회 수: 11 (최근 30일)
Karbala'a Unvi. Science
Karbala'a Unvi. Science 2020년 8월 7일
댓글: Karbala'a Unvi. Science 2020년 8월 7일
Hi everyone
I got this code from internet, and trying to get the images from a video, then converting them into a video.
But, I am faceing a problime that the sequence of the formed video is not worling because some of the images
jump a head on each other,
like it works with image ( image 001) to ( image 010 ) then it jumps to ( image 100 ) to ( image 200 ) to start again from( image 002)
and so on .. weling to get the help from you all
Sorry I couldn't attach the video to this massege, you can use any short video..
Thanks in advance
Zee
clc, clear all, close all
workingDir = tempname("Vedio\12");
mkdir(workingDir)
mkdir(workingDir,'images')
shuttleVideo = VideoReader('Selfie.avi');
ii = 1;
while hasFrame(shuttleVideo)
img = readFrame(shuttleVideo);
filename = [sprintf('%01d',ii) '.jpg'];
fullname = fullfile(workingDir,'images',filename);
imwrite(img,fullname) % Write out to a JPEG file (img1.jpg, img2.jpg, etc.)
ii = ii+1;
end
%
imageNames = dir(fullfile(workingDir,'images','*.jpg'));
imageNames = {imageNames.name}';
%
outputVideo = VideoWriter(fullfile(workingDir,'Selfie_out.avi'));
outputVideo.FrameRate = shuttleVideo.FrameRate;
open(outputVideo)
%
for ii = 1:length(imageNames)
img = imread(fullfile(workingDir,'images',imageNames{ii}));
writeVideo(outputVideo,img)
end
close(outputVideo)
%
shuttleAvi = VideoReader(fullfile(workingDir,'Selfie_out.avi'));
ii = 1;
while hasFrame(shuttleAvi)
mov(ii) = im2frame(readFrame(shuttleAvi));
ii = ii+1;
end
figure
imshow(mov(1).cdata, 'Border', 'tight')
%
movie(mov,1,shuttleAvi.FrameRate)

답변 (1개)

Sudheer Bhimireddy
Sudheer Bhimireddy 2020년 8월 7일
It depends on the order in which you are reading the image files. If you want to check this, look at your imageNames variable and its contents and order
Change your filename for images to below if you have less than 10000 images
filename = [sprintf('%06d',ii) '.jpg'];
It's always better to have the filename with a trailing 0 before the iteration number.
  댓글 수: 3
Karbala'a Unvi. Science
Karbala'a Unvi. Science 2020년 8월 7일
Thank you so much for that
and there was an images with a glitch in 7 images that made the video more hard to understan it
Thank you so much for the great help
Yours
Zee
Karbala'a Unvi. Science
Karbala'a Unvi. Science 2020년 8월 7일
Thank you so much that is great help from you
That is great.
Zee

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by