MHI 只是一种实现运动检测的方法(并以剪影为基础)。
假设最近对象的轮廓已创建。它还使用时间戳来识别当前轮廓是否是最近的。为了实现运动检测,必须将较旧的轮廓与当前轮廓进行比较。因此,较早的轮廓也会以较早的时间戳保存在图像中。
MHI 描述了一些运动物体在图像序列上的变化。基本上,您应该只维护一个每个像素都编码了时间信息的图像 - 无论剪影是否是最近的,或者在给定时间发生移动的位置。
因此 MHI 的实现非常简单,例如:
function MHI = MHI(fg)
% Initialize the output, MHI a.k.a. H(x,y,t,T)
MHI = fg;
% Define MHI parameter T
T = 15; % # of frames being considered; maximal value of MHI.
% Load the first frame
frame1 = fg{1};
% Get dimensions of the frames
[y_max x_max] = size(frame1);
% Compute H(x,y,1,T) (the first MHI)
MHI{1} = fg{1} .* T;
% Start global loop for each frame
for frameIndex = 2:length(fg)
%Load current frame from image cell
frame = fg{frameIndex};
% Begin looping through each point
for y = 1:y_max
for x = 1:x_max
if (frame(y,x) == 255)
MHI{frameIndex}(y,x) = T;
else
if (MHI{frameIndex-1}(y,x) > 1)
MHI{frameIndex}(y,x) = MHI{frameIndex-1}(y,x) - 1;
else
MHI{frameIndex}(y,x) = 0;
end
end
end
end
end
代码来自:https://searchcode.com/codesearch/view/8509149/
更新 #1:
尝试如下绘制:
% showMHI.m
% Input frame number and motion history vector to display normalized MHI
% at the specified frame.
function showMHI(n, motion_history)
frameDisp = motion_history{n};
frameDisp = double(frameDisp);
frameDisp = frameDisp ./ 15;
figure, imshow(frameDisp)
title('MHI Image');