【问题标题】:Motion History Image (MHI) in MatlabMatlab中的运动历史图像(MHI)
【发布时间】:2015-04-29 05:54:03
【问题描述】:

我的项目是通过存储的视频剪辑检测人类活动。 我能够成功地做到以下几点:

  1. 使用 OpenCV 从视频中获取运动历史图像 (MHI)
  2. 使用 Matlab 对图像集进行训练和分类

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

我附上了一个示例运动历史图像 (MHI)

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

【问题讨论】:

标签: image matlab opencv motion


【解决方案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');

【讨论】:

  • 这个 MHI 代码有问题。我在我的视频中使用了它,我得到以下输出:postimg.org/image/cgu55is07/fd3b4802
  • 查看更新 #1 了解详情
  • 您好 Kornel,非常感谢!您的解决方案效果很好。现在我正在尝试实时获取网络摄像头视频的 MHI。你能帮助我吗?非常感谢您的帮助。
  • 你能在一个新问题中解释一下吗?
  • 您好 Kornel,这里是问题的link。
猜你喜欢
  • 1970-01-01
  • 2016-04-02
  • 2012-08-15
  • 1970-01-01
  • 1970-01-01
  • 2017-08-17
  • 1970-01-01
  • 2015-05-20
  • 1970-01-01
相关资源
最近更新 更多