我正在做一个关于嘴唇识别的项目,我必须以 30 fps 的帧速率读取录制的视频,因此,如果我有 70 帧,我只需要每 8 帧获取或选择一个代表性帧作为数据集中帧数最短的视频为 16 帧,但我的问题是每 8 帧调整一次 for 循环,并且它无法读取任何帧,这是视频读取器的问题?所以,如果您有什么想法我会很感激 谢谢,,
v = VideoReader('1 - 1.avi');
s = floor((size(v,4))/8);
for t =1:s:size(v,4)
img = read(s,i);
y = imresize(img,[100,120];
最佳答案
我会选择example for VideoReader并修改代码进行解释-
%%// Paramters
sampling_factor = 8;
resizing_params = [100 120];
%%// Input video
xyloObj = VideoReader('xylophone.mpg');
%%// Setup other parameters
nFrames = floor(xyloObj.NumberOfFrame/sampling_factor); %%// xyloObj.NumberOfFrames;
vidHeight = resizing_params(1); %// xyloObj.Height;
vidWidth = resizing_params(1); %// xyloObj.Width;
%// Preallocate movie structure.
mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),'colormap',[]);
%// Read one frame at a time.
for k = 1 :nFrames
IMG = read(xyloObj, (k-1)*sampling_factor+1);
%// IMG = some_operation(IMG);
mov(k).cdata = imresize(IMG,[vidHeight vidWidth]);
end
%// Size a figure based on the video's width and height.
hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight])
%// Play back the movie once at the video's frame rate.
movie(hf, mov, 1, xyloObj.FrameRate);
基本上,我所做的唯一更改是针对“nFrames”以及围绕它的其他因素。尝试更改“sampling_factor”,看看这是否有意义。另外,我还添加了您在代码末尾执行的图像大小调整。
关于image - 如何在 MATLAB 中从视频中选择特定帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22317579/