【行为识别】基于matlab轨迹法行为识别【含Matlab源码 375期】

举报
海神之光 发表于 2022/05/29 05:56:44 2022/05/29
【摘要】 一、获取代码方式 获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。 获取代码方式2: 完整代码已上传我的资源:【行为识别】基于matlab轨迹法行为识别【含Matl...

一、获取代码方式

获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

获取代码方式2:
完整代码已上传我的资源:【行为识别】基于matlab轨迹法行为识别【含Matlab源码 375期】

备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、部分源代码

%%%%%%%
%%% Main training/testing file
close all
clear all;
clc;

IraniDatasetPath = 'C:\Users\lenovo\Desktop\17351584MACH3D-Rodriguez\MACH3D\actions\bend';
trainAction = 'bend';
threshold = 0.73; % bend: 0.725; pjump: 0.76; runleft: 0.73; jack: 0.77; wave1: 0.78
actions = {'bend', 'jack', 'jump', 'pjump', 'run', 'runleft', 'runright', 'side', 'skip', 'walk', 'wave1', 'wave2'};   %  'runleft', 'runright'
actors = {'daria', 'denis', 'eli', 'ido', 'ira', 'lena', 'lyova', 'moshe', 'shahar'};
trainActorID = [1 2 3 4 6 9]; % [1 2 3 4 6 9];   % [1 2 3 4 6 9];    % i.e. Training will be done on: daria, denis, eli, ido, lena, shahar 
testActorID = [5]; % [1, 7, 8];    %s[5 7 8]               % i.e. Testing of the trained 3D MACH filter will be done on all the actions done by: ira, lyova, and moshe

% programRootPath =  'D:\Mikel\mFiles\Image Processing\MACH3D\';

numActions = length(actions);
numTestActors = length(testActorID);
numTrainActors = length(trainActorID);
volumes = cell(1, numTrainActors);

for v = 1 : numTrainActors
    inFile = sprintf('%s_%0.3d.avi', trainAction, trainActorID(v));
    % inFile = [programRootPath, inFile];
    ifp = aviinfo(inFile);
    volume = zeros(ifp.Height, ifp.Width, ifp.NumFrames, 'uint8');
    for f = 1 : ifp.NumFrames
        frame = aviread(inFile, f);
        rgbImg = frame.cdata;
        grayImg = rgb2gray(rgbImg);
        edgeImg = sobel(grayImg);
        volume(:,:,f) = edgeImg;
    end
    volumes{v} = volume;
end
mach3d = train_otmach3(volumes);
mach_file = sprintf('%s_mach.mat', trainAction);
save (mach_file, 'mach3d')


% Save 3D MACH as a short movie clip

machMovieFile = sprintf('%s_mach.avi', trainAction);
mov = avifile(machMovieFile, 'COMPRESSION', 'None', 'FPS', ifp.FramesPerSecond, 'QUALITY', 100);  % "Indeo5" is better and offer more compression than "Cinepak"
figure(1);
for f = 1 : ifp.NumFrames 
    rgbMACH = cat(3, mach3d(:,:,f), mach3d(:,:,f), mach3d(:,:,f));
    m = im2frame(rgbMACH);
    mov = addframe(mov, m);
    imshow(rgbMACH);
    pause(0.040);
end
disp('3D MACH Filter as a Movie');
disp('=========================');
mov = close(mov)


% Test 3-D MACH filter
% =======================
for a = 1 : numActions
    for v = 1 : numTestActors

        inFileTest = [IraniDatasetPath, sprintf('%s\\%s_%s.avi', actions{a}, actors{testActorID(v)}, actions{a})];
       

        iftp = aviinfo(inFileTest);
        volume = zeros(iftp.Height, iftp.Width, iftp.NumFrames, 'uint8');
        figure(2);
        for f = 1 : iftp.NumFrames
            frame = aviread(inFileTest, f);
            rgbImg = frame.cdata;
            grayImg = rgb2gray(rgbImg);
            edgeImg = sobel(grayImg);
            volume(:,:,f) = edgeImg;
    
        end
        tic
        c = fftnormxcorr3(volume, mach3d);
        disp('');
        disp(sprintf('Test Clip: %s_%s.avi', actors{testActorID(v)}, actions{a}));
        disp('============================')
        [cmax, i, j, k] = max3(c)
        toc

        lineWidth = 4;
        color = [255 255 0];


        outFile = sprintf('Result_TrainedOn_%s_TestedOn_%s_%s.avi', trainAction, actions{a}, actors{testActorID(v)}); 

        mov = avifile(outFile, 'COMPRESSION', 'Indeo5', 'FPS', iftp.FramesPerSecond, 'QUALITY', 100);  % "Indeo5" is better and offer more compression than "Cinepak"

        figure(4)
        for f = 1 : iftp.NumFrames - ifp.NumFrames + 1
            [cmax2, i2, j2] = max2(c(:,:,f));
            frame = aviread(inFileTest, f);
            rgbImg = frame.cdata;
            if cmax2 > threshold
                rgbImg = putColorRectangle(rgbImg, i2, j2, i2+ifp.Height-1, j2+ifp.Width-1, lineWidth, color);
                rgbImg = putColorCrossHair(rgbImg, 'rgb', round(i2+ifp.Height/2), round(j2+ifp.Width/2), 25, 25, 3, color);
            end

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/113995288

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。