mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-02 14:45:15 +02:00
Added ability to load in cmu motion capture data bases in the new data base loading format.
This commit is contained in:
parent
791f499412
commit
c45a80499c
14 changed files with 361 additions and 1736 deletions
|
|
@ -692,84 +692,3 @@ skel = acclaim_skeleton()
|
|||
|
||||
|
||||
|
||||
|
||||
def fetch_cmu(subj_motions, base_url = 'http://mocap.cs.cmu.edu:8080/subjects', skel_store_dir = '.', motion_store_dir = '.', store_motions = True, return_motions = True, messages = True):
|
||||
'''
|
||||
Download and store the skel. and motions indicated in a tuple (A,B) where A is a list of skeletons and B
|
||||
the corresponding 2-D list of motions, ie B_ij is the j-th motion to download for skeleton A_i
|
||||
The method can optionally store the fetched data and / or return them as arrays.
|
||||
If the data are already stored, they are not fetched but just retrieved.
|
||||
|
||||
e.g.
|
||||
# Download the data, do not return anything
|
||||
GPy.util.mocap.fetch_cmu(subj_motions = ([35],[[1,2,3]]), return_motions = False)
|
||||
# Fetch and return the data in a list. Do not store them anywhere
|
||||
GPy.util.mocap.fetch_cmu(subj_motions = ([35],[[1,2,3]]), return_motions = True, store_motions = False)
|
||||
|
||||
In both cases above, if the data do exist in the given skel_store_dir and motion_store_dir, they are just loaded from there.
|
||||
'''
|
||||
|
||||
subjectsNum = subj_motions[0]
|
||||
motionsNum = subj_motions[1]
|
||||
|
||||
# Convert numbers to strings
|
||||
subjects = []
|
||||
motions = [list() for _ in range(len(subjectsNum))]
|
||||
for i in range(len(subjectsNum)):
|
||||
curSubj = str(int(subjectsNum[i]))
|
||||
if subjectsNum[i] < 10:
|
||||
curSubj = '0' + curSubj
|
||||
subjects.append(curSubj)
|
||||
for j in range(len(motionsNum[i])):
|
||||
curMot = str(int(motionsNum[i][j]))
|
||||
if motionsNum[i][j] < 10:
|
||||
curMot = '0' + curMot
|
||||
motions[i].append(curMot)
|
||||
|
||||
|
||||
all_skels = []
|
||||
|
||||
assert len(subjects) == len(motions)
|
||||
|
||||
if return_motions:
|
||||
all_motions = [list() for _ in range(len(subjects))]
|
||||
else:
|
||||
all_motions = []
|
||||
|
||||
for i in range(len(subjects)):
|
||||
cur_skel_suffix = '/' + subjects[i] + '/'
|
||||
cur_skel_dir = skel_store_dir + cur_skel_suffix
|
||||
cur_skel_file = cur_skel_dir + subjects[i] + '.asf'
|
||||
cur_skel_url = base_url + cur_skel_suffix + subjects[i] + '.asf'
|
||||
|
||||
if os.path.isfile(cur_skel_file):
|
||||
if return_motions:
|
||||
with open(cur_skel_file, 'r') as f:
|
||||
cur_skel_data = f.read()
|
||||
else:
|
||||
if store_motions:
|
||||
if not os.path.isdir(cur_skel_dir):
|
||||
os.mkdir(cur_skel_dir)
|
||||
if not os.path.isdir(motion_store_dir + cur_skel_suffix):
|
||||
os.mkdir(motion_store_dir + cur_skel_suffix)
|
||||
cur_skel_data = dat.download_resource(cur_skel_url, cur_skel_file, store_motions, messages)
|
||||
|
||||
if return_motions:
|
||||
all_skels.append(cur_skel_data)
|
||||
|
||||
for j in range(len(motions[i])):
|
||||
cur_motion_url = base_url + cur_skel_suffix + subjects[i] + '_' + motions[i][j] + '.amc'
|
||||
cur_motion_file = motion_store_dir + cur_skel_suffix + subjects[i] + '_' + motions[i][j] + '.amc'
|
||||
if os.path.isfile(cur_motion_file):
|
||||
with open(cur_motion_file, 'r') as f:
|
||||
if return_motions:
|
||||
cur_motion_data = f.read()
|
||||
else:
|
||||
cur_motion_data = dat.download_resource(cur_motion_url, cur_motion_file, store_motions, messages)
|
||||
|
||||
if return_motions:
|
||||
all_motions[i].append(cur_motion_data)
|
||||
|
||||
return all_skels, all_motions
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue