Optical flow between two frames

5 ビュー (過去 30 日間)
Dalia
Dalia 2023 年 9 月 15 日
回答済み: Ishaan 2025 年 3 月 26 日
I have used the following code to estimate a velocity of a moving box, u and v values of different points at the same block are not close. How can I estimate the representive u & v values?
obj = VideoReader('bigbox.mp4');
for k = 1 : 2
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 件のコメント
Image Analyst
Image Analyst 2023 年 9 月 16 日
If you have any more questions, then attach your data ('bigbox.mp4') with the paperclip icon after you read this:

サインインしてコメントする。

回答 (1 件)

Ishaan
Ishaan 2025 年 3 月 26 日
Hey,
I understand that you are getting a wide range of horizontal (Vx or u) and vertical (Vy or v) velocities at different points on the same block, and you want to get a representative value, a single value that best describes the velocity of a block.
The following are some approaches you can consider to aggregate the “opticalFlow” vectors into a single and meaningful value.
Note: divide the optical flow field into non-overlapping blocks before applying these methods
1. Block Average
Compute the mean “u” and “v” for each block and take it as representative value
2. Median Filtering (suggested)
Using median makes the aggregation robust to outliers, as it avoids the influence of noise / extreme values.
3. Mode
Compute the most common value of u and v to represent dominant motion in each block.
4. Weighted Average
While computing the mean value, give more importance to velocities with higher magnitude. This would aid if the noise has lower magnitude than the actual motion.
5. Principal Component Analysis
This method will identify the dominant motion in each block and gives a compact representation of motion trends.
Hope this helps you @Dalia

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by