Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extracted common functions to pose_helper.py #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
added type hint
  • Loading branch information
waragai-katsunori committed Nov 10, 2021
commit 73a2a2d98a9e920336ef068dafe709ab81fdcdc0
110 changes: 56 additions & 54 deletions pose_helper.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import copy
from typing import List

import cv2 as cv
import numpy as np


def draw_debug(
image,
elapsed_time,
keypoint_score_th,
keypoints,
scores,
):
image: np.ndarray,
elapsed_time: float,
keypoint_score_th: float,
keypoints: List,
scores: List[float],
) -> np.ndarray:
debug_image = copy.deepcopy(image)

# 0:鼻 1:左目 2:右目 3:左耳 4:右耳 5:左肩 6:右肩 7:左肘 8:右肘 # 9:左手首
# 10:右手首 11:左股関節 12:右股関節 13:左ひざ 14:右ひざ 15:左足首 16:右足首
for index01, index02 in ((0, 1), # Line:鼻 → 左目
(0, 2), # Line:鼻 → 右目
(1, 3), # Line:左目 → 左耳
(2, 4), # Line:右目 → 右耳
(0, 5), # Line:鼻 → 左肩
(0, 6), # Line:鼻 → 右肩
(5, 6), # Line:左肩 → 右肩
(5, 7), # Line:左肩 → 左肘
(7, 9), # Line:左肘 → 左手首
(6, 8), # Line:右肩 → 右肘
(8, 10), # Line:右肘 → 右手首
(11, 12), # Line:左股関節 → 右股関節
(5, 11), # Line:左肩 → 左股関節
(11, 13), # Line:左股関節 → 左ひざ
(13, 15), # Line:左ひざ → 左足首
(6, 12), # Line:右肩 → 右股関節
(12, 14), # Line:右股関節 → 右ひざ
(14, 16), # Line:右ひざ → 右足首
for index01, index02 in ((0, 1), # Line:鼻 → 左目
(0, 2), # Line:鼻 → 右目
(1, 3), # Line:左目 → 左耳
(2, 4), # Line:右目 → 右耳
(0, 5), # Line:鼻 → 左肩
(0, 6), # Line:鼻 → 右肩
(5, 6), # Line:左肩 → 右肩
(5, 7), # Line:左肩 → 左肘
(7, 9), # Line:左肘 → 左手首
(6, 8), # Line:右肩 → 右肘
(8, 10), # Line:右肘 → 右手首
(11, 12), # Line:左股関節 → 右股関節
(5, 11), # Line:左肩 → 左股関節
(11, 13), # Line:左股関節 → 左ひざ
(13, 15), # Line:左ひざ → 左足首
(6, 12), # Line:右肩 → 右股関節
(12, 14), # Line:右股関節 → 右ひざ
(14, 16), # Line:右ひざ → 右足首
):
if is_good_keypoints(index01, index02, keypoint_score_th, scores):
draw_keypoints(debug_image, index01, index02, keypoints)
Expand All @@ -54,55 +57,54 @@ def draw_debug(
return debug_image


def is_good_keypoints(index01, index02, keypoint_score_th, scores):
def is_good_keypoints(index01: int, index02: int, keypoint_score_th: float, scores: List[float]) -> bool:
return scores[index01] > keypoint_score_th and scores[
index02] > keypoint_score_th


def draw_keypoints(debug_image, index01, index02, keypoints):
def draw_keypoints(debug_image: np.ndarray, index01: int, index02: int, keypoints: List):
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)


def draw_debug_multi_person(
image,
elapsed_time,
keypoint_score_th,
keypoints_list,
scores_list,
bbox_score_th,
bbox_list,
):
image: np.ndarray,
elapsed_time: float,
keypoint_score_th: float,
keypoints_list: List,
scores_list: List[float],
bbox_score_th: float,
bbox_list: List,
) -> np.ndarray:
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):
for index01, index02 in ((0, 1), # Line:鼻 → 左目
(0, 2), # Line:鼻 → 右目
(1, 3), # Line:左目 → 左耳
(2, 4), # Line:右目 → 右耳
(0, 5), # Line:鼻 → 左肩
(0, 6), # Line:鼻 → 右肩
(5, 6), # Line:左肩 → 右肩
(5, 7), # Line:左肩 → 左肘
(7, 9), # Line:左肘 → 左手首
(6, 8), # Line:右肩 → 右肘
(8, 10), # Line:右肘 → 右手首
(11, 12), # Line:左股関節 → 右股関節
(5, 11), # Line:左肩 → 左股関節
(11, 13), # Line:左股関節 → 左ひざ
(13, 15), # Line:左ひざ → 左足首
(6, 12), # Line:右肩 → 右股関節
(12, 14), # Line:右股関節 → 右ひざ
(14, 16), # Line:右ひざ → 右足首
for index01, index02 in ((0, 1), # Line:鼻 → 左目
(0, 2), # Line:鼻 → 右目
(1, 3), # Line:左目 → 左耳
(2, 4), # Line:右目 → 右耳
(0, 5), # Line:鼻 → 左肩
(0, 6), # Line:鼻 → 右肩
(5, 6), # Line:左肩 → 右肩
(5, 7), # Line:左肩 → 左肘
(7, 9), # Line:左肘 → 左手首
(6, 8), # Line:右肩 → 右肘
(8, 10), # Line:右肘 → 右手首
(11, 12), # Line:左股関節 → 右股関節
(5, 11), # Line:左肩 → 左股関節
(11, 13), # Line:左股関節 → 左ひざ
(13, 15), # Line:左ひざ → 左足首
(6, 12), # Line:右肩 → 右股関節
(12, 14), # Line:右股関節 → 右ひざ
(14, 16), # Line:右ひざ → 右足首
):
if is_good_keypoints(index01, index02, keypoint_score_th, scores):
draw_keypoints(debug_image, index01, index02, keypoints)


# Circle:各点
for keypoint, score in zip(keypoints, scores):
if score > keypoint_score_th:
Expand All @@ -127,4 +129,4 @@ def draw_debug_multi_person(
(10, 30), cv.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 2,
cv.LINE_AA)

return debug_image
return debug_image