Block matching algorithm
显示 更早的评论
sir, Am doing a project based on camera based vehicle speed measurement we used block matching algorithm to compare first and last frame of the video captured could u pls help me out by suggesting a program code for this.
回答(1 个)
Mark Darwin
2019-11-27
1 个投票
% Copyright 2015-2016 The MathWorks, Inc.
%%
close all
clear
clc
tic
%% Set up video reader
videoReader = vision.VideoFileReader('buoyMotion.avi',...
'ImageColorSpace','Intensity');
%% Set up optical flow
of = opticalFlowHS;
of.Smoothness = 0.1;
% of = opticalFlowFarneback();
% of.NumPyramidLevels = 1;
% of = opticalFlowLK();
% of.NoiseThreshold = 0.01;
% of = opticalFlowLKDoG();
% of.NoiseThreshold = 1e-4;
%% Loop algorithm
while(~isDone(videoReader))
vidFrame = step(videoReader);
flowField = estimateFlow(of,vidFrame);
subplot(2,2,1);
plot(flowField,...
'DecimationFactor',[10 10],...
'ScaleFactor',50);
title('Optical Flow')
horizontalMotion = flowField.Vx;
objectsToRight = horizontalMotion > 1;
objectsToLeft = horizontalMotion < -1;
subplot(2,2,3);
imshow(objectsToRight);
title('Objects moving to the RIGHT side’)
subplot(2,2,4);
imshow(objectsToLeft);
title('Objects moving to the LEFT side')
robotLeftMotion = nnz(objectsToRight);
robotRightMotion = nnz(objectsToLeft);
if robotLeftMotion > robotRightMotion
movString = 'Moving to LEFT';
else
movString = 'Moving to RIGHT';
end
frameMov = insertText(vidFrame,[400 400],movString,...
'FontSize',26);
subplot(2,2,2);
imshow(frameMov)
title('Robot Movement')
drawnow;
End
%% Clean up
timeElapsed = toc
release(videoReader);
1 个评论
Mark Darwin
2019-11-27
video about motion for Block matching algoritm
https://drive.google.com/file/d/1v6YcZr4H_S5nKOd_jU4KS14djNYb4xc-/view?usp=sharing
类别
在 帮助中心 和 File Exchange 中查找有关 Video Formats and Interfaces 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!