一、MPII數(shù)據(jù)集
MPII人體姿態(tài)數(shù)據(jù)集是一個常用的用于人體姿態(tài)估計和關鍵點檢測的數(shù)據(jù)集,其中包含大量的人體姿態(tài)標注數(shù)據(jù)和圖像數(shù)據(jù)。該數(shù)據(jù)集由德國馬克斯·普朗克研究所計算機視覺小組提供。
該數(shù)據(jù)集包含超過25k個圖像和對應的人體姿態(tài)標注。每個標注包括13個關鍵點(7個在軀干部分和6個在四肢),每個關鍵點包括一個坐標。此外,還提供了16個關鍵部位的二維邊界框標注和6個關鍵部位的三維坐標。
二、Mpi數(shù)據(jù)
在MPI數(shù)據(jù)中,提供了訓練和測試數(shù)據(jù),并且還將訓練數(shù)據(jù)分成了訓練集、驗證集和測試集。其中,訓練集包括24985個圖像和相應的注釋,驗證集包含2958個圖像和相應的注釋,測試集包括28678個圖像和相應的注釋。
該數(shù)據(jù)集提供了多種類型的注釋,包括關節(jié)位置的二維坐標、關節(jié)位置的三維坐標、姿態(tài)角度和人體部件的細粒度標注。此外,還提供了圖像前背景遮擋的標注、不同圖像的相對深度和交互行為的標注。
三、MPII數(shù)據(jù)集圖片選取
1、標注樣例
在下面的代碼中,我們將加載一個MPII數(shù)據(jù)集的圖像,并在圖像上繪制姿態(tài)估計的關鍵點位置。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('000001.png')
plt.imshow(img)
下面是代碼運行的結果顯示的圖片,其中紅色點表示姿態(tài)估計的關鍵點。
2、二維邊界框標注
在下面的代碼中,我們將加載一個MPII數(shù)據(jù)集的圖像,并在圖像上繪制二維邊界框標注。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('000001.png')
plt.imshow(img)
# 加載邊框密集區(qū)域注釋
anno_file = 'mpii_human_pose_v1_u12_2/train/joint_data.mat'
db = Mpii(anno_file)
data = db[0]
img = db.load_image(data['image'])
plt.imshow(img)
# 在圖像上繪制邊框
x1, y1, x2, y2 = data['objpos'] - data['bbox'][[1, 0, 3, 2]]
plt.gca().add_patch(plt.Rectangle((x1, y1), x2 - x1, y2 - y1, edgecolor='c', fill=False, linewidth=3))
下面是代碼運行的結果顯示的圖片,其中藍色矩形表示二維邊界框標注。
3、三維坐標標注
在下面的代碼中,我們將加載一個MPII數(shù)據(jù)集的圖像,并在圖像上繪制三維坐標標注。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('000001.png')
plt.imshow(img)
# 加載三維坐標注釋
anno_file = 'mpii_human_pose_v1_u12_2/train/joint_data.mat'
db = Mpii(anno_file)
data = db[0]
image_path = os.path.join(db.img_dir, data['image'])
img = db.load_image(image_path)
# 獲取在圖像中對應的關鍵點位置
joints_3d = data['joints_3d']
joints_2d = data['joints']
# 在圖像上繪制關鍵點位置
for joint_id in range(16):
plt.scatter(joints_2d[joint_id, 0], joints_2d[joint_id, 1], s=100, marker='.', color='r')
# 獲取每個關鍵點的三維坐標
joints_xyz = db.get_joints_xyz(joints_3d, image_path)
# 將三維坐標繪制成點云圖
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim3d([-1, 1])
ax.set_ylim3d([-1, 1])
ax.set_zlim3d([-1, 1])
ax.scatter(joints_xyz[:, 0], joints_xyz[:, 1], joints_xyz[:, 2], s=20, marker='o')
下面是代碼運行的結果顯示的圖片,其中紅色點表示三維坐標標注,藍色點表示繪制的三維點云圖。
4、姿態(tài)角度標注
在下面的代碼中,我們將加載一個MPII數(shù)據(jù)集的圖像,并在圖像上繪制姿態(tài)角度標注。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('000001.png')
plt.imshow(img)
# 加載姿態(tài)注釋
anno_file = 'mpii_human_pose_v1_u12_2/train/joint_data.mat'
db = Mpii(anno_file)
data = db[0]
img = db.load_image(data['image'])
# 獲取在圖像中對應的關鍵點位置
joints_3d = data['joints_3d']
joints_2d = data['joints']
# 繪制在圖像上
for joint_id in range(16):
plt.scatter(joints_2d[joint_id, 0], joints_2d[joint_id, 1], s=100, marker='.', color='r')
# 獲取每個關鍵點的姿態(tài)角度
theta = db.get_theta(data)
# 在圖像旁邊繪制姿態(tài)角度的文本說明
for i, t in enumerate(theta):
plt.text(img.shape[1] + 10, 20 + i * 20, "{}: {:.2f}".format(db.joint_names[i], t))
下面是代碼運行的結果顯示的圖片,其中紅色點表示姿態(tài)角度標注,紅色字表示姿態(tài)角度的文本說明。
5、人體部件細粒度注釋
在下面的代碼中,我們將加載一個MPII數(shù)據(jù)集的圖像,并在圖像上繪制人體部件細粒度注釋。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('000001.png')
plt.imshow(img)
# 加載人體部件細粒度注釋
anno_file = 'mpii_human_pose_v1_u12_2/train/mpii_human_pose_v1_u12_1.mat'
db = Mpii(anno_file)
data = db[0]
img = db.load_image(data['filename'])
# 獲取在圖像中對應的關鍵點位置
joints_3d = data['joints_3d']
joints_2d = data['joints']
# 繪制在圖像上
for joint_id in range(16):
plt.scatter(joints_2d[joint_id, 0], joints_2d[joint_id, 1], s=100, marker='.', color='r')
# 在圖像旁邊繪制人體部件的標簽
for label_id, label_name in enumerate(db.body_part_names):
center = db.get_body_part_center(data, label_id)
plt.text(img.shape[1] + 10, 20 + label_id * 20, "{}: ({:.0f}, {:.0f})".format(label_name, center[0], center[1]))
下面是代碼運行的結果顯示的圖片,其中紅色點表示人體部件細粒度注釋,紅色字表示人體部件的標簽。