Action Synopsis: Pose Selection and Illustration 实现

 这是论文中的一部分, 并没有加 多维mds优化。


getaspect.m

function [ joint_position, joint_velc2, angle_position, angle_velc2 ] = getaspect( sequence )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here

framenum = size(sequence, 2);
pointnum = size(sequence, 1)/3;

% omit the last frame
joint_position = sequence(:, 1:framenum-1);
joint_velc = sequence(:, 2:framenum) - sequence(:, 1:framenum-1);
joint_velc2 = zeros(pointnum, framenum-1);
for i = 1:framenum-1
    p = joint_velc(:, i);
    p = reshape(p, 3, []);
    p = p';
    p = p.*p;
    p = sum(p, 2);
    p = sqrt(p);
    joint_velc2(:, i) = p;
end

angle_position = getangle(sequence);
angle_velc = angle_position(:, 2:framenum) - angle_position(:, 1:framenum-1);
angle_velc2 = zeros(9, framenum-1);
for i = 1:framenum-1
    p = angle_velc(:, i);
    p = reshape(p, 4, []);
    p = p';
    p = p.*p;
    p = sum(p, 2);
    p = sqrt(p);
    angle_velc2(:, i) = p;
end

angle_position = angle_position(:, 1:framenum-1);
end

function [ angles ] = getangle(sequence)

framenum = size(sequence, 2);
angles = zeros(36, framenum);

a = [1, 2, 9;...
    2, 3, 4;...
    3, 4, 5;...
    2, 6, 7;...
    6, 7, 8;...
    9, 10, 11;...
    10, 11, 12;...
    9, 13, 14;...
    13, 14, 15];

for i = 1:framenum
    p = sequence(:, i);
    p = reshape(p, 3, []);
    p = p';
    for j = 1:9
        aa = a(j, :);
        pp = p(aa, :);
        vec1 = pp(1, :) - pp(2, :);
        vec1 = vec1/sqrt(vec1*vec1');
        vec2 = pp(3,:) - pp(2, :);
        vec2 = vec2/sqrt(vec2*vec2');
        
        vec3 = cross(vec1, vec2);
        theta = acos(vec1*vec2');
        
        q = angle2q(vec3', theta);
        % ma = q2matrix(q);
        angles(j*4-3:j*4, i) = q;
    end
end

end


affinx.m

function [ ma ] = affinx( joint, weight )
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here

framenum = size(joint, 2);
pointnum = size(joint, 1);

ma = zeros(framenum, framenum);

delta = zeros(size(joint, 1), 1);
for i = 1:size(joint, 1)
    ptmp = joint(i, :);
    delta(i) = var(ptmp);
end

for i = 1:framenum
    for j = i+1:framenum
        
        p1 = joint(:, i);
        p2 = joint(:, j);
        re = 0;
        
        pp = p1 - p2;
        pp = pp.*pp;
        pp = pp./delta;
        pp = pp.*weight';
        
        re = sum(pp, 1);
%         for k = 1:pointnum
%             pp1 = p1(k);
%             pp2 = p2(k);
%             re = re+(pp1-pp2)*(pp1-pp2)/delta(k)*weight(k);
%         end
        
        re = re*exp(-(j-i)/framenum);
        ma(i, j) = re;
        ma(j, i) = re;
    end
end


end



main.m

clear
clc

addpath(genpath('.'))

%%
% load
load('cmu_skeletons');

sequence_id = 1;
sequence = cmu_skeletons(sequence_id).data;

load('sequence');

[ joint_position, joint_velc, angle_position, angle_velc ] = getaspect( sequence );

%%
% j_po_weight = ones(45, 1);
j_po_weight = [3 3 3,...
    4 4 4,...
    3 3 3,...
    2 2 2,...
    1 1 1,...
    3 3 3,...
    2 2 2,...
    1 1 1,...
    4 4 4,...
    3 3 3,2 2 2,1 1 1,...
    3 3 3,2 2 2,1 1 1];
%j_velc_weight = ones(15, 1);
j_velc_weight = [3, 4, 3, 2, 1, 3, 2, 1, 4, 3, 2 1, 3, 2 1];

% a_po_weight = ones(36, 1);
a_po_weight = [2 2 2 2,...
    2 2 2 2,...
    1, 1 1 1,...
    2 2 2 2,...
    1 1 1 1,...
    2 2 2 2,...
    1 1 1 1,...
    2 2 2 2,...
    1 1 1 1];

%a_velc_weight = ones(9, 1);
a_velc_weight = [2 2 1 2 1 2 1 2 1];

%%
[ ma_j_po ] = affinx( joint_position, j_po_weight );
[ ma_j_vel ] = affinx( joint_velc, j_velc_weight );
[ ma_a_po ] = affinx( angle_position, a_po_weight );
[ ma_a_vel ] = affinx( angle_velc, a_velc_weight );

ma = ma_j_po+ma_j_vel+ma_a_po+ma_a_vel

[tmp1] = mdscale(ma, 2)


其中, 我用了 https://github.com/chen1474147/Deep3DPose/tree/master/prepare/mesh/quatern 的四元数库。 结果还不错, 可以将运动变化检测出来。




你可能感兴趣的:(论文实现)