Processing Frames from a Video

10 ビュー (過去 30 日間)
Hollis Williams
Hollis Williams 2022 年 4 月 15 日
コメント済み: David K. 2022 年 4 月 15 日
I have a piece of code where I read an image and then do some processing with it. If I instead have an AVI file, is there a simple way to read the video file, select a chosen frame from it, and then analyse that frame as an image?
III0 = double(imread('Documents\sphereattempt.png'));
III1 = (III0(:,:,3)./(III0(:,:,1)+III0(:,:,2)+III0(:,:,3)));
figure(2);
contourf(flipud(min(max(movmean(movmean(III1,10,2),10,1),0.3),0.5)),[0.3:0.01:0.5]);
axis equal;
colorbar
set(gca,'Ydir','reverse')

採用された回答

David K.
David K. 2022 年 4 月 15 日
The VideoReader object looks like the way to go. With the basic case being:
v = VideoReader('example.avi');
while hasFrame(v)
frame = readFrame(v);
% processing for each frame goes here
end
Where frame is an individual image. If you want to start from a specific time you can use
v.CurrentTime = 2.5; % time in seconds to start
then use readFrame to get the frame you want.
Something that may go wrong is shown on Supported Video Formats where there is a troubleshooting section talking about how there is a chance that you will need to install some other things if your specific avi format is not currently readable by your matlab install. I have not personally tried any of these methods to fix a format issue.
  2 件のコメント
Hollis Williams
Hollis Williams 2022 年 4 月 15 日
So in the processing section it would start
III0 = double(imread('frame')); ?
David K.
David K. 2022 年 4 月 15 日
Not quite. The readFrame function is taking the place of the imread function in your code. If the video is X by Y pixels and is in color. The output frame from
frame = readFrame(v);
should be a X x Y x 3 uint8 array. So III0 should be
III0 = double(readFrame(v));
to make them the same as your single image.

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by