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');
你是如何在OpenCV中创建MHI的? –
我为MHI使用了以下代码: http://www.ece.iastate.edu/~alexs/classes/2007_Fall_401/code/09_MotionHistory/motempl.c –