如何在MATLAB中从视频中选择特定帧? [英] how to select specific frames from a video in MATLAB?

查看:1107
本文介绍了如何在MATLAB中从视频中选择特定帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个关于嘴唇识别的项目,我必须以30 fps的帧速读取录制的视频,所以,如果我有70帧,我需要每8帧获取或选择一个代表帧作为数据集中帧数最短的最短视频是16帧,但我的问题是每8帧调整一次for循环,它无法读取任何帧是关于视频阅读器的问题??所以,请你,如果你有任何想法我会很感激
谢谢,

I am working on a project about lip recognition and I have to read a recorded a video at a frame rate of 30 fps so, if I have 70 frames I need just to acquire or select a representative frame every 8 frames as the shortest video which has number of frames in the data set is of 16 frames but my problem is to adjust the for loop every 8 frames,and it can't read any frame is the problem about the video reader??so,please if you have any idea I would be grateful thanks,,

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];


推荐答案

<请参阅 VideoReader的示例并修改代码以解释 -

I would take the example for VideoReader and modify the code to explain -

%%// 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',看看是否有意义。另外,我添加了您在代码末尾执行的图像大小调整。

Basically the only change I have made are for 'nFrames' and the other factors revolving around it. Try changing the 'sampling_factor' and see if that makes sense . Also, I have added the image resizing that you are performing at the end of your code.

这篇关于如何在MATLAB中从视频中选择特定帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆