概述
网址
http://mocap.cs.cmu.edu/
读取工具
网页地址: http://mocap.cs.cmu.edu/tools.php
可视化工具
http://graphics.cs.cmu.edu/software/mocapPlayer.zip
Matlab 读取 AMC 文件
% Reads data from an AMC motion file into a Matlab matrix variable.
% AMC file has to be in the AMC format used in the online CMU motion capture library.
% number of dimensions = number of columns = 62
% function D = amc_to_matrix(fname)
% fname = name of disk input file, in AMC format
% Example:
% D = amc_to_matrix(fname)
%
function [D] = amc_to_matrix(fname)
fid=fopen(fname, 'rt');
if fid == -1,
fprintf('Error, can not open file %s.n', fname);
return;
end;
% read-in header
line=fgetl(fid);
while ~strcmp(line,':DEGREES')
line=fgetl(fid);
end
D=[];
dims =[6 3 3 3 3 3 3 2 3 1 1 2 1 2 2 3 1 1 2 1 2 3 1 2 1 3 1 2 1];
locations = [1 7 10 13 16 19 22 25 27 30 31 32 34 35 37 39 42 43 44 46 47 49 52 53 55 56 59 60 62];
% read-in data
% labels can be in any order
frame=1;
while ~feof(fid)
if rem(frame,100) == 0
disp('Reading frame: ');
disp(frame);
end;
row = zeros(62,1);
% read frame number
line = fscanf(fid,'%sn',1);
for i=1:29
% read angle label
id = fscanf (fid,'%s',1);
switch (id)
case 'root', index = 1;
case 'lowerback', index = 2;
case 'upperback', index = 3;
case 'thorax', index = 4;
case 'lowerneck', index = 5;
case 'upperneck', index = 6;
case 'head', index = 7;
case 'rclavicle', index = 8;
case 'rhumerus', index = 9;
case 'rradius', index = 10;
case 'rwrist', index = 11;
case 'rhand', index = 12;
case 'rfingers', index = 13;
case 'rthumb', index = 14;
case 'lclavicle', index = 15;
case 'lhumerus', index = 16;
case 'lradius', index = 17;
case 'lwrist', index = 18;
case 'lhand', index = 19;
case 'lfingers', index = 20;
case 'lthumb', index = 21;
case 'rfemur', index = 22;
case 'rtibia', index = 23;
case 'rfoot', index = 24;
case 'rtoes', index = 25;
case 'lfemur', index = 26;
case 'ltibia', index = 27;
case 'lfoot', index = 28;
case 'ltoes', index = 29;
otherwise
fprintf('Error, labels in the amc are not correct.n');
return;
end
% where to put the data
location = locations(index);
len = dims(index);
if len == 6
x = fscanf (fid,'%f %f %f %f %f %fn',6);
else
if len == 3
x = fscanf (fid,'%f %f %fn',3);
else
if len == 2
x = fscanf (fid,'%f %fn',2);
else
if len == 1
x = fscanf (fid,'%fn',1);
end
end
end
end
row(location:location+len-1,1) = x;
end
row = row';
D = [D; row];
frame = frame + 1;
end
disp('Total number of frames read: ');
disp(frame-1);
fclose(fid);
save([fname,'.mat'], 'D')
python
先调用上方的 matlab 代码读取 amc 文件并转化为矩阵,保存到 mat 文件,然后用python 读取 mat 文件
import scipy.io as scio
import os
import time
path = 'walk.amc'
while not os.path.exists(path+'.mat'):
_ = os.system('matlab -nosplash -nojvm -nodesktop -r "amc_to_matrix('{}'); exit"'.format(path))
time.sleep(10)
data = scio.loadmat(path+'.mat')
import seaborn as sns
import pandas as pd
names = ['root', 'lowerback', 'upperback', 'thorax', 'lowerneck', 'upperneck',
'head', 'rclavicle', 'rhumerus', 'rradius', 'rwrist', 'rhand', 'rfingers',
'rthumb', 'lclavicle', 'lhumerus', 'lradius', 'lwrist', 'lhand', 'lfingers',
'lthumb', 'rfemur', 'rtibia', 'rfoot', 'rtoes', 'lfemur', 'ltibia', 'lfoot', 'ltoes']
dofs = [6, 3, 3, 3, 3, 3, 3, 2, 3, 1, 1, 2, 1, 2, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 1, 3, 1, 2, 1]
col_names = []
for i,name in enumerate(names):
for j in range(dofs[i]):
col_names.append(name + str(j))
print(col_names)
'''
['root0', 'root1', 'root2', 'root3', 'root4', 'root5', 'lowerback0', 'lowerback1', 'lowerback2', 'upperback0', 'upperback1', 'upperback2', 'thorax0', 'thorax1', 'thorax2', 'lowerneck0', 'lowerneck1', 'lowerneck2', 'upperneck0', 'upperneck1', 'upperneck2', 'head0', 'head1', 'head2', 'rclavicle0', 'rclavicle1', 'rhumerus0', 'rhumerus1', 'rhumerus2', 'rradius0', 'rwrist0', 'rhand0', 'rhand1', 'rfingers0', 'rthumb0', 'rthumb1', 'lclavicle0', 'lclavicle1', 'lhumerus0', 'lhumerus1', 'lhumerus2', 'lradius0', 'lwrist0', 'lhand0', 'lhand1', 'lfingers0', 'lthumb0', 'lthumb1', 'rfemur0', 'rfemur1', 'rfemur2', 'rtibia0', 'rfoot0', 'rfoot1', 'rtoes0', 'lfemur0', 'lfemur1', 'lfemur2', 'ltibia0', 'lfoot0', 'lfoot1', 'ltoes0']
'''
d = data['D']
data_dict = {} # 创建数据字典,为生成Dataframe做准备
for col, ts in zip(col_names, d.T):
data_dict[col] = ts
df = pd.DataFrame(data_dict)
df.plot(figsize=(20,20))
plt.legend(loc='upper right')
plt.figure(figsize=(20,20))
sns.heatmap(np.abs(df.corr()))
最后
以上就是帅气荔枝为你收集整理的CMU 动作捕获数据集网址读取工具的全部内容,希望文章能够帮你解决CMU 动作捕获数据集网址读取工具所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复