从这可以找到答案
从github的Issue中得到了一种解决办法,需要修改一下tf-pose中的estimator.py文件,其中TfPoseEstimator类中有一个函数为draw_humans,将在其中添加一个list来保存点的坐标即可。需要添加以下三行代码,其中,flat就是存放坐标的list
flat = [0.0 for i in range(36)]
....
flat[i*2] = center[0]
flat[i*2+1] = center[1]
修改完毕后为该函数增加一个返回值或是在函数中直接输出,更改后的代码如下
def draw_humans(npimg, humans, imgcopy=False):
if imgcopy:
npimg = np.copy(npimg)
image_h, image_w = npimg.shape[:2]
centers = {}
#添加一个数组记录坐标 作为返回值返回
flat = [0.0 for i in range(36)]
for human in humans:
# draw point
for i in range(common.CocoPart.Background.value):
if i not in human.body_parts.keys():
continue
body_part = human.body_parts[i]
center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5))
centers[i] = center
#自行添加 将每个关节的坐标点记录在flat中
flat[i*2] = center[0]
flat[i*2+1] = center[1]
cv2.circle(npimg, center, 3, common.CocoColors[i], thickness=3, lineType=8, shift=0)
# draw line
for pair_order, pair in enumerate(common.CocoPairsRender):
if pair[0] not in human.body_parts.keys() or pair[1] not in human.body_parts.keys():
continue
# npimg = cv2.line(npimg, centers[pair[0]], centers[pair[1]], common.CocoColors[pair_order], 3)
cv2.line(npimg, centers[pair[0]], centers[pair[1]], common.CocoColors[pair_order], 3)
#print(flat)
return npimg, flat