本文介绍了实时运动历史图像(MHI)在Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是通过存储的视频剪辑检测人类活动。我使用以下代码,以获得视频剪辑的运动历史图像(MHI)。

My project was to detect human activity through stored video clips. I have used following code in order to get the Motion History Image (MHI) of the video clip.

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


$ b b

但是,现在我想扩展我的项目并实时显示运动历史图像(MHI)。也就是说,将从网络摄像头捕获帧,并且在捕获帧时,将显示运动历史图像(MHI)。如何实现这一点?

However, now I want to extend my project and display the Motion History Image (MHI) in real time. That is, the frames will be captured from the webcam, and as they are captured, a Motion History Image (MHI) will be displayed. How can I achieve this?

任何帮助将不胜感激。谢谢。

Any help will be appreciated. Thank you.

推荐答案

你应该把你的循环矢量化。您还可以使用 MHI 的3D数组,而不是单元格数组。我没有测试它,但代码应该看起来像这样:

You should definitely vectorize your loops. You can also use a 3D array for MHI instead of a cell array. I have not tested it, but the code should look something like this:

MHI = zeros(y_max, x_max, numel(fg));
MHI(:,:,1) = fg{1} .* T;
for frameIndex = 2:length(fg)
  mhi = MHI(:,:,frameIndex);
  mhi(fg{frameIndex} == 255) = T;

  prevMHI = MHI(:,:,frameIndex-1);
  idx = prevMHI > 1;
  mhi(idx) = prevMHI(idx) - 1;
end

这篇关于实时运动历史图像(MHI)在Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 12:33