How to obtain velocity and magnitude vectors of the optical flow field? I am using Lucas-Kande method of optical flow.
4 ビュー (過去 30 日間)
古いコメントを表示
I am working on the following code.
n=0;
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);
H=imag(flow)
V=real(flow)
frameWithFlow = getframe(gca);
imshow(frameRGB);
imshow(frameWithFlow.cdata)
hold on
plot(flow,'DecimationFactor',[5 5], 'ScaleFactor',10)
hold off
n=n+1;
end
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
2018 年 5 月 5 日
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?
回答 (1 件)
Vishnu Sreekumar
2017 年 3 月 1 日
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
quiver(1:n,1:m,x_vel,y_vel);
3 件のコメント
Cheuk Wing Edmond Lam
2018 年 6 月 24 日
do you happen to know the units of the values reported by flow.Magnitude?
Vishnu Sreekumar
2019 年 6 月 18 日
@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.
参考
カテゴリ
Help Center および File Exchange で Tracking and Motion Estimation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!