所以我刚开始使用MATLAB中的图像处理/计算机视觉。
所以我的第一个任务是把一系列的图像(帧)转换成视频。因此,我通过在线资源(更具体地说,是MATLAB网站)找到了一种方法来实现它。
所以我实现的是http://www.mathworks.com/help/matlab/examples/convert-between-image-sequences-and-video.html,它为我解决了这个问题。
然而,当我播放它时,视频在某些地方似乎很紧张。就像它会在中间带来一个不同的画面,让整个视频在那一刹那变得不稳定。它发生在视频中的几个地方。
有人知道为什么会这样吗?
谢谢
下面是我使用的代码:
myFolder = 'C:\Users\owner\Desktop\MATLAB GUI\Color\Color'; %Specify Directory
filePattern = fullfile(myFolder, '*.jpg') %identify jpg files
jpegFiles = dir(filePattern) %use dir to list jpg files
size = length(jpegFiles); % length of the size of the file
outputVideo = VideoWriter(fullfile(myFolder,'video1.avi'));
outputVideo.FrameRate = 30;
open(outputVideo);
for i = 1:length(jpegFiles) %load all the files in the directory
j = i; %%accumulating the number of jpegfiles into handles.j
baseFileName = jpegFiles(i).name;
fullFileName = fullfile(myFolder, baseFileName);
%fprintf(1, 'Now reading %s\n', fullFileName); %filename of image
imageArray = imread(fullFileName); %image being read
%imageArray = rgb2gray(imageArray);
imagecell{i} = imageArray; %storing the images in imagecells
writeVideo(outputVideo,imagecell{i});
end
close(outputVideo);
video1 = VideoReader(fullfile(myFolder,'video1.avi'));
mov(video1.NumberOfFrames) = struct('cdata',[],'colormap',[]);
for ii = 1:video1.NumberOfFrames
mov(ii) = im2frame(read(video1,ii));
end
set(gcf,'position', [150 150 video1.Width video1.Height])
set(gca,'units','pixels');
set(gca,'position',[0 0 video1.Width video1.Height])
image(mov(1).cdata,'Parent',gca);
axis off;
movie(mov,1,video1.FrameRate);发布于 2014-06-19 22:25:49
考虑到可能有太多的文件要重命名(用零填充),这里有一个快速的函数可以帮您做到这一点:您只需要提供存储图像的目录/文件夹,填充(如果少于100个文件,那么填充可以是2个;如果小于1000个文件,则填充可以是3个;等等),以及一个常见的模式。代码假定每个文件中都有一个共同的模式(如“框架”或“图像”),删除后只留下数字:
renameFiles(directory,padSize,fileNamePattern)
filePattern = fullfile(directory, '*.jpg') %identify jpg files
jpegFiles = dir(filePattern) %use dir to list jpg files
for k=1:size(jpegFiles)
% get the source file that will be moved/renamed
fileSrc = jpegFiles(k).name;
% get the parts of the file
[path,name,ext] = fileparts(fileSrc);
% where does the pattern fit in the name?
idx = strfind(name,fileNamePattern);
% remove the pattern from the name
if idx==0
% pattern does not exist in file so skip it
continue;
elseif idx==1
% pattern is at the beginning of name so remove it
frameNumberStr = name(length(fileNamePattern)+1:end);
else
% pattern is at the end of name so remove it
frameNumberStr = name(1:idx-1);
end
% get the number of digits
numDigits = length(frameNumberStr);
% create the new file name
paddedName = [fileNamePattern repmat('0',1,padSize-numDigits) frameNumberStr];
fprintf('%s\n',paddedName);
% only move if the destination is different
if strcmp(paddedName,name) ~= 1
% set the destination file
fileDest = fullfile(directory,[paddedName ext]);
% move the file
movefile(fileSrc, fileDest,'f');
end
end
end一个例子--如果所有文件都有“frame”的通用模式,并且只有不到1000个文件,那么将此函数运行为
rename(pwd,3,'frame')所有被命名为frame1.jpg或frame99.jpg的文件现在都被命名为frame001.jpg和frame099.jpg。
希望这能有所帮助!
发布于 2014-06-20 17:15:47
如果有“计算机视觉系统工具箱”,则可以使用vision.VideoFileWriter对象。您可以简单地将图像一次一个地输入到它的step()方法中,然后将它们作为视频帧写入视频文件。请注意,图像必须都是相同的大小和数据类型相同。
https://stackoverflow.com/questions/24313963
复制相似问题