Average Optical Flow vectors and plot over multiple frames
Hello,
I am trying to get the average optical flow vectors for a whole video (e.g. for a 10 second video). Currently I am using the opticalFlowFarneback method from Estimate optical flow example with the Computer Vision Toolbox (https://www.mathworks.com/help/vision/ref/opticalflowhs.estimateflow.html):
%% Estimating Optical Flow
% This example uses the Farneback Method to to estimate the direction and speed of moving
% cars in the video
% Copyright 2018 The MathWorks, Inc.
%% Read the video into MATLAB
vidReader = VideoReader(‘visiontraffic.avi’);
opticFlow = opticalFlowFarneback;
%% Estimate Optical Flow of each frame
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
flow = estimateFlow(opticFlow,frameGray);
imshow(frameRGB)
hold on
% Plot the flow vectors
plot(flow,’DecimationFactor’,[25 25],’ScaleFactor’, 2)
% Find the handle to the quiver object
q = findobj(gca,’type’,’Quiver’);
% Change the color of the arrows to red
q.Color = ‘r’;
drawnow
hold off
end
Although this produces a nice visualization of flow vectors between two frames (see attached image), I need more like an average of flow vectors across all frames of the video. I am quite new to MatLab, I would be super thankful for any feedback how to change abovementioned code.Hello,
I am trying to get the average optical flow vectors for a whole video (e.g. for a 10 second video). Currently I am using the opticalFlowFarneback method from Estimate optical flow example with the Computer Vision Toolbox (https://www.mathworks.com/help/vision/ref/opticalflowhs.estimateflow.html):
%% Estimating Optical Flow
% This example uses the Farneback Method to to estimate the direction and speed of moving
% cars in the video
% Copyright 2018 The MathWorks, Inc.
%% Read the video into MATLAB
vidReader = VideoReader(‘visiontraffic.avi’);
opticFlow = opticalFlowFarneback;
%% Estimate Optical Flow of each frame
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
flow = estimateFlow(opticFlow,frameGray);
imshow(frameRGB)
hold on
% Plot the flow vectors
plot(flow,’DecimationFactor’,[25 25],’ScaleFactor’, 2)
% Find the handle to the quiver object
q = findobj(gca,’type’,’Quiver’);
% Change the color of the arrows to red
q.Color = ‘r’;
drawnow
hold off
end
Although this produces a nice visualization of flow vectors between two frames (see attached image), I need more like an average of flow vectors across all frames of the video. I am quite new to MatLab, I would be super thankful for any feedback how to change abovementioned code. Hello,
I am trying to get the average optical flow vectors for a whole video (e.g. for a 10 second video). Currently I am using the opticalFlowFarneback method from Estimate optical flow example with the Computer Vision Toolbox (https://www.mathworks.com/help/vision/ref/opticalflowhs.estimateflow.html):
%% Estimating Optical Flow
% This example uses the Farneback Method to to estimate the direction and speed of moving
% cars in the video
% Copyright 2018 The MathWorks, Inc.
%% Read the video into MATLAB
vidReader = VideoReader(‘visiontraffic.avi’);
opticFlow = opticalFlowFarneback;
%% Estimate Optical Flow of each frame
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
flow = estimateFlow(opticFlow,frameGray);
imshow(frameRGB)
hold on
% Plot the flow vectors
plot(flow,’DecimationFactor’,[25 25],’ScaleFactor’, 2)
% Find the handle to the quiver object
q = findobj(gca,’type’,’Quiver’);
% Change the color of the arrows to red
q.Color = ‘r’;
drawnow
hold off
end
Although this produces a nice visualization of flow vectors between two frames (see attached image), I need more like an average of flow vectors across all frames of the video. I am quite new to MatLab, I would be super thankful for any feedback how to change abovementioned code. optical flow, plot, plotting, quiver, video processing, video, vector, vectors MATLAB Answers — New Questions