我在重绘json的骨骼点时候,遇到一个奇怪问题。因为本人刚入门,所以可能疑惑点很奇怪。
我的疑惑点是为什么明明图片中显示一个人,有大神解惑一下嘛?为什么openpose的json会出现多个‘person-id’???我的重绘代码只是单纯考虑了单人情况,多人的情况未考虑。因为单人的json出现多个person-id,导致我的重绘骨骼错误。【补充一下,重绘json骨骼点时候,我没有考虑置信度】
下图是我重绘DukeMTMC-reID的一张图片的json骨骼点以及它的json信息。
以下是我重绘的部分代码(本人代码功底很差劲,所以请见谅):
def draw(im, file):
path1 = './data/openpose/DukeMTMC-reID/bounding_box_pose_train'
for root, ds, fs in os.walk(path1):
for ff in fs:
if ff.split('_keypoints')[-2] == (file.split('\\')[-1]).split('.jpg')[0]:
imshow(im)
file1 = open(os.path.join(path1, ff))
sourceInLine = file1.readlines()
# 将json的文件分割出对应的坐标字符【即:pose_keypoints_2d的坐标信息】
pointx = []
pointy = []
# 将json的文件分割出对应的坐标字符【即:pose_keypoints_2d的坐标信息】
if 'pose_keypoints_2d' not in sourceInLine[0]:
for i in range(0, 18):
x = float(0)
y = float(0)
plot(x, y, 'r.')
pointx.append(x)
pointy.append(y)
print(x, y)
else:
temp1 = sourceInLine[0].split('pose_keypoints_2d":[')[-1]
temp2 = temp1.split('],"face_keypoints_2d')[0]
temp3 = temp2.split(',')
print(temp3)
# 将坐标字符串,分类成对应的x列表与y列表
for i in range(0, len(temp3), 3):
x = float(temp3[i])
y = float(temp3[i + 1])
plot(x, y, 'r.')
pointx.append(x)
pointy.append(y)
print(x, y)
# 将坐标字符串,分类成对应的x列表与y列表
for i in range(0, len(temp3), 3):
x = float(temp3[i])
y = float(temp3[i + 1])
plot(x, y, 'r.')
pointx.append(x)
pointy.append(y)
print(x, y)
# 右边连线#######################################
right_head_x = []
right_head_y = []
right_head_x.append(pointx[0])
right_head_x.append(pointx[14])
right_head_x.append(pointx[16])
right_head_y.append(pointy[0])
right_head_y.append(pointy[14])
right_head_y.append(pointy[16])
plt.plot(right_head_x, right_head_y, color='blue') # 头蓝色
right_body_x = []
right_body_y = []
for i in range(2, 5, 1):
x = float(pointx[i])
y = float(pointy[i])
right_body_x.append(x)
right_body_y.append(y)
plt.plot(right_body_x, right_body_y, color='yellow') # 身体黄色
right_leg_x = []
right_leg_y = []
for i in range(8, 11, 1):
x = float(pointx[i])
y = float(pointy[i])
right_leg_x.append(x)
right_leg_y.append(y)
plt.plot(right_leg_x, right_leg_y, color='green') # 腿绿色
right_ShoulderToBody_x = []
right_ShoulderToBody_y = []
right_ShoulderToBody_x.append(pointx[1])
right_ShoulderToBody_x.append(pointx[2])
right_ShoulderToBody_y.append(pointy[1])
right_ShoulderToBody_y.append(pointy[2])
plt.plot(right_ShoulderToBody_x, right_ShoulderToBody_y, color='black') # 连接线黑色
right_BodyToLeg_x = []
right_BodyToLeg_y = []
right_BodyToLeg_x.append(pointx[1])
right_BodyToLeg_x.append(pointx[8])
right_BodyToLeg_y.append(pointy[1])
right_BodyToLeg_y.append(pointy[8])
plt.plot(right_BodyToLeg_x, right_BodyToLeg_y, color='black')
# 左边边连线#######################################
left_head_x = []
left_head_y = []
left_head_x.append(pointx[0])
left_head_x.append(pointx[15])
left_head_x.append(pointx[17])
left_head_y.append(pointy[0])
left_head_y.append(pointx[15])
left_head_y.append(pointy[17])
plt.plot(left_head_x, left_head_y, color='pink') # 头粉色
left_body_x = []
left_body_y = []
for i in range(5, 8, 1):
x = float(pointx[i])
y = float(pointy[i])
left_body_x.append(x)
left_body_y.append(y)
plt.plot(left_body_x, left_body_y, color='coral') # 身体珊瑚色
left_leg_x = []
left_leg_y = []
for i in range(11, 14, 1):
x = float(pointx[i])
y = float(pointy[i])
left_leg_x.append(x)
left_leg_y.append(y)
plt.plot(left_leg_x, left_leg_y, color='purple') # 腿紫色
left_ShoulderToBody_x = []
left_ShoulderToBody_y = []
left_ShoulderToBody_x.append(pointx[1])
left_ShoulderToBody_x.append(pointx[5])
left_ShoulderToBody_y.append(pointy[1])
left_ShoulderToBody_y.append(pointx[5])
plt.plot(left_ShoulderToBody_x, left_ShoulderToBody_y, color='black') # 连接线黑色
left_BodyToLeg_x = []
left_BodyToLeg_y = []
left_BodyToLeg_x.append(pointx[1])
left_BodyToLeg_x.append(pointx[11])
left_BodyToLeg_y.append(pointy[1])
left_BodyToLeg_y.append(pointy[11])
plt.plot(left_BodyToLeg_x, left_BodyToLeg_y, color='black')
outputpath = os.path.join('./data/image_point/DukeMTMC-reID/bounding_box_train', file.split('\\')[-1])
plt.savefig(outputpath)
# axis('off')
# plt.show(block=False)
# plt.pause(0.1)
plt.close('all')
由于我的代码,只提取最后一个‘person_id’后边的相关的骨骼点坐标以及置信度。所以重绘骨骼点就错误了。
如有错误,请大神们多多指教!!!