MTII数据集下载地址:http://human-pose.mpi-inf.mpg.de/#download
MPII人体姿势数据集,1.0版
马克斯·普朗克信息学院版权所有2015
MPII 样本数: 25000 个(单人、多人)
16个关键点,0 - r ankle, 1 - r knee, 2 - r hip,3 - l hip,4 - l knee, 5 - l ankle, 6 - l ankle, 7 - l ankle,8 - upper neck, 9 - head top,10 - r wrist,11 - r elbow, 12 - r shoulder, 13 - l shoulder,14 - l elbow, 15 - l wrist
Annotation description
Annotations are stored in a matlab structure RELEASE having following fields
.annolist(imgidx) - annotations for image imgidx
.image.name - image filename
.annorect(ridx) - body annotations for a person ridx
.x1, .y1, .x2, .y2 - coordinates of the head rectangle
.scale - person scale w.r.t. 200 px height
.objpos - rough human position in the image
.annopoints.point - person-centric body joint annotations
.x, .y - coordinates of a joint
.id - joint id (0 - r ankle, 1 - r knee, 2 - r hip, 3 - l hip, 4 - l knee, 5 - l ankle, 6 - pelvis, 7 - thorax, 8 - upper neck, 9 - head top, 10 - r wrist, 11 - r elbow, 12 - r shoulder, 13 - l shoulder, 14 - l elbow, 15 - l wrist)
is_visible - joint visibility
.vidx - video index in video_list
.frame_sec - image position in video, in seconds
.img_train(imgidx) - training/testing image assignment
.single_person(imgidx) - contains rectangle id ridx of sufficiently separated individuals
.act(imgidx) - activity/category label for image imgidx
.act_name - activity name
.cat_name - category name
.act_id - activity id
.video_list(videoidx) - specifies video id as is provided by YouTube. To watch video on youtube go to https://www.youtube.com/watch?v=video_list(videoidx)
我下载的数据集images大小为24984张图片数据,解析出的有关键点的标注文档个数为17209个txt文件(16个点以及不足16个点全部解析),和别人解析的数目对不上,具体原因没有找到
"""
摘录:https://github.com/Fangyh09/PoseDatasets
"""
from scipy.io import loadmat
import numpy as np
def save_joints():
mat = loadmat('E:\迅雷下载\mpii_human_pose_v1_u12_2\\mpii_human_pose_v1_u12_1.mat')
fout = open(r'E:\迅雷下载\mpii_human_pose_v1_u12_2\\mpii_list1.txt', 'w')
for i, (anno, train_flag) in enumerate(
zip(mat['RELEASE']['annolist'][0, 0][0],
mat['RELEASE']['img_train'][0, 0][0],
)):
img_fn = anno['image']['name'][0, 0][0]
train_flag = int(train_flag)
if 'annopoints' in str(anno['annorect'].dtype):
# only one person
annopoints = anno['annorect']['annopoints'][0]
head_x1s = anno['annorect']['x1'][0]
head_y1s = anno['annorect']['y1'][0]
head_x2s = anno['annorect']['x2'][0]
head_y2s = anno['annorect']['y2'][0]
for annopoint, head_x1, head_y1, head_x2, head_y2 in zip(
annopoints, head_x1s, head_y1s, head_x2s, head_y2s):
if annopoint != []:
head_rect = [float(head_x1[0, 0]),
float(head_y1[0, 0]),
float(head_x2[0, 0]),
float(head_y2[0, 0])]
feed_dict = {}
feed_dict['width'] = int(abs(float(head_x2[0, 0]) - float(head_x1[0, 0])))
feed_dict['height'] = int(abs(float(head_y2[0, 0]) - float(head_y1[0, 0])))
# joint coordinates
annopoint = annopoint['point'][0, 0]
j_id = [str(j_i[0, 0]) for j_i in annopoint['id'][0]]
x = [x[0, 0] for x in annopoint['x'][0]]
y = [y[0, 0] for y in annopoint['y'][0]]
joint_pos = {}
for _j_id, (_x, _y) in zip(j_id, zip(x, y)):
joint_pos[str(_j_id)] = [float(_x), float(_y)]
if 'is_visible' in str(annopoint.dtype):
vis = [v[0] if v else [0]
for v in annopoint['is_visible'][0]]
vis = dict([(k, int(v[0])) if len(v) > 0 else v
for k, v in zip(j_id, vis)])
else:
vis = None
feed_dict['x'] = x
feed_dict['y'] = y
feed_dict['vis'] = vis
feed_dict['filename'] = img_fn
data = {
'filename': img_fn,
'train': train_flag,
'head_rect': head_rect,
'is_visible': vis,
'joint_pos': joint_pos
}
#
headlocation = ' '.join(str(x) for x in head_rect)
label = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']
sss = ' '
for key in label:
if key in data['joint_pos'].keys():
print("key",key)
sss = sss + str(key) + ' ' + str(int(data['joint_pos'][key][0])) + ' ' + str(int(data['joint_pos'][key][1])) + ' ' + str(int(data['is_visible'][key])) + ' '
else:
pass
print(sss)
sss = sss.strip()
with open("E:\迅雷下载\mpii_human_pose_v1_u12_2\\txt1\\" + data['filename'].split(".")[0] + '.txt', 'a+') as f:
f.write(sss +";" + headlocation + '\n')
# fout.write(data['filename'] + ' ' + sss + '\n')
# fout.close()
if __name__ == '__main__':
save_joints()
可视化
# -*- coding: utf-8 -*-
"""
mat格式转成txt格式
"""
import numpy as np
import cv2
import os
if __name__ == '__main__':
path1 = r"E:\mpii_human_pose_v1_u12_2\txt\\"#注意这里不要有中文路径,否则cv2.imread的时候无法读取数据
path2 = r"E:\mpii_human_pose_v1_u12_2\images\\"
path3 = r"E:\mpii_human_pose_v1_u12_2\vis\\"
txtList = os.listdir(path1)
imagesList = os.listdir(path2)
for txt in txtList:
txtPath = path1 + txt
imgPath = path2 + txt.split('.')[0] + ".jpg"
saveImgPath = path3 + txt.split('.')[0] + ".jpg"
print(imgPath)
img = cv2.imread(imgPath)
with open(txtPath, 'r') as f:
lines = f.readlines()
for line in lines:
pointLocation = line.split(';')[0].split(' ')
print(pointLocation)
for i in range(int(len(pointLocation) / 4)):
print(pointLocation[i * 4],pointLocation[i * 4 + 1],pointLocation[i * 4 + 2])
cv2.circle(img, (int(pointLocation[i * 4 + 1]), int(pointLocation[i * 4 + 2])), 1, (0, 0, 255), 2)
cv2.putText(img, pointLocation[i * 4], (int(pointLocation[i * 4 + 1]), int(pointLocation[i * 4 + 2])), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
#
cv2.imwrite(saveImgPath, img)
cv2.imshow("img", img)
cv2.waitKey(1)
# exit(0)

参考:https://blog.csdn.net/u013841196/article/details/107104183
3370

被折叠的 条评论
为什么被折叠?



