MATLAB Answers

How to obtain velocity and magnitude vectors of the optical flow field? I am using Lucas-Kande method of optical flow.

조회 수: 41(최근 30일)
Daksh Agarwal
Daksh Agarwal 11 Mar 2016
I am working on the following code.
folder = fileparts(which('viptraffic.avi'));
movieFullFileName = fullfile(folder, 'viptraffic.avi');
vidReader = VideoReader(movieFullFileName);
opticFlow = opticalFlowLK('NoiseThreshold',0.0039);
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
flow = estimateFlow(opticFlow,frameGray);
frameWithFlow = getframe(gca);
hold on
plot(flow,'DecimationFactor',[5 5], 'ScaleFactor',10)
hold off
Is there a way to get the optical flow estimates of velocity and magnitude for every optical flow field obtained in every image?

  댓글 수: 1

Nachiket Patki
Nachiket Patki 5 May 2018
hey @ Daksh Agarwal I also tried this code can you please tell me one thing whether your output video runs very slowly? Because I am facing that problem. How can I make it faster?

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


Vishnu Sreekumar
Vishnu Sreekumar 1 Mar 2017
If you're still looking for an answer:
x_vel = flow.Vx;
y_vel = flow.Vy;
magnitudes = flow.Magnitude;
orientations = flow.Orientation;
Note that if the image is n x m (n rows, m columns), X direction is top to bottom and Y direction is left to right when using imshow and
plot(flow,'DecimationFactor',[5 5], 'ScaleFactor',10)
is the same as

  댓글 수: 3

Nachiket Patki
Nachiket Patki 5 May 2018
I implemented the same code and what I obtained is mxn sized x_vel and y_vel matrix (also magnitude and orientation get the same size) which is same as the frame size. But how can I get the velocity of only the objects (what I mean is particularly the objects only)that are present in the video frames?
Vishnu Sreekumar
Vishnu Sreekumar 18 Jun 2019
@Cheuk: No but I imagine it is pixels traveled per timeframe.
So if your magnitude is 0.4, and the distance between pixels is 1 cm (depending on your specific application), and the timestep between two frames is 0.1 s, then the speed is 0.4 x 1 cm / 0.1 s = 4 cm/s.

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

Community Treasure Hunt

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

Start Hunting!

Translated by