Skip to content

Commit

Permalink
Update pose estimator API
Browse files Browse the repository at this point in the history
  • Loading branch information
kyakuno committed Jan 23, 2020
1 parent cb40ce2 commit 78d9c63
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import cv2

import ailia
import ailia_pose_estimator

#require ailia SDK 1.2.1

Expand All @@ -26,13 +25,13 @@
if not os.path.exists(weight_path):
urllib.request.urlretrieve("https://storage.googleapis.com/ailia-models/lightweight-human-pose-estimation/"+weight_path,weight_path)

algorithm = ailia_pose_estimator.ALGORITHM_LW_HUMAN_POSE
algorithm = ailia.POSE_ALGORITHM_LW_HUMAN_POSE

file_name = 'balloon.png'

# estimator initialize
env_id=ailia.get_gpu_environment_id()
pose = ailia_pose_estimator.PoseEstimator(model_path,weight_path, env_id=env_id, algorithm=algorithm)
pose = ailia.PoseEstimator(model_path,weight_path, env_id=env_id, algorithm=algorithm)

shape = pose.get_input_shape()
ailia_input_width = shape[3]
Expand Down Expand Up @@ -67,7 +66,7 @@ def hsv_to_rgb(h, s, v):
def line(input_img,person,point1,point2):
threshold = 0.2
if person.points[point1].score>threshold and person.points[point2].score>threshold:
color = hsv_to_rgb(255*point1/ailia_pose_estimator.POSE_KEYPOINT_CNT,255,255)
color = hsv_to_rgb(255*point1/ailia.POSE_KEYPOINT_CNT,255,255)

x1 = int(input_img.shape[1] * person.points[point1].x)
y1 = int(input_img.shape[0] * person.points[point1].y)
Expand All @@ -80,33 +79,33 @@ def line(input_img,person,point1,point2):

for idx in range(count) :
person = pose.get_object_pose(idx)
for i in range(ailia_pose_estimator.POSE_KEYPOINT_CNT):
for i in range(ailia.POSE_KEYPOINT_CNT):
score = person.points[i].score
x = (input_img.shape[1] * person.points[i].x)
y = (input_img.shape[0] * person.points[i].y)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_NOSE,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_LEFT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_NOSE,ailia.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_SHOULDER_LEFT,ailia.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_SHOULDER_RIGHT,ailia.POSE_KEYPOINT_SHOULDER_CENTER)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EYE_LEFT,ailia_pose_estimator.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EYE_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EAR_LEFT,ailia_pose_estimator.POSE_KEYPOINT_EYE_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EAR_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_EYE_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_EYE_LEFT,ailia.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia.POSE_KEYPOINT_EYE_RIGHT,ailia.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia.POSE_KEYPOINT_EAR_LEFT,ailia.POSE_KEYPOINT_EYE_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_EAR_RIGHT,ailia.POSE_KEYPOINT_EYE_RIGHT)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_LEFT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_RIGHT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_WRIST_LEFT,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_WRIST_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_ELBOW_LEFT,ailia.POSE_KEYPOINT_SHOULDER_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_ELBOW_RIGHT,ailia.POSE_KEYPOINT_SHOULDER_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_WRIST_LEFT,ailia.POSE_KEYPOINT_ELBOW_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_WRIST_RIGHT,ailia.POSE_KEYPOINT_ELBOW_RIGHT)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_BODY_CENTER,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_HIP_LEFT,ailia_pose_estimator.POSE_KEYPOINT_BODY_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_HIP_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_BODY_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_BODY_CENTER,ailia.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_HIP_LEFT,ailia.POSE_KEYPOINT_BODY_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_HIP_RIGHT,ailia.POSE_KEYPOINT_BODY_CENTER)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_KNEE_LEFT,ailia_pose_estimator.POSE_KEYPOINT_HIP_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ANKLE_LEFT,ailia_pose_estimator.POSE_KEYPOINT_KNEE_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_KNEE_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_HIP_RIGHT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ANKLE_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_KNEE_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_KNEE_LEFT,ailia.POSE_KEYPOINT_HIP_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_ANKLE_LEFT,ailia.POSE_KEYPOINT_KNEE_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_KNEE_RIGHT,ailia.POSE_KEYPOINT_HIP_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_ANKLE_RIGHT,ailia.POSE_KEYPOINT_KNEE_RIGHT)

# save image
cv2.imwrite( "output.png", input_img)
45 changes: 22 additions & 23 deletions openpose/openpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import cv2

import ailia
import ailia_pose_estimator

#OPENPOSE: MULTIPERSON KEYPOINT DETECTION
#SOFTWARE LICENSE AGREEMENT
Expand All @@ -21,13 +20,13 @@
if not os.path.exists(weight_path):
urllib.request.urlretrieve("http://posefs1.perception.cs.cmu.edu/OpenPose/models/pose/coco/"+weight_path,weight_path)

algorithm = ailia_pose_estimator.ALGORITHM_OPEN_POSE
algorithm = ailia.POSE_ALGORITHM_OPEN_POSE

file_name = 'balloon.png'

# estimator initialize
env_id=ailia.get_gpu_environment_id()
pose = ailia_pose_estimator.PoseEstimator(model_path,weight_path, env_id=env_id, algorithm=algorithm)
pose = ailia.PoseEstimator(model_path,weight_path, env_id=env_id, algorithm=algorithm)

shape = pose.get_input_shape()
ailia_input_width = shape[3]
Expand Down Expand Up @@ -62,7 +61,7 @@ def hsv_to_rgb(h, s, v):
def line(input_img,person,point1,point2):
threshold = 0.2
if person.points[point1].score>threshold and person.points[point2].score>threshold:
color = hsv_to_rgb(255*point1/ailia_pose_estimator.POSE_KEYPOINT_CNT,255,255)
color = hsv_to_rgb(255*point1/ailia.POSE_KEYPOINT_CNT,255,255)

x1 = int(input_img.shape[1] * person.points[point1].x)
y1 = int(input_img.shape[0] * person.points[point1].y)
Expand All @@ -75,33 +74,33 @@ def line(input_img,person,point1,point2):

for idx in range(count) :
person = pose.get_object_pose(idx)
for i in range(ailia_pose_estimator.POSE_KEYPOINT_CNT):
for i in range(ailia.POSE_KEYPOINT_CNT):
score = person.points[i].score
x = (input_img.shape[1] * person.points[i].x)
y = (input_img.shape[0] * person.points[i].y)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_NOSE,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_LEFT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_NOSE,ailia.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_SHOULDER_LEFT,ailia.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_SHOULDER_RIGHT,ailia.POSE_KEYPOINT_SHOULDER_CENTER)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EYE_LEFT,ailia_pose_estimator.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EYE_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EAR_LEFT,ailia_pose_estimator.POSE_KEYPOINT_EYE_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_EAR_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_EYE_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_EYE_LEFT,ailia.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia.POSE_KEYPOINT_EYE_RIGHT,ailia.POSE_KEYPOINT_NOSE)
line(input_img,person,ailia.POSE_KEYPOINT_EAR_LEFT,ailia.POSE_KEYPOINT_EYE_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_EAR_RIGHT,ailia.POSE_KEYPOINT_EYE_RIGHT)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_LEFT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_RIGHT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_WRIST_LEFT,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_WRIST_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_ELBOW_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_ELBOW_LEFT,ailia.POSE_KEYPOINT_SHOULDER_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_ELBOW_RIGHT,ailia.POSE_KEYPOINT_SHOULDER_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_WRIST_LEFT,ailia.POSE_KEYPOINT_ELBOW_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_WRIST_RIGHT,ailia.POSE_KEYPOINT_ELBOW_RIGHT)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_BODY_CENTER,ailia_pose_estimator.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_HIP_LEFT,ailia_pose_estimator.POSE_KEYPOINT_BODY_CENTER)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_HIP_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_BODY_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_BODY_CENTER,ailia.POSE_KEYPOINT_SHOULDER_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_HIP_LEFT,ailia.POSE_KEYPOINT_BODY_CENTER)
line(input_img,person,ailia.POSE_KEYPOINT_HIP_RIGHT,ailia.POSE_KEYPOINT_BODY_CENTER)

line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_KNEE_LEFT,ailia_pose_estimator.POSE_KEYPOINT_HIP_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ANKLE_LEFT,ailia_pose_estimator.POSE_KEYPOINT_KNEE_LEFT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_KNEE_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_HIP_RIGHT)
line(input_img,person,ailia_pose_estimator.POSE_KEYPOINT_ANKLE_RIGHT,ailia_pose_estimator.POSE_KEYPOINT_KNEE_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_KNEE_LEFT,ailia.POSE_KEYPOINT_HIP_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_ANKLE_LEFT,ailia.POSE_KEYPOINT_KNEE_LEFT)
line(input_img,person,ailia.POSE_KEYPOINT_KNEE_RIGHT,ailia.POSE_KEYPOINT_HIP_RIGHT)
line(input_img,person,ailia.POSE_KEYPOINT_ANKLE_RIGHT,ailia.POSE_KEYPOINT_KNEE_RIGHT)

# save image
cv2.imwrite( "output.png", input_img)

0 comments on commit 78d9c63

Please sign in to comment.