MATLAB Answers

save matrices from loop

조회 수: 3(최근 30일)
Adrian Brown
Adrian Brown 2021년 3월 15일
댓글: Adrian Brown 2021년 3월 18일
Hello,
I am using this code that estimate Optical flow of a given video.
My purpose is to create a matrix that contain all the flow values for all while loop.
vidReader = VideoReader('Tennis Ball.avi'); % Read the Video size of frame in a video is 240x352
opticFlow = opticalFlowFarneback;
%% Estimate Optical Flow of each frame
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
flow = estimateFlow(opticFlow,frameGray); % get 4 parameters size 240x352 each
% I aim to get all the the values get it in flow for each videoframe
%size of the matrix must be 240x352*53 where 53 is the number of frames in
%the video
end
I really apprecaite any help
  댓글 수: 1
Adrian Brown
Adrian Brown 2021년 3월 15일
@Image Analyst @Jan I hope if you could please help with any suggest to my question.

댓글을 달려면 로그인하십시오.

채택된 답변

Bob Thompson
Bob Thompson 2021년 3월 15일
I could be wrong, but it seems like you just need to index flow.
vidReader = VideoReader('Tennis Ball.avi'); % Read the Video size of frame in a video is 240x352
opticFlow = opticalFlowFarneback;
%% Estimate Optical Flow of each frame
Frame = 0; % Initialize frame index
while hasFrame(vidReader)
Frame = 1; % Increase index for new frame
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
flow(:,:,frame) = estimateFlow(opticFlow,frameGray); % get 4 parameters size 240x352 each
end
  댓글 수: 11
Adrian Brown
Adrian Brown 2021년 3월 18일
Dear @Bob Thompson I really appreciate any reply from you. from each suggestion I learned a new thing from you. The two option are very helpfull for me. Thank you for your time and all your suggestion.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by