finding a velocity of moving object using optical flow
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a matlab based application in which I compute the optical flow by the following code. How can I find the resultant vector of velocity for the moving object and what are the units of u and v?
%%Extraction of frames
>> obj = VideoReader(filename);
for k = 1 : 2 %fill in the appropriate number
this_frame = readFrame(obj);
thisfig = figure();
thisax = axes('Parent', thisfig);
image(this_frame, 'Parent', thisax);
title(thisax, sprintf('Frame #%d', k));
end
%% optical flow
>> I1=imread('Framep#1.png');
>> I2=imread('Framep#2.png');
>> modelname = 'ex_blkopticalflow.slx';
>> open_system(modelname)
>> out = sim(modelname);
>> Vx = real(out.simout);
>> Vy = imag(out.simout);
>> img = out.simout1;
>> flow = opticalFlow(Vx,Vy);
>> figure
imshow(img)
hold on
plot(flow,'DecimationFactor',[5 5],'ScaleFactor',40)
댓글 수: 1
Cris LaPierre
2023년 9월 22일
You might be interested in our Computer Vision for Engineering and Science specialization. It's free to enroll.
Here's a relevant video from Course 3: Applying Optical Flow
답변 (1개)
Ishaan
2025년 3월 26일
I noticed that the code you are using after frame extraction is same as the one in Compute Optical Flow Velocities Example provided by MathWorks. And I understand that you intend to get the resultant velocity in a vector format and know the units of its components.
I think that you are referring to the horizontal (“Vx”) and vertical component (“Vy”) of the velocity with “u” and “v” respectively, same as the nomenclature used in the video linked by @Cris LaPierre.
The units of “Vx” and “Vy” is “pixels per frame” as no other information is available to the optical flow function.
The resultant velocity vector is available as the following read-only properties of the “opticalFlow” object:
- “flow.Orientation” - Phase angles of optical flow in radians
- “flow.Magnitude” - Magnitude of optical flow in pixels per frame
For more details on “opticalFlow”, please refer to this documentation: https://www.mathworks.com/help/vision/ref/opticalflowobject.html
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!