Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 5 additions & 187 deletions demo_multipose.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import tensorflow as tf
import tensorflow_hub as tfhub

from pose_helper import draw_debug_multi_person


def get_args():
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -103,6 +105,8 @@ def main():
module = tfhub.load(model_url)
model = module.signatures['serving_default']

cv.namedWindow('MoveNet(multipose) Demo', cv.WINDOW_NORMAL)

while True:
start_time = time.time()

Expand All @@ -124,7 +128,7 @@ def main():
elapsed_time = time.time() - start_time

# デバッグ描画
debug_image = draw_debug(
debug_image = draw_debug_multi_person(
debug_image,
elapsed_time,
keypoint_score_th,
Expand All @@ -146,191 +150,5 @@ def main():
cv.destroyAllWindows()


def draw_debug(
image,
elapsed_time,
keypoint_score_th,
keypoints_list,
scores_list,
bbox_score_th,
bbox_list,
):
debug_image = copy.deepcopy(image)

# 0:鼻 1:左目 2:右目 3:左耳 4:右耳 5:左肩 6:右肩 7:左肘 8:右肘 # 9:左手首
# 10:右手首 11:左股関節 12:右股関節 13:左ひざ 14:右ひざ 15:左足首 16:右足首
for keypoints, scores in zip(keypoints_list, scores_list):
# Line:鼻 → 左目
index01, index02 = 0, 1
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:鼻 → 右目
index01, index02 = 0, 2
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左目 → 左耳
index01, index02 = 1, 3
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:右目 → 右耳
index01, index02 = 2, 4
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:鼻 → 左肩
index01, index02 = 0, 5
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:鼻 → 右肩
index01, index02 = 0, 6
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左肩 → 右肩
index01, index02 = 5, 6
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左肩 → 左肘
index01, index02 = 5, 7
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左肘 → 左手首
index01, index02 = 7, 9
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:右肩 → 右肘
index01, index02 = 6, 8
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:右肘 → 右手首
index01, index02 = 8, 10
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左股関節 → 右股関節
index01, index02 = 11, 12
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左肩 → 左股関節
index01, index02 = 5, 11
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左股関節 → 左ひざ
index01, index02 = 11, 13
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:左ひざ → 左足首
index01, index02 = 13, 15
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:右肩 → 右股関節
index01, index02 = 6, 12
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:右股関節 → 右ひざ
index01, index02 = 12, 14
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)
# Line:右ひざ → 右足首
index01, index02 = 14, 16
if scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th:
point01 = keypoints[index01]
point02 = keypoints[index02]
cv.line(debug_image, point01, point02, (255, 255, 255), 4)
cv.line(debug_image, point01, point02, (0, 0, 0), 2)

# Circle:各点
for keypoint, score in zip(keypoints, scores):
if score > keypoint_score_th:
cv.circle(debug_image, keypoint, 6, (255, 255, 255), -1)
cv.circle(debug_image, keypoint, 3, (0, 0, 0), -1)

# バウンディングボックス
for bbox in bbox_list:
if bbox[4] > bbox_score_th:
cv.rectangle(debug_image, (bbox[0], bbox[1]), (bbox[2], bbox[3]),
(255, 255, 255), 4)
cv.rectangle(debug_image, (bbox[0], bbox[1]), (bbox[2], bbox[3]),
(0, 0, 0), 2)

# 処理時間
cv.putText(debug_image,
"Elapsed Time : " + '{:.1f}'.format(elapsed_time * 1000) + "ms",
(10, 30), cv.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 4,
cv.LINE_AA)
cv.putText(debug_image,
"Elapsed Time : " + '{:.1f}'.format(elapsed_time * 1000) + "ms",
(10, 30), cv.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 2,
cv.LINE_AA)

return debug_image


if __name__ == '__main__':
main()
Loading