[英]How to extract all the frames from a video using MATLAB and do key frame extraction by any standard method?
[英]how to display the frame difference output of all the frames in video using matlab
我已经计算了视频的当前和背景帧的h,s和v值的差异,并希望显示该值,以便对差异值进行随机检查,以采取进一步措施。 我得到的最终输出为360x640矩阵。 猜猜它显示最后一帧的差值。 谁能帮助我显示h,s和v的所有差值。
videoObject = VideoReader(movieFullFileName)
% Determine how many frames there are.
% numberOfFrames = videoObject.NumberOfFrames;
vidHeight = videoObject.Height;
vidWidth = videoObject.Width;
for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = read(videoObject, frame);
% Now let's do the differencing
alpha = 0.5;
if frame == 1
Background = thisFrame;
else
% Change background slightly at each frame
% Background(t+1)=(1-alpha)*I+alpha*Background
Background = (1-alpha)* thisFrame + alpha * Background;
end
% Display the changing/adapting background.
subplot(2, 2, 3);
imshow(Background);
title('Adaptive Background', 'FontSize', fontSize);
% Do color conversion from rgb to hsv
x=rgb2hsv(thisFrame);
y=rgb2hsv(Background);
% Split the hsv component to h,s,v value
Hx = x(:,:,1);
Sx = x(:,:,2);
Vx = x(:,:,3);
Hy = y(:,:,1);
Sy = y(:,:,2);
Vy = y(:,:,3);
dh=(abs(double(Hx) - double(Hy)));
ds1=(abs(double(Sx) - double(Sy)));
dv1=(abs(double(Vx) - double(Vy)));
disp(dh);
disp(ds1);
disp(dv1);
end
end
您应该添加drawnow
在的结尾for
-loop每帧更新的图形窗口。
而且, disp
将以数字显示差异矩阵。 考虑使用类似
subplot(2, 2, 1)
imshow(dh)
具有适当的颜色缩放比例以可视化差异矩阵。
如果要显示完整的图像
首先,您需要评估完整的HSV图像
hsv=zeros(size(x,1),size(x,2))
hsv(:,:,1) = dh;
hsv(:,:,2) = ds1;
hsv(:,:,3) = dv1;
然后使用以下命令转换为RGB:
rgb = hsv2rgb(hsv);
那么您可以使用以下命令显示它:
image(rgb);
如果要显示单个h,s和v图像
只需使用:
for frame = 1 : numberOfFrames
subplot(3,1,1)
imshow(dh)
subplot(3,1,2)
imshow(ds1)
subplot(3,1,3)
imshow(ds2)
impixelinfo;
pause;
end
当光标在图像上方时,您将在图像的左下方看到像素值。 要继续下一张图像,请按任意键盘键
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.