2015-04-29 33 views
1

我的项目是通过存储的视频剪辑检测人类活动。 我能够成功地做到以下几点:Matlab中的运动历史图像(MHI)

  1. 使用OpenCV的
  2. 乘火车从视频运动历史图像(MHI)和分类利用Matlab图像组

然而,我想要使用Matlab来获取运动历史图像(MHI)。有没有可能,如果有人可以指导我?谢谢。

我已附加样本运动历史图像(MHI)

MHI sample

我已经使用MHI以下代码: http://www.ece.iastate.edu/~alexs/classes/2007_Fall_401/code/09_MotionHistory/motempl.c

+0

你是如何在OpenCV中创建MHI的? –

+0

我为MHI使用了以下代码: http://www.ece.iastate.edu/~alexs/classes/2007_Fall_401/code/09_MotionHistory/motempl.c –

回答

1

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'); 
+0

此MHI代码有问题。我在视频中使用了它,并获得了以下输出:http://postimg.org/image/cgu55is07/fd3b4802/ –

+0

请参阅更新#1以了解详细信息 – Kornel

+0

Hello Kornel,非常感谢!您的解决方案很好。 现在我正试图实时获取摄像头视频的MHI。你可以帮我吗?真的很感谢帮助。 –