-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdemoMPII.m
executable file
·75 lines (58 loc) · 2.21 KB
/
demoMPII.m
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
% This script demonstrates how to use:
% the proposed EM algorithm + pose dictionary learned from Human3.6M
% + the most recent CNN based 2D detector "Hourglass network"
% (https://github.com/anewell/pose-hg-demo)
% We use the first image in the validation set of MPII as example
clear
datapath = 'data/mpii/';
% list of validation images in MPII
fileID = fopen([datapath 'annot/valid_images.txt']);
imgList = textscan(fileID,'%s');
fclose(fileID);
% load dictionary learned from Human3.6M
dict = load('dict/poseDict-all-K128');
dictDataset = 'hm36m';
% convert dictionary format
% because the joint order in MPII is different from that in Human3.6M
dict = getMPIIdict(dict,dictDataset);
numKp = length(dict.skel.tree);
% read MPII annotation
h5File = [datapath 'annot/valid.h5'];
scales = hdf5read(h5File,'scale');
centers = hdf5read(h5File,'center');
parts = hdf5read(h5File,'part');
%% process the first image
i = 1;
% read heatmaps generated by the Hourglass model
% see data/mpii/main-heatmaps.lua for how to run Hourglass on MPII and save heatmaps
% if you are processing a seqeunce, stack the heatmaps of all frames see demoHG for example
heatmap = hdf5read(sprintf('%s/test-valid/valid%d.h5',datapath,i),'heatmaps');
% transpose heatmaps to make it consistent with the MATLAB x-y directions
heatmap = permute(heatmap,[2,1,3]);
% EM
% set beta and gamma to be zero because you are processing single images
output = PoseFromVideo('heatmap',heatmap,'dict',dict);
% get estimated poses coordinates for EM output
% the estimated 2D joint location is w.r.t. the bounding box
% need to be converted to the original image coordinates
preds_2d = transformMPII(output.W_final,centers(:,i),scales(i),[size(heatmap,1) size(heatmap,2)],1);
preds_3d = output.S_final;
%% visualize
nPlot = 4;
figure('position',[300 300 200*nPlot 200]);
subplot(1,nPlot,1);
I = imread(sprintf('%s/images/%s',datapath,imgList{1}{i}));
imshow(I); hold on
vis2Dmarker(parts(:,:,i));
title('image+gt')
subplot(1,nPlot,2);
imagesc(mat2gray(sum(heatmap,3)));
axis equal off
title('heatmap')
subplot(1,nPlot,3);
imshow(I);
vis2Dskel(preds_2d,dict.skel);
title('2D estimates')
subplot(1,nPlot,4);
vis3Dskel(preds_3d(:,:,i),dict.skel,'viewpoint',[-90 0]);
title('3D (novel view)')