# Matlab 提取视频的每一帧图像_Matlab培训

5169℃
Matlab 提取视频的每一帧图像

 %% Read Video xyloObj = VideoReader(‘MVI_1268.MOV’);   nFrames = xyloObj.NumberOfFrames; vidHeight = xyloObj.Height; vidWidth = 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     mov(k).cdata = read(xyloObj, k); 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);   %% Analysis % load mov frame1 = mov(1).cdata; frame2 = mov(2).cdata; frame50 = mov(50).cdata; frame60 = mov(60).cdata; save(‘frame1.mat’, ‘frame1’); save(‘frame2.mat’, ‘frame2’); save(‘frame50.mat’, ‘frame50’); save(‘frame60.mat’, ‘frame60’);

 imshow(frame50);

 clc clear close all   % 创建视频读取对象，并设置参数 xyloObj = VideoReader(‘20130313_11404701.avi’); % 3547帧   nFrames = xyloObj.NumberOfFrames; vidHeight = xyloObj.Height; vidWidth = xyloObj.Width; FrameRate = xyloObj.FrameRate; % 24帧播放的   % 创建几帧数据的空间 frames = 101:110; mov(1:length(frames)) = struct(‘cdata’, zeros(vidHeight, vidWidth, 3, ‘uint8’), ‘colormap’, []);   % 读数据 for k = 1 : length(frames)     mov(k).cdata = read(xyloObj, frames(k)); end   % 基于video的分辨率创建figure hf = figure; set(hf, ‘position’, [150 150 vidWidth vidHeight])   % 播放视频 movie(hf, mov, 1, 10); % 在hf中以xyloObj.FrameRate帧率播放mov，播放1次   % 保存数据 save Frame101-110 mov vidHeight vidWidth

• 在线沟通，请点我在线咨询

• 咨询热线：
13261671783
客服qq：
3285157825